From 4b2fcb09a4bfd3f099013bbf64550e57b1e13e55 Mon Sep 17 00:00:00 2001 From: Florian Jacob Date: Tue, 5 Nov 2013 19:38:58 +0100 Subject: [PATCH] Added a new ''modified:' metadata tag to be able to specify the publication time and date and the last modified time and date independently. This makes it possible to access the last updated date with {{ article.locale_modified }} in templates. Additionally, an already delivered feed entry can be corrected by changing the modified date and time, as it is used for atom:update / rss pubDate field now. --- docs/changelog.rst | 3 ++- docs/getting_started.rst | 7 ++++++ pelican/contents.py | 4 ++++ pelican/readers.py | 3 +++ .../article_with_markdown_and_footnote.md | 3 ++- ...icle_with_markdown_and_nonascii_summary.md | 1 + .../content/article_with_md_extension.md | 1 + .../tests/content/article_with_metadata.rst | 1 + .../basic/a-markdown-powered-article.html | 2 +- pelican/tests/output/basic/article-1.html | 2 +- pelican/tests/output/basic/article-2.html | 2 +- pelican/tests/output/basic/article-3.html | 2 +- .../output/basic/author/alexis-metaireau.html | 4 ++-- pelican/tests/output/basic/category/bar.html | 2 +- pelican/tests/output/basic/category/cat1.html | 8 +++---- pelican/tests/output/basic/category/misc.html | 8 +++---- pelican/tests/output/basic/category/yeah.html | 2 +- .../basic/filename_metadata-example.html | 2 +- pelican/tests/output/basic/index.html | 20 ++++++++-------- pelican/tests/output/basic/oh-yeah.html | 2 +- .../tests/output/basic/second-article-fr.html | 2 +- .../tests/output/basic/second-article.html | 2 +- pelican/tests/output/basic/tag/bar.html | 6 ++--- pelican/tests/output/basic/tag/baz.html | 2 +- pelican/tests/output/basic/tag/foo.html | 4 ++-- pelican/tests/output/basic/tag/foobar.html | 2 +- pelican/tests/output/basic/tag/yeah.html | 2 +- .../output/basic/this-is-a-super-article.html | 2 +- pelican/tests/output/basic/unbelievable.html | 2 +- .../custom/a-markdown-powered-article.html | 6 ++++- pelican/tests/output/custom/article-1.html | 6 ++++- pelican/tests/output/custom/article-2.html | 6 ++++- pelican/tests/output/custom/article-3.html | 6 ++++- .../custom/author/alexis-metaireau.html | 24 +++++++++++++++---- .../custom/author/alexis-metaireau2.html | 24 +++++++++++++++---- .../custom/author/alexis-metaireau3.html | 12 ++++++++-- pelican/tests/output/custom/category/bar.html | 6 ++++- .../tests/output/custom/category/cat1.html | 24 +++++++++++++++---- .../tests/output/custom/category/misc.html | 24 +++++++++++++++---- .../tests/output/custom/category/yeah.html | 6 ++++- .../output/custom/drafts/a-draft-article.html | 2 +- .../tests/output/custom/feeds/all-en.atom.xml | 20 ++++++++-------- .../tests/output/custom/feeds/all-fr.atom.xml | 2 +- .../tests/output/custom/feeds/all.atom.xml | 22 ++++++++--------- pelican/tests/output/custom/feeds/all.rss.xml | 24 +++++++++---------- .../tests/output/custom/feeds/bar.atom.xml | 2 +- pelican/tests/output/custom/feeds/bar.rss.xml | 4 ++-- .../tests/output/custom/feeds/cat1.atom.xml | 8 +++---- .../tests/output/custom/feeds/cat1.rss.xml | 10 ++++---- .../tests/output/custom/feeds/misc.atom.xml | 8 +++---- .../tests/output/custom/feeds/misc.rss.xml | 10 ++++---- .../tests/output/custom/feeds/yeah.atom.xml | 2 +- .../tests/output/custom/feeds/yeah.rss.xml | 4 ++-- .../custom/filename_metadata-example.html | 6 ++++- pelican/tests/output/custom/index.html | 24 +++++++++++++++---- pelican/tests/output/custom/index2.html | 24 +++++++++++++++---- pelican/tests/output/custom/index3.html | 12 ++++++++-- pelican/tests/output/custom/oh-yeah-fr.html | 2 +- pelican/tests/output/custom/oh-yeah.html | 6 ++++- .../output/custom/second-article-fr.html | 6 ++++- .../tests/output/custom/second-article.html | 6 ++++- pelican/tests/output/custom/tag/bar.html | 18 +++++++++++--- pelican/tests/output/custom/tag/baz.html | 6 ++++- pelican/tests/output/custom/tag/foo.html | 12 ++++++++-- pelican/tests/output/custom/tag/foobar.html | 6 ++++- pelican/tests/output/custom/tag/yeah.html | 6 ++++- .../custom/this-is-a-super-article.html | 6 ++++- pelican/tests/output/custom/unbelievable.html | 6 ++++- pelican/tests/test_readers.py | 4 ++++ .../notmyidea/templates/article_infos.html | 8 ++++++- pelican/themes/simple/templates/article.html | 5 ++++ pelican/themes/simple/templates/page.html | 3 +++ pelican/writers.py | 2 +- 73 files changed, 381 insertions(+), 152 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 54b0d871..976eecc8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,7 +4,8 @@ Release history Next release ============ -- Nothing yet +* Added the `:modified:` metadata field to complement `:date:`. + Used to specify the last date and time an article was updated independently from the date and time it was published. 3.3.0 (2013-09-24) ================== diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 201b9ad4..4860576c 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -301,6 +301,7 @@ this metadata in text files via the following syntax (give your file the ############## :date: 2010-10-03 10:20 + :modified: 2010-10-04 18:40 :tags: thats, awesome :category: yeah :slug: my-super-post @@ -320,6 +321,7 @@ pattern:: Title: My super title Date: 2010-12-03 10:20 + Modified: 2010-12-05 19:30 Category: Python Tags: pelican, publishing Slug: my-super-post @@ -341,6 +343,7 @@ interprets the HTML in a very straightforward manner, reading metadata from My super title + @@ -367,6 +370,10 @@ the W3C's `suggested subset ISO 8601`__. __ `W3C ISO 8601`_ +``modified`` should be last time you updated the article, and defaults to ``date`` if not specified. +Besides you can show ``modified`` in the templates, feed entries in feed readers will be updated automatically +when you set ``modified`` to the current date after you modified your article. + If you do not explicitly specify summary metadata for a given post, the ``SUMMARY_MAX_LENGTH`` setting can be used to specify how many words from the beginning of an article are used as the summary. diff --git a/pelican/contents.py b/pelican/contents.py index 059c54a7..96794026 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -113,6 +113,10 @@ class Content(object): if hasattr(self, 'date'): self.locale_date = strftime(self.date, self.date_format) + if not hasattr(self, 'modified'): + self.modified = self.date + if hasattr(self, 'modified'): + self.locale_modified = strftime(self.modified, self.date_format) # manage status if not hasattr(self, 'status'): diff --git a/pelican/readers.py b/pelican/readers.py index 6c279abc..c286e801 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -42,6 +42,7 @@ from pelican.utils import get_date, pelican_open METADATA_PROCESSORS = { 'tags': lambda x, y: [Tag(tag, y) for tag in x.split(',')], 'date': lambda x, y: get_date(x), + 'modified': lambda x, y: get_date(x), 'status': lambda x, y: x.strip(), 'category': Category, 'author': Author, @@ -521,6 +522,7 @@ def default_metadata(settings=None, process=None): metadata['category'] = value if 'DEFAULT_DATE' in settings and settings['DEFAULT_DATE'] != 'fs': metadata['date'] = datetime.datetime(*settings['DEFAULT_DATE']) + metadata['modified'] = metadata['date'] return metadata @@ -530,6 +532,7 @@ def path_metadata(full_path, source_path, settings=None): if settings.get('DEFAULT_DATE', None) == 'fs': metadata['date'] = datetime.datetime.fromtimestamp( os.stat(full_path).st_ctime) + metadata['modified'] = metadata['date'] metadata.update(settings.get('EXTRA_PATH_METADATA', {}).get( source_path, {})) return metadata diff --git a/pelican/tests/content/article_with_markdown_and_footnote.md b/pelican/tests/content/article_with_markdown_and_footnote.md index dc257d62..332ccea6 100644 --- a/pelican/tests/content/article_with_markdown_and_footnote.md +++ b/pelican/tests/content/article_with_markdown_and_footnote.md @@ -1,8 +1,9 @@ Title: Article with markdown containing footnotes Date: 2012-10-31 +Modified: 2012-11-01 Summary: Summary with **inline** markup *should* be supported. This is some content[^1] with some footnotes[^footnote] [^1]: Numbered footnote -[^footnote]: Named footnote \ No newline at end of file +[^footnote]: Named footnote diff --git a/pelican/tests/content/article_with_markdown_and_nonascii_summary.md b/pelican/tests/content/article_with_markdown_and_nonascii_summary.md index e26cc009..d76ed4a1 100644 --- a/pelican/tests/content/article_with_markdown_and_nonascii_summary.md +++ b/pelican/tests/content/article_with_markdown_and_nonascii_summary.md @@ -1,6 +1,7 @@ Title: マックOS X 10.8でパイソンとVirtualenvをインストールと設定 Slug: python-virtualenv-on-mac-osx-mountain-lion-10.8 Date: 2012-12-20 +Modified: 2012-12-22 Tags: パイソン, マック Category: 指導書 Summary: パイソンとVirtualenvをまっくでインストールする方法について明確に説明します。 diff --git a/pelican/tests/content/article_with_md_extension.md b/pelican/tests/content/article_with_md_extension.md index 1f111796..89b6980c 100644 --- a/pelican/tests/content/article_with_md_extension.md +++ b/pelican/tests/content/article_with_md_extension.md @@ -2,6 +2,7 @@ Title: Test md File Category: test Tags: foo, bar, foobar Date: 2010-12-02 10:14 +Modified: 2010-12-02 10:20 Summary: I have a lot to test Test Markdown File Header diff --git a/pelican/tests/content/article_with_metadata.rst b/pelican/tests/content/article_with_metadata.rst index d4bac1c0..c5768cfb 100644 --- a/pelican/tests/content/article_with_metadata.rst +++ b/pelican/tests/content/article_with_metadata.rst @@ -4,6 +4,7 @@ This is a super article ! :tags: foo, bar, foobar :date: 2010-12-02 10:14 +:modified: 2010-12-02 10:20 :category: yeah :author: Alexis Métaireau :summary: diff --git a/pelican/tests/output/basic/a-markdown-powered-article.html b/pelican/tests/output/basic/a-markdown-powered-article.html index 6bc29eba..40c96766 100644 --- a/pelican/tests/output/basic/a-markdown-powered-article.html +++ b/pelican/tests/output/basic/a-markdown-powered-article.html @@ -35,7 +35,7 @@