summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2015-03-19 22:42:40 +0100
committerSébastien Dailly <sebastien@chimrod.com>2015-03-19 22:42:40 +0100
commite90c342c6b3487840f0b7067fd2ed04678d00db3 (patch)
treeb27c61028e350e85170b5a3b13cf77188c24da4e
parent0ad73de1d89956739738716f2d32652ca83164b5 (diff)
Do not load disqus comment automaticaly
-rwxr-xr-xpelicanconf.py12
-rw-r--r--plugins/related_posts/related_posts.py92
-rw-r--r--publishconf.py10
-rwxr-xr-xtheme/static/css/main.css39
-rwxr-xr-xtheme/templates/article.html23
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 @@
</ul>
{% endif %}
</div>
- <script type="text/javascript">
- var disqus_identifier = "{{ article.url }}";
- (function() {
- var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
- dsq.src = '//{{ DISQUS_SITENAME }}.disqus.com/embed.js';
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
- })();
- </script>
</div>
+ <div id="disqus_comments">
+ <button onclick="load_disqus()">recharger</button>
+ </div>
+ <script type="text/javascript">
+ var disqus_identifier = "{{ article.url }}";
+ function load_disqus() {
+ var dsq = document.createElement('script');
+ dsq.type = 'text/javascript';
+ dsq.async = true;
+ dsq.src = '//{{ DISQUS_SITENAME }}.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ var load_button = document.getElementById('disqus_comments');
+ load_button.parentNode.removeChild(load_button);
+ };
+ </script>
{% endif %}
{% endblock %}