From e90c342c6b3487840f0b7067fd2ed04678d00db3 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 19 Mar 2015 22:42:40 +0100 Subject: Do not load disqus comment automaticaly --- pelicanconf.py | 12 ----- plugins/related_posts/related_posts.py | 92 +++++++++++++++++++++------------- publishconf.py | 10 ++++ theme/static/css/main.css | 39 ++++++++++++++ theme/templates/article.html | 23 ++++++--- 5 files changed, 120 insertions(+), 56 deletions(-) diff --git a/pelicanconf.py b/pelicanconf.py index 09b4d78..a6da2bf 100755 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -33,8 +33,6 @@ ARTICLE_SAVE_AS = u'{date:%Y}/{date:%m}/{slug}/index.html' STATIC_SAVE_AS=u'{path}' -STATIC_PATHS = ['images', 'resources'] - THEME = 'theme' TYPOGRIFY = False TEMPLATE_PAGES = {'../extras/404.html': '404.html'} @@ -54,7 +52,6 @@ EXTRA_PATH_METADATA = { PLUGIN_PATHS = ['plugins'] -#from pelican.plugins import related_posts PLUGINS = ['related_posts', 'typogrify'] SUMMARY_MAX_LENGTH=100 @@ -64,12 +61,3 @@ DOCUTILS_SETTINGS={ 'strip_comments': 'True' } -import sys -import os.path -try: - sys.path.append(os.path.dirname(os.path.abspath(__file__))) - from disqus import * - PLUGINS.append("disqus_static") -except: - pass - diff --git a/plugins/related_posts/related_posts.py b/plugins/related_posts/related_posts.py index 4000e03..dff03c5 100644 --- a/plugins/related_posts/related_posts.py +++ b/plugins/related_posts/related_posts.py @@ -1,36 +1,56 @@ -""" -Related posts plugin for Pelican -================================ - -Adds related_posts variable to article's context -""" - -from pelican import signals -from collections import Counter - - -def add_related_posts(generator): - # get the max number of entries from settings - # or fall back to default (5) - numentries = generator.settings.get('RELATED_POSTS_MAX', 5) - - for article in generator.articles: - # no tag, no relation - if not hasattr(article, 'tags'): - continue - - # score = number of common tags - scores = Counter() - for tag in article.tags: - scores += Counter(generator.tags[tag]) - - # remove itself - scores.pop(article) - - article.related_posts = [other for other, count - in scores.most_common(numentries)] - - -def register(): - signals.article_generator_finalized.connect(add_related_posts) - +""" +Related posts plugin for Pelican +================================ + +Adds related_posts variable to article's context +""" + +from pelican import signals +from collections import Counter +from itertools import chain + + +def add_related_posts(generator): + # get the max number of entries from settings + # or fall back to default (5) + numentries = generator.settings.get('RELATED_POSTS_MAX', 5) + # Skip all posts in the same category as the article + skipcategory = generator.settings.get('RELATED_POSTS_SKIP_SAME_CATEGORY', False) + for article in generator.articles: + # set priority in case of forced related posts + if hasattr(article,'related_posts'): + # split slugs + related_posts = article.related_posts.split(',') + posts = [] + # get related articles + for slug in related_posts: + i = 0 + slug = slug.strip() + for a in generator.articles: + if i >= numentries: # break in case there are max related psots + break + if a.slug == slug: + posts.append(a) + i += 1 + + article.related_posts = posts + else: + # no tag, no relation + if not hasattr(article, 'tags'): + continue + + # score = number of common tags + related = chain(*(generator.tags[tag] for tag in article.tags)) + if skipcategory: + related = (other for other in related + if other.category != article.category) + scores = Counter(related) + + # remove itself + scores.pop(article, None) + + article.related_posts = [other for other, count + in scores.most_common(numentries)] + +def register(): + signals.article_generator_finalized.connect(add_related_posts) \ No newline at end of file diff --git a/publishconf.py b/publishconf.py index 10a7e59..b224980 100644 --- a/publishconf.py +++ b/publishconf.py @@ -17,3 +17,13 @@ DELETE_OUTPUT_DIRECTORY = True DISQUS_SITENAME='chimrod' #GOOGLE_ANALYTICS = "" + +import sys +import os.path +try: + sys.path.append(os.path.dirname(os.path.abspath(__file__))) + from disqus import * + PLUGINS.append("disqus_static") +except: + pass + diff --git a/theme/static/css/main.css b/theme/static/css/main.css index 7851ed8..d10ef1f 100755 --- a/theme/static/css/main.css +++ b/theme/static/css/main.css @@ -339,4 +339,43 @@ img.center { margin-right: auto; } +#disqus_comments { + text-align: center; +} + +/* BUTTONS */ button{ + margin:0 7px 0 0; + background-color:#f5f5f5; + border:1px solid #dedede; + border-top:1px solid #eee; + border-left:1px solid #eee; font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif; + font-size:100%; + line-height:130%; + text-decoration:none; + font-weight:bold; + color:#565656; + cursor:pointer; + padding:5px 10px 6px 7px; /* Links */ +} +button{ + width:auto; + overflow:visible; + padding:4px 10px 3px 7px; /* IE6 */ +} +button[type]{ + padding:5px 10px 5px 7px; /* Firefox */ + line-height:17px; /* Safari */ +} +*:first-child+html button[type]{ + padding:4px 10px 3px 7px; /* IE7 */ +} +button img, .buttons a img{ + margin:0 3px -3px 0 !important; + padding:0; + border:none; + width:16px; + height:16px; +} + + .clear { clear:both; } diff --git a/theme/templates/article.html b/theme/templates/article.html index 976041a..5b366e0 100755 --- a/theme/templates/article.html +++ b/theme/templates/article.html @@ -64,15 +64,22 @@ {% endif %} - +
+ +
+ {% endif %} {% endblock %} -- cgit v1.2.3