From c6f1d0aadaa5e1dd71ad2a6897169f9da4458c2a Mon Sep 17 00:00:00 2001 From: dave mankoff Date: Mon, 11 Jun 2012 08:39:13 -0400 Subject: [PATCH 1/8] fix SUMMARY_MAX_LENGTH, document it, and test it --- docs/settings.rst | 6 ++++++ pelican/settings.py | 2 +- tests/test_contents.py | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index 85e9f0c3..a26c37dd 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -90,6 +90,12 @@ Setting name (default value) What doe index pages for collections of content e.g. tags and category index pages. `PAGINATED_DIRECT_TEMPLATES` (``('index',)``) Provides the direct templates that should be paginated. +`SUMMARY_MAX_LENGTH` (``50``) When creating a short summary of an article, this will + be the default length in words of the text created. + This only applies if your content does not otherwise + specify a summary. Setting to None will cause the summary + to be a copy of the original content. + ===================================================================== ===================================================================== .. [#] Default is the system locale. diff --git a/pelican/settings.py b/pelican/settings.py index a8c8bea4..d2a39cd9 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -68,7 +68,7 @@ _DEFAULT_CONFIG = {'PATH': '.', 'ARTICLE_PERMALINK_STRUCTURE': '', 'TYPOGRIFY': False, 'LESS_GENERATOR': False, - 'SUMARY_MAX_LENGTH': 50, + 'SUMMARY_MAX_LENGTH': 50, } diff --git a/tests/test_contents.py b/tests/test_contents.py index c6ef29a8..e7c9ad01 100644 --- a/tests/test_contents.py +++ b/tests/test_contents.py @@ -4,6 +4,7 @@ from .support import unittest from pelican.contents import Page from pelican.settings import _DEFAULT_CONFIG +from pelican.utils import truncate_html_words from jinja2.utils import generate_lorem_ipsum @@ -48,6 +49,20 @@ class TestPage(unittest.TestCase): page = Page(**self.page_kwargs) self.assertEqual(page.summary, TEST_SUMMARY) + def test_summary_max_length(self): + """If a :SUMMARY_MAX_LENGTH: is set, and there is no other summary, generated summary + should not exceed the given length.""" + page_kwargs = self._copy_page_kwargs() + settings = _DEFAULT_CONFIG.copy() + page_kwargs['settings'] = settings + del page_kwargs['metadata']['summary'] + settings['SUMMARY_MAX_LENGTH'] = None + page = Page(**page_kwargs) + self.assertEqual(page.summary, TEST_CONTENT) + settings['SUMMARY_MAX_LENGTH'] = 10 + page = Page(**page_kwargs) + self.assertEqual(page.summary, truncate_html_words(TEST_CONTENT, 10)) + def test_slug(self): """If a title is given, it should be used to generate the slug.""" page = Page(**self.page_kwargs) @@ -83,14 +98,9 @@ class TestPage(unittest.TestCase): from datetime import datetime from sys import platform dt = datetime(2015, 9, 13) - # make a deep copy of page_kawgs - page_kwargs = dict([(key, self.page_kwargs[key]) for key in - self.page_kwargs]) - for key in page_kwargs: - if not isinstance(page_kwargs[key], dict): - break - page_kwargs[key] = dict([(subkey, page_kwargs[key][subkey]) - for subkey in page_kwargs[key]]) + + page_kwargs = self._copy_page_kwargs() + # set its date to dt page_kwargs['metadata']['date'] = dt page = Page(**page_kwargs) @@ -124,3 +134,15 @@ class TestPage(unittest.TestCase): # Until we find some other method to test this functionality, we # will simply skip this test. unittest.skip("There is no locale %s in this system." % locale) + + def _copy_page_kwargs(self): + # make a deep copy of page_kwargs + page_kwargs = dict([(key, self.page_kwargs[key]) for key in + self.page_kwargs]) + for key in page_kwargs: + if not isinstance(page_kwargs[key], dict): + break + page_kwargs[key] = dict([(subkey, page_kwargs[key][subkey]) + for subkey in page_kwargs[key]]) + + return page_kwargs From 1c708a70ba7f806ca2cf373b1f3c47d74c52c086 Mon Sep 17 00:00:00 2001 From: dave mankoff Date: Mon, 11 Jun 2012 09:00:36 -0400 Subject: [PATCH 2/8] Revert "better html parser" This reverts commit c6d1de14f3db63705b35fbe3fd5db3701ea962a4. --- pelican/readers.py | 101 +-------------------------------------------- 1 file changed, 2 insertions(+), 99 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index 83cb7e3b..83565918 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -13,11 +13,8 @@ try: from markdown import Markdown except ImportError: Markdown = False # NOQA -import cgi -from HTMLParser import HTMLParser import re - from pelican.contents import Category, Tag, Author from pelican.utils import get_date, open @@ -129,12 +126,13 @@ class MarkdownReader(Reader): metadata[name] = self.process_metadata(name, value[0]) return content, metadata -""" + class HtmlReader(Reader): file_extensions = ['html', 'htm'] _re = re.compile('\<\!\-\-\#\s?[A-z0-9_-]*\s?\:s?[A-z0-9\s_-]*\s?\-\-\>') def read(self, filename): + """Parse content and metadata of (x)HTML files""" with open(filename) as content: metadata = {'title': 'unnamed'} for i in self._re.findall(content): @@ -144,101 +142,6 @@ class HtmlReader(Reader): metadata[name] = self.process_metadata(name, value) return content, metadata -""" - -class PelicanHTMLParser(HTMLParser): - def __init__(self, settings): - HTMLParser.__init__(self) - self.body = '' - self.metadata = {} - self.settings = settings - - self._data_buffer = '' - - self._in_top_level = True - self._in_head = False - self._in_title = False - self._in_body = False - self._in_tags = False - - def handle_starttag(self, tag, attrs): - if tag == 'head' and self._in_top_level: - self._in_top_level = False - self._in_head = True - elif tag == 'title' and self._in_head: - self._in_title = True - self._data_buffer = '' - elif tag == 'body' and self._in_top_level: - self._in_top_level = False - self._in_body = True - self._data_buffer = '' - elif tag == 'meta' and self._in_head: - self._handle_meta_tag(attrs) - - elif self._in_body: - self._data_buffer += self.build_tag(tag, attrs, False) - - def handle_endtag(self, tag): - if tag == 'head': - if self._in_head: - self._in_head = False - self._in_top_level = True - elif tag == 'title': - self._in_title = False - self.metadata['title'] = self._data_buffer - elif tag == 'body': - self.body = self._data_buffer - self._in_body = False - self._in_top_level = True - elif self._in_body: - self._data_buffer += ''.format(cgi.escape(tag)) - - def handle_startendtag(self, tag, attrs): - if tag == 'meta' and self._in_head: - self._handle_meta_tag(attrs) - if self._in_body: - self._data_buffer += self.build_tag(tag, attrs, True) - - def handle_comment(self, data): - if self._in_body and data.strip() == 'PELICAN_END_SUMMARY': - self.metadata['summary'] = self._data_buffer - - def handle_data(self, data): - self._data_buffer += data - - def build_tag(self, tag, attrs, close_tag): - result = '<{}'.format(cgi.escape(tag)) - result += ''.join((' {}="{}"'.format(cgi.escape(k), cgi.escape(v)) for k,v in attrs)) - if close_tag: - return result + ' />' - return result + '>' - - def _handle_meta_tag(self, attrs): - name = self._attr_value(attrs, 'name') - contents = self._attr_value(attrs, 'contents', '') - if name == 'keywords': - if contents: - self.metadata['tags'] = [Tag(unicode(tag), self.settings) for tag in contents.split(',')] - elif name == 'date': - self.metadata['date'] = get_date(contents) - else: - self.metadata[name] = contents - - @classmethod - def _attr_value(cls, attrs, name, default=None): - return next((x[1] for x in attrs if x[0] == name), default) - -class HTMLReader(Reader): - file_extensions = ['htm', 'html'] - enabled = True - - def read(self, filename): - """Parse content and metadata of markdown files""" - with open(filename) as content: - parser = PelicanHTMLParser(self.settings) - parser.feed(content) - parser.close() - return parser.body, parser.metadata _EXTENSIONS = {} From d9dba3864486dd3949e69976619bc993aaee387a Mon Sep 17 00:00:00 2001 From: dave mankoff Date: Mon, 11 Jun 2012 09:00:57 -0400 Subject: [PATCH 3/8] Revert "turn utils.open into actual context manager so as to better handle encoding warnings" This reverts commit 876c7f509392d6c245a81e26fd5fd2a81851281f. --- pelican/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pelican/utils.py b/pelican/utils.py index db15a343..d4e34842 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import contextlib import os import re import pytz @@ -33,10 +32,10 @@ def get_date(string): pass raise ValueError("'%s' is not a valid date" % string) -@contextlib.contextmanager + def open(filename): """Open a file and return it's content""" - yield _open(filename, encoding='utf-8').read() + return _open(filename, encoding='utf-8').read() def slugify(value): From ddb345897e41f7fc11a345381ee6392737839a75 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 14 Jun 2012 10:29:44 -0400 Subject: [PATCH 4/8] Add gitorious icon to default theme. See ametaireau/pelican-themes#38 and ametaireau/pelican-themes#39 for references. --- pelican/themes/notmyidea/static/css/main.css | 1 + .../notmyidea/static/images/icons/gitorious.png | Bin 0 -> 3675 bytes 2 files changed, 1 insertion(+) create mode 100644 pelican/themes/notmyidea/static/images/icons/gitorious.png diff --git a/pelican/themes/notmyidea/static/css/main.css b/pelican/themes/notmyidea/static/css/main.css index 92905076..dce9e247 100644 --- a/pelican/themes/notmyidea/static/css/main.css +++ b/pelican/themes/notmyidea/static/css/main.css @@ -312,6 +312,7 @@ img.left, figure.left {float: right; margin: 0 0 2em 2em;} .social a[type$='atom+xml'], .social a[type$='rss+xml'] {background-image: url('../images/icons/rss.png');} .social a[href*='twitter.com'] {background-image: url('../images/icons/twitter.png');} .social a[href*='linkedin.com'] {background-image: url('../images/icons/linkedin.png');} + .social a[href*='gitorious.org'] {background-image: url('../images/icons/gitorious.org');} /* About diff --git a/pelican/themes/notmyidea/static/images/icons/gitorious.png b/pelican/themes/notmyidea/static/images/icons/gitorious.png new file mode 100644 index 0000000000000000000000000000000000000000..6485f5ecc5f6047a052d9adfb686ee154e7233af GIT binary patch literal 3675 zcmeH}_cs;(AIIM!du1jmd)(}q&As*>mwP2~txFP0S<$suA0ydaQQ0fx>V~qnD`Z|H zDsM1YRfBtf8PhSR$Jg1$Z#Z(m^oWl9R>38%Fr zV-o!|&8oo5l;~FpNdreqVXu59TS#ArPaCJS)~oig4I?ydw2WCs3f4*(#&YPD3tysp zyLy&ZrFA0dh5gU|Zg3a4e&2NdXtJ$6v<*278zrMgbh332;&r zrUQOx5VdKotgD z`hA5QR(*4vZDlM6DVAhkU}Z6+_|xb0_{drY{|m>{Rte_f~M(8MshYu zaDF=@zFp0G=Tzfw8oWz^vUSY}hTV7;tYWO}x%9@qin2NJ zz-^>1h>9&zzl~0rDhSGtx}s}@G(%cU8$HTuwl1u5UTNv!XK>?b2$mG^VXBOK5UJE9S~ooN=pm#z z=Y+30S+kBG1X@TR1#Igi$iJ}=^&f}&} zMOJneveKy1y3%l~Rk>!n6kF1&-|TP{$*kLJB6d^E5S>amk6pK&v7IlaFXb}V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gW_eSRoNz}2?Bd6&HsVuPbsky0xaZGVr1=qDy zRhPBzoopPJ!baRjL<_i2U!D%uaC6B-98PRa5k_-Hi?VmKGd}u0Dn8k4+v2Gu_H^`I z`OqJ%Aa`ru{%E^BXfBBF$E!sa%hgBxkHyJezv~WcKb0P3@ML6=sVH;yj@=Zbh-ZD1 z-_6Lz9Dq;}05H)2{3f6I1^^Fa0oZf_KrIIVZoj9_-39ZfDh7YjeuipAOblqHnRd;pX1guKpVP^?KjrDZl!Lxy>?erb8ta^(jygszj+vLaYB8AoV>@2=0&gbI Date: Thu, 14 Jun 2012 23:04:23 +0200 Subject: [PATCH 5/8] added GoSquared support GoSquared(analytics) support added in default themes and documentation (in French and English) --- README.rst | 2 +- docs/fr/configuration.rst | 3 +++ docs/settings.rst | 1 + pelican/themes/notmyidea/templates/gosquared.html | 14 ++++++++++++++ pelican/themes/simple/templates/gosquared.html | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 pelican/themes/notmyidea/templates/gosquared.html create mode 100644 pelican/themes/simple/templates/gosquared.html diff --git a/README.rst b/README.rst index 5012bb9c..4f4edb61 100644 --- a/README.rst +++ b/README.rst @@ -26,7 +26,7 @@ Pelican currently supports: * Atom/RSS feeds * Code syntax highlighting * Import from WordPress, Dotclear, or RSS feeds -* Integration with external tools: Twitter, Google Analytics, etc. (optional) +* Integration with external tools: Twitter, Google Analytics, GoSquared, etc. (optional) Have a look at `the documentation `_ for more information. diff --git a/docs/fr/configuration.rst b/docs/fr/configuration.rst index 695a0b0e..fadaf258 100644 --- a/docs/fr/configuration.rst +++ b/docs/fr/configuration.rst @@ -98,6 +98,9 @@ GITHUB_URL : GOOGLE_ANALYTICS : 'UA-XXXX-YYYY' pour activer Google analytics ; + +GOSQUARED_SITENAME : + 'XXX-YYYYYY-X' pour activer GoSquared ; JINJA_EXTENSIONS : Liste d'extension Jinja2 que vous souhaitez utiliser ; diff --git a/docs/settings.rst b/docs/settings.rst index b36c9953..416c22d4 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -398,6 +398,7 @@ Setting name What does it do ? `GITHUB_URL` Your GitHub URL (if you have one). It will then use this information to create a GitHub ribbon. `GOOGLE_ANALYTICS` 'UA-XXXX-YYYY' to activate Google Analytics. +`GOSQUARED_SITENAME` 'XXX-YYYYYY-X' to activate GoSquared. `MENUITEMS` A list of tuples (Title, URL) for additional menu items to appear at the beginning of the main menu. `PIWIK_URL` URL to your Piwik server - without 'http://' at the diff --git a/pelican/themes/notmyidea/templates/gosquared.html b/pelican/themes/notmyidea/templates/gosquared.html new file mode 100644 index 00000000..f47efcf4 --- /dev/null +++ b/pelican/themes/notmyidea/templates/gosquared.html @@ -0,0 +1,14 @@ +{% if GOSQUARED_SITENAME %} + +{% endif %} diff --git a/pelican/themes/simple/templates/gosquared.html b/pelican/themes/simple/templates/gosquared.html new file mode 100644 index 00000000..f47efcf4 --- /dev/null +++ b/pelican/themes/simple/templates/gosquared.html @@ -0,0 +1,14 @@ +{% if GOSQUARED_SITENAME %} + +{% endif %} From d1dfcdafc229b788bf48f08964836ff17eace4f0 Mon Sep 17 00:00:00 2001 From: asselinpaul Date: Thu, 14 Jun 2012 23:32:23 +0200 Subject: [PATCH 6/8] updated remove GoSqaured from README and template file from the notmyidea theme. --- README.rst | 2 +- pelican/themes/notmyidea/templates/.DS_Store | Bin 0 -> 6148 bytes .../themes/notmyidea/templates/gosquared.html | 14 -------------- 3 files changed, 1 insertion(+), 15 deletions(-) create mode 100644 pelican/themes/notmyidea/templates/.DS_Store delete mode 100644 pelican/themes/notmyidea/templates/gosquared.html diff --git a/README.rst b/README.rst index 4f4edb61..5012bb9c 100644 --- a/README.rst +++ b/README.rst @@ -26,7 +26,7 @@ Pelican currently supports: * Atom/RSS feeds * Code syntax highlighting * Import from WordPress, Dotclear, or RSS feeds -* Integration with external tools: Twitter, Google Analytics, GoSquared, etc. (optional) +* Integration with external tools: Twitter, Google Analytics, etc. (optional) Have a look at `the documentation `_ for more information. diff --git a/pelican/themes/notmyidea/templates/.DS_Store b/pelican/themes/notmyidea/templates/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 - var GoSquared={}; - GoSquared.acct = "{{ GOSQUARED_SITENAME }}"; - (function(w){ - function gs(){ - w._gstc_lt=+(new Date); var d=document; - var g = d.createElement("script"); g.type = "text/javascript"; g.async = true; g.src = "//d1l6p2sc9645hc.cloudfront.net/tracker.js"; - var s = d.getElementsByTagName("script")[0]; s.parentNode.insertBefore(g, s); - } - w.addEventListener?w.addEventListener("load",gs,false):w.attachEvent("onload",gs); - })(window); - -{% endif %} From c461c6435df87bb0407d3459719e3278ffb5d55c Mon Sep 17 00:00:00 2001 From: Michael Guntsche Date: Sat, 16 Jun 2012 19:53:53 +0200 Subject: [PATCH 7/8] Fix HTML5 conformance of the notmyidea template The W3C validator complained that the pagination

was inside an

    . So just move it out of there. --- pelican/themes/notmyidea/templates/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pelican/themes/notmyidea/templates/index.html b/pelican/themes/notmyidea/templates/index.html index de607152..8752a6b6 100644 --- a/pelican/themes/notmyidea/templates/index.html +++ b/pelican/themes/notmyidea/templates/index.html @@ -41,12 +41,12 @@ {% endif %} - {% if loop.last and (articles_page.has_previous() - or not articles_page.has_previous() and loop.length > 1) %} - {% include 'pagination.html' %} - {% endif %} {% if loop.last %}
+ {% if loop.last and (articles_page.has_previous() + or not articles_page.has_previous() and loop.length > 1) %} + {% include 'pagination.html' %} + {% endif %} {% endif %} {% endfor %} From 083f302b194eaeedd76d65b96120f42f54112c22 Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Sat, 16 Jun 2012 11:23:55 -0700 Subject: [PATCH 8/8] Remove errant .DS_Store and add to .gitignore --- .gitignore | 1 + pelican/themes/notmyidea/templates/.DS_Store | Bin 6148 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100644 pelican/themes/notmyidea/templates/.DS_Store diff --git a/.gitignore b/.gitignore index 4029b327..9274ba2d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .*.swp .*.swo *.pyc +.DS_Store docs/_build docs/fr/_build build diff --git a/pelican/themes/notmyidea/templates/.DS_Store b/pelican/themes/notmyidea/templates/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0