def add_static_comments(gen, content):
    if gen.settings['PELICAN_COMMENT_SYSTEM'] != True:
        return

    content.comments_count = 0
    content.comments = []

    #Modify the local context, so we get proper values for the feed
    context = copy.copy(gen.context)
    context['SITEURL'] += "/" + content.url
    context['SITENAME'] = "Comments for: " + content.title
    context['SITESUBTITLE'] = ""
    path = gen.settings['PELICAN_COMMENT_SYSTEM_FEED'] % content.slug
    writer = Writer(gen.output_path, settings=gen.settings)

    folder = os.path.join(gen.settings['PELICAN_COMMENT_SYSTEM_DIR'],
                          content.slug)

    if not os.path.isdir(folder):
        logger.debug("No comments found for: " + content.slug)
        writer.write_feed([], context, path)
        return

    reader = MarkdownReader(gen.settings)
    comments = []
    replies = []

    for file in os.listdir(folder):
        name, extension = os.path.splitext(file)
        if extension[1:].lower() in reader.file_extensions:
            com_content, meta = reader.read(os.path.join(folder, file))

            avatar_path = avatars.getAvatarPath(name, meta)

            com = Comment(file, avatar_path, com_content, meta, gen.settings,
                          file, context)

            if 'replyto' in meta:
                replies.append(com)
            else:
                comments.append(com)

    writer.write_feed(comments + replies, context, path)

    #TODO: Fix this O(n²) loop
    for reply in replies:
        for comment in chain(comments, replies):
            if comment.id == reply.metadata['replyto']:
                comment.addReply(reply)

    count = 0
    for comment in comments:
        comment.sortReplies()
        count += comment.countReplies()

    comments = sorted(comments)

    content.comments_count = len(comments) + count
    content.comments = comments
예제 #2
0
def write_feed(gen, items, context, slug):
    if gen.settings['PELICAN_COMMENT_SYSTEM_FEED'] is None:
        return

    path = gen.settings['PELICAN_COMMENT_SYSTEM_FEED'] % slug

    writer = Writer(gen.output_path, settings=gen.settings)
    writer.write_feed(items, context, path)
def write_feed(gen, items, context, slug):
    if gen.settings['PELICAN_COMMENT_SYSTEM_FEED'] is None:
        return

    path = gen.settings['PELICAN_COMMENT_SYSTEM_FEED'] % slug

    writer = Writer(gen.output_path, settings=gen.settings)
    writer.write_feed(items, context, path)
def add_static_comments(gen, content):
	if gen.settings['PELICAN_COMMENT_SYSTEM'] != True:
		return

	content.comments_count = 0
	content.comments = []

	#Modify the local context, so we get proper values for the feed
	context = copy.copy(gen.context)
	context['SITEURL'] += "/" + content.url
	context['SITENAME'] = "Comments for: " + content.title
	context['SITESUBTITLE'] = ""
	path = gen.settings['PELICAN_COMMENT_SYSTEM_FEED'] % content.slug
	writer = Writer(gen.output_path, settings=gen.settings)

	folder = os.path.join(gen.settings['PELICAN_COMMENT_SYSTEM_DIR'], content.slug)

	if not os.path.isdir(folder):
		logger.debug("No comments found for: " + content.slug)
		writer.write_feed( [], context, path)
		return

	reader = MarkdownReader(gen.settings)
	comments = []
	replies = []

	for file in os.listdir(folder):
		name, extension = os.path.splitext(file)
		if extension[1:].lower() in reader.file_extensions:
			com_content, meta = reader.read(os.path.join(folder, file))
			
			avatar_path = avatars.getAvatarPath(name, meta)

			com = Comment(file, avatar_path, com_content, meta, gen.settings, file, context)

			if 'replyto' in meta:
				replies.append( com )
			else:
				comments.append( com )

	writer.write_feed( comments + replies, context, path)

	#TODO: Fix this O(n²) loop
	for reply in replies:
		for comment in chain(comments, replies):
			if comment.id == reply.metadata['replyto']:
				comment.addReply(reply)

	count = 0
	for comment in comments:
		comment.sortReplies()
		count += comment.countReplies()

	comments = sorted(comments)

	content.comments_count = len(comments) + count
	content.comments = comments
예제 #5
0
def write_feed_all(gen, writer):
    if gen.settings['PELICAN_COMMENT_SYSTEM'] is not True:
        return
    if gen.settings['PELICAN_COMMENT_SYSTEM_FEED_ALL'] is None:
        return

    context = copy.copy(gen.context)
    context['SITENAME'] += " - All Comments"
    context['SITESUBTITLE'] = ""
    path = gen.settings['PELICAN_COMMENT_SYSTEM_FEED_ALL']

    global _all_comments
    _all_comments = sorted(_all_comments)
    _all_comments.reverse()

    for com in _all_comments:
        com.title = com.article.title + " - " + com.title
        com.override_url = com.article.url + com.url

    writer = Writer(gen.output_path, settings=gen.settings)
    writer.write_feed(_all_comments, context, path)
def write_feed_all(gen, writer):
    if gen.settings["PELICAN_COMMENT_SYSTEM"] is not True:
        return
    if gen.settings["PELICAN_COMMENT_SYSTEM_FEED_ALL"] is None:
        return

    context = copy.copy(gen.context)
    context["SITENAME"] += " - All Comments"
    context["SITESUBTITLE"] = ""
    path = gen.settings["PELICAN_COMMENT_SYSTEM_FEED_ALL"]

    global _all_comments
    _all_comments = sorted(_all_comments)
    _all_comments.reverse()

    for com in _all_comments:
        com.title = com.article.title + " - " + com.title
        com.override_url = com.article.url + com.url

    writer = Writer(gen.output_path, settings=gen.settings)
    writer.write_feed(_all_comments, context, path)