From debd6fb3b4a472c80a8fc7924eddf6e79856e725 Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Wed, 28 Nov 2012 00:29:30 +0100 Subject: [PATCH 1/7] add FILENAME_METADATA setting to extract metadata from filename FILENAME_METADATA default to '(?P\d{4}-\d{2}-\d{2}).*' which will allow to extract date metadata from the filename. --- pelican/readers.py | 14 +++++++++++++- pelican/settings.py | 12 +++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index f04b4a03..ad2b0f74 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import os +import re try: import docutils import docutils.core @@ -207,8 +209,9 @@ for cls in Reader.__subclasses__(): def read_file(filename, fmt=None, settings=None): """Return a reader object using the given format.""" + base, ext = os.path.splitext(os.path.basename(filename)) if not fmt: - fmt = filename.split('.')[-1] + fmt = ext[1:] if fmt not in _EXTENSIONS: raise TypeError('Pelican does not know how to parse %s' % filename) @@ -230,4 +233,13 @@ def read_file(filename, fmt=None, settings=None): content = typogrify(content) metadata['title'] = typogrify(metadata['title']) + filename_metadata = settings and settings.get('FILENAME_METADATA') + if filename_metadata: + match = re.match(filename_metadata, base) + if match: + for k, v in match.groupdict().iteritems(): + if k not in metadata: + k = k.lower() # metadata must be lowercase + metadata[k] = reader.process_metadata(k, v) + return content, metadata diff --git a/pelican/settings.py b/pelican/settings.py index d2c0cef5..a98f3538 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -5,6 +5,7 @@ import inspect import os import locale import logging +import re from os.path import isabs @@ -60,7 +61,7 @@ _DEFAULT_CONFIG = {'PATH': '.', 'TAG_CLOUD_STEPS': 4, 'TAG_CLOUD_MAX_ITEMS': 100, 'DIRECT_TEMPLATES': ('index', 'tags', 'categories', 'archives'), - 'EXTRA_TEMPLATES_PATHS' : [], + 'EXTRA_TEMPLATES_PATHS': [], 'PAGINATED_DIRECT_TEMPLATES': ('index', ), 'PELICAN_CLASS': 'pelican.Pelican', 'DEFAULT_DATE_FORMAT': '%a %d %B %Y', @@ -70,6 +71,7 @@ _DEFAULT_CONFIG = {'PATH': '.', 'DEFAULT_PAGINATION': False, 'DEFAULT_ORPHANS': 0, 'DEFAULT_METADATA': (), + 'FILENAME_METADATA': '(?P\d{4}-\d{2}-\d{2}).*', 'FILES_TO_COPY': (), 'DEFAULT_STATUS': 'published', 'ARTICLE_PERMALINK_STRUCTURE': '', @@ -205,4 +207,12 @@ def configure_settings(settings): " falling back to the default extension " + _DEFAULT_CONFIG['OUTPUT_SOURCES_EXTENSION']) + filename_metadata = settings.get('FILENAME_METADATA') + if filename_metadata and not isinstance(filename_metadata, basestring): + logger.error("Detected misconfiguration with FILENAME_METADATA" + " setting (must be string or compiled pattern), falling" + "back to the default") + settings['FILENAME_METADATA'] = \ + _DEFAULT_CONFIG['FILENAME_METADATA'] + return settings From 3a25f82c4fc95c4654a7d85eb0fdd85e39cfb904 Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Wed, 28 Nov 2012 01:01:15 +0100 Subject: [PATCH 2/7] update docs/settings.rst for both DEFAULT_METADATA and FILENAME_METADATA --- docs/settings.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/settings.rst b/docs/settings.rst index 7d73afe0..2ce44dfb 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -50,6 +50,16 @@ Setting name (default value) What doe If tuple object, it will instead generate the default datetime object by passing the tuple to the datetime.datetime constructor. +`DEFAULT_METADATA` (``()``) The default metadata you want to use for all articles + and pages. +`FILENAME_METADATA` (``'(?P\d{4}-\d{2}-\d{2}).*'``) The regexp that will be used to extract any metadata + from the filename. All named groups that are matched + will be set in the metadata object. + The default value will only extract the date from + the filename. + For example, if you would like to extract both the + date and the slug, you could set something like: + ``'(?P\d{4}-\d{2}-\d{2})_(?.*)'``. `DELETE_OUTPUT_DIRECTORY` (``False``) Delete the content of the output directory before generating new files. `FILES_TO_COPY` (``()``) A list of files (or directories) to copy from the source (inside the From dfab8ed5b96a03ac35394acc3123ca0b79eb552e Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Fri, 30 Nov 2012 01:12:59 +0100 Subject: [PATCH 3/7] test the "metadata from filename" feature --- pelican/readers.py | 2 +- ...2012-11-29_rst_w_filename_meta#foo-bar.rst | 6 ++ .../2012-11-30_md_w_filename_meta#foo-bar.md | 6 ++ tests/test_readers.py | 93 +++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tests/content/2012-11-29_rst_w_filename_meta#foo-bar.rst create mode 100644 tests/content/2012-11-30_md_w_filename_meta#foo-bar.md diff --git a/pelican/readers.py b/pelican/readers.py index ad2b0f74..74cec02f 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -228,7 +228,7 @@ def read_file(filename, fmt=None, settings=None): content, metadata = reader.read(filename) # eventually filter the content with typogrify if asked so - if settings and settings['TYPOGRIFY']: + if settings and settings.get('TYPOGRIFY'): from typogrify.filters import typogrify content = typogrify(content) metadata['title'] = typogrify(metadata['title']) diff --git a/tests/content/2012-11-29_rst_w_filename_meta#foo-bar.rst b/tests/content/2012-11-29_rst_w_filename_meta#foo-bar.rst new file mode 100644 index 00000000..43f05a15 --- /dev/null +++ b/tests/content/2012-11-29_rst_w_filename_meta#foo-bar.rst @@ -0,0 +1,6 @@ + +Rst with filename metadata +########################## + +:category: yeah +:author: Alexis Métaireau diff --git a/tests/content/2012-11-30_md_w_filename_meta#foo-bar.md b/tests/content/2012-11-30_md_w_filename_meta#foo-bar.md new file mode 100644 index 00000000..cdccfc8a --- /dev/null +++ b/tests/content/2012-11-30_md_w_filename_meta#foo-bar.md @@ -0,0 +1,6 @@ +category: yeah +author: Alexis Métaireau + +Markdown with filename metadata +=============================== + diff --git a/tests/test_readers.py b/tests/test_readers.py index c9d22c18..dcfee809 100644 --- a/tests/test_readers.py +++ b/tests/test_readers.py @@ -34,6 +34,50 @@ class RstReaderTest(unittest.TestCase): for key, value in expected.items(): self.assertEquals(value, metadata[key], key) + def test_article_with_filename_metadata(self): + content, metadata = readers.read_file( + _filename('2012-11-29_rst_w_filename_meta#foo-bar.rst'), + settings={}) + expected = { + 'category': 'yeah', + 'author': u'Alexis Métaireau', + 'title': 'Rst with filename metadata', + } + for key, value in metadata.items(): + self.assertEquals(value, expected[key], key) + + content, metadata = readers.read_file( + _filename('2012-11-29_rst_w_filename_meta#foo-bar.rst'), + settings={ + 'FILENAME_METADATA': '(?P\d{4}-\d{2}-\d{2}).*' + }) + expected = { + 'category': 'yeah', + 'author': u'Alexis Métaireau', + 'title': 'Rst with filename metadata', + 'date': datetime.datetime(2012, 11, 29), + } + for key, value in metadata.items(): + self.assertEquals(value, expected[key], key) + + content, metadata = readers.read_file( + _filename('2012-11-29_rst_w_filename_meta#foo-bar.rst'), + settings={ + 'FILENAME_METADATA': '(?P\d{4}-\d{2}-\d{2})_' \ + '_(?P.*)' \ + '#(?P.*)-(?P.*)' + }) + expected = { + 'category': 'yeah', + 'author': u'Alexis Métaireau', + 'title': 'Rst with filename metadata', + 'date': datetime.datetime(2012, 11, 29), + 'slug': 'article_with_filename_metadata', + 'mymeta': 'foo', + } + for key, value in metadata.items(): + self.assertEquals(value, expected[key], key) + def test_article_metadata_key_lowercase(self): """Keys of metadata should be lowercase.""" reader = readers.RstReader({}) @@ -80,6 +124,13 @@ class MdReaderTest(unittest.TestCase): self.assertEqual(content, expected) + expected = { + 'category': 'test', + 'title': 'Test md File', + } + for key, value in metadata.items(): + self.assertEquals(value, expected[key], key) + @unittest.skipUnless(readers.Markdown, "markdown isn't installed") def test_article_with_mkd_extension(self): # test to ensure the mkd extension is being processed by the correct reader @@ -110,6 +161,48 @@ class MdReaderTest(unittest.TestCase): self.assertEqual(content, expected) + @unittest.skipUnless(readers.Markdown, "markdown isn't installed") + def test_article_with_filename_metadata(self): + content, metadata = readers.read_file( + _filename('2012-11-30_md_w_filename_meta#foo-bar.md'), + settings={}) + expected = { + 'category': 'yeah', + 'author': u'Alexis Métaireau', + } + for key, value in expected.items(): + self.assertEquals(value, metadata[key], key) + + content, metadata = readers.read_file( + _filename('2012-11-30_md_w_filename_meta#foo-bar.md'), + settings={ + 'FILENAME_METADATA': '(?P\d{4}-\d{2}-\d{2}).*' + }) + expected = { + 'category': 'yeah', + 'author': u'Alexis Métaireau', + 'date': datetime.datetime(2012, 11, 30), + } + for key, value in expected.items(): + self.assertEquals(value, metadata[key], key) + + content, metadata = readers.read_file( + _filename('2012-11-30_md_w_filename_meta#foo-bar.md'), + settings={ + 'FILENAME_METADATA': '(?P\d{4}-\d{2}-\d{2})' + '_(?P.*)' + '#(?P.*)-(?P.*)' + }) + expected = { + 'category': 'yeah', + 'author': u'Alexis Métaireau', + 'date': datetime.datetime(2012, 11, 30), + 'slug': 'md_w_filename_meta', + 'mymeta': 'foo', + } + for key, value in expected.items(): + self.assertEquals(value, metadata[key], key) + class AdReaderTest(unittest.TestCase): @unittest.skipUnless(readers.asciidoc, "asciidoc isn't installed") From 92b9ccb08a077675984986c4f36fedf73c0e803b Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Fri, 30 Nov 2012 01:29:11 +0100 Subject: [PATCH 4/7] fix failing TestArticlesGenerator.test_generate_context test new file have been added to the content directory so articles_expected needs to be updated --- tests/test_generators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_generators.py b/tests/test_generators.py index 7abaf687..90b19227 100644 --- a/tests/test_generators.py +++ b/tests/test_generators.py @@ -73,6 +73,7 @@ class TestArticlesGenerator(unittest.TestCase): [u'Article title', 'published', 'Default', 'article'], [u'Article with template', 'published', 'Default', 'custom'], [u'Test md File', 'published', 'test', 'article'], + [u'Rst with filename metadata', 'published', u'yeah', 'article'], [u'Test Markdown extensions', 'published', u'Default', 'article'], [u'This is a super article !', 'published', 'Yeah', 'article'], [u'This is an article with category !', 'published', 'yeah', 'article'], From fc13ae8e7605db6cac1f3e7dfac5aa9777d088b0 Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Fri, 30 Nov 2012 01:48:28 +0100 Subject: [PATCH 5/7] add new file to functional test content to showcase FILENAME_METADATA and update functional tests output --- .../content/2012-11-30_filename-metadata.rst | 4 + tests/output/basic/archives.html | 2 + tests/output/basic/category/misc.html | 40 ++++-- tests/output/basic/feeds/all-en.atom.xml | 3 +- tests/output/basic/feeds/all.atom.xml | 3 +- tests/output/basic/feeds/misc.atom.xml | 3 +- .../basic/filename_metadata-example.html | 66 ++++++++++ tests/output/basic/index.html | 40 ++++-- tests/output/custom/archives.html | 2 + .../custom/author/alexis-metaireau.html | 2 +- .../custom/author/alexis-metaireau2.html | 55 ++++----- .../custom/author/alexis-metaireau3.html | 115 +++++++++++++++++ tests/output/custom/category/misc.html | 43 +++++-- tests/output/custom/feeds/all-en.atom.xml | 3 +- tests/output/custom/feeds/all.atom.xml | 3 +- tests/output/custom/feeds/all.rss.xml | 3 +- tests/output/custom/feeds/misc.atom.xml | 3 +- tests/output/custom/feeds/misc.rss.xml | 3 +- .../custom/filename_metadata-example.html | 116 ++++++++++++++++++ tests/output/custom/index.html | 70 +++++------ tests/output/custom/index2.html | 55 ++++----- tests/output/custom/index3.html | 115 +++++++++++++++++ 22 files changed, 622 insertions(+), 127 deletions(-) create mode 100644 samples/content/2012-11-30_filename-metadata.rst create mode 100644 tests/output/basic/filename_metadata-example.html create mode 100644 tests/output/custom/author/alexis-metaireau3.html create mode 100644 tests/output/custom/filename_metadata-example.html create mode 100644 tests/output/custom/index3.html diff --git a/samples/content/2012-11-30_filename-metadata.rst b/samples/content/2012-11-30_filename-metadata.rst new file mode 100644 index 00000000..b048103d --- /dev/null +++ b/samples/content/2012-11-30_filename-metadata.rst @@ -0,0 +1,4 @@ +FILENAME_METADATA example +######################### + +Some cool stuff! diff --git a/tests/output/basic/archives.html b/tests/output/basic/archives.html index 0bccff9b..cb06dfa1 100644 --- a/tests/output/basic/archives.html +++ b/tests/output/basic/archives.html @@ -33,6 +33,8 @@

Archives for A Pelican Blog

+
Fri 30 November 2012
+
FILENAME_METADATA example
Wed 29 February 2012
Second article
Wed 20 April 2011
diff --git a/tests/output/basic/category/misc.html b/tests/output/basic/category/misc.html index 86cf5470..2d62b852 100644 --- a/tests/output/basic/category/misc.html +++ b/tests/output/basic/category/misc.html @@ -34,8 +34,32 @@ +
+

Other articles

+
+
    + + + +
  1. +
    +

    Second article

    +
    + +
    +
    Wed 29 February 2012 @@ -44,14 +68,12 @@

    tags: foobarbaz

    Translations: fr -

    This is some article, in english

    -
    - -
    -

    Other articles

    -
    -
      - +

      This is some article, in english

      + + read more + + +
    1. diff --git a/tests/output/basic/feeds/all-en.atom.xml b/tests/output/basic/feeds/all-en.atom.xml index fc05c4b3..54c87905 100644 --- a/tests/output/basic/feeds/all-en.atom.xml +++ b/tests/output/basic/feeds/all-en.atom.xml @@ -1,5 +1,6 @@ -A Pelican Blog/2012-02-29T00:00:00ZSecond article2012-02-29T00:00:00Ztag:,2012-02-29:second-article.html<p>This is some article, in english</p> +A Pelican Blog/2012-11-30T00:00:00ZFILENAME_METADATA example2012-11-30T00:00:00Ztag:,2012-11-30:filename_metadata-example.html<p>Some cool stuff!</p> +Second article2012-02-29T00:00:00Ztag:,2012-02-29:second-article.html<p>This is some article, in english</p> A markdown powered article2011-04-20T00:00:00Ztag:,2011-04-20:a-markdown-powered-article.html<p>You're mutually oblivious.</p> <p><a href="/unbelievable.html">a root-relative link to unbelievable</a> <a href="/unbelievable.html">a file-relative link to unbelievable</a></p>Article 12011-02-17T00:00:00Ztag:,2011-02-17:article-1.html<p>Article 1</p> diff --git a/tests/output/basic/feeds/all.atom.xml b/tests/output/basic/feeds/all.atom.xml index f3a1a6f4..3081adc6 100644 --- a/tests/output/basic/feeds/all.atom.xml +++ b/tests/output/basic/feeds/all.atom.xml @@ -1,5 +1,6 @@ -A Pelican Blog/2012-02-29T00:00:00ZSecond article2012-02-29T00:00:00Ztag:,2012-02-29:second-article.html<p>This is some article, in english</p> +A Pelican Blog/2012-11-30T00:00:00ZFILENAME_METADATA example2012-11-30T00:00:00Ztag:,2012-11-30:filename_metadata-example.html<p>Some cool stuff!</p> +Second article2012-02-29T00:00:00Ztag:,2012-02-29:second-article.html<p>This is some article, in english</p> Deuxième article2012-02-29T00:00:00Ztag:,2012-02-29:second-article-fr.html<p>Ceci est un article, en français.</p> A markdown powered article2011-04-20T00:00:00Ztag:,2011-04-20:a-markdown-powered-article.html<p>You're mutually oblivious.</p> <p><a href="/unbelievable.html">a root-relative link to unbelievable</a> diff --git a/tests/output/basic/feeds/misc.atom.xml b/tests/output/basic/feeds/misc.atom.xml index 40ad44c5..e71bd151 100644 --- a/tests/output/basic/feeds/misc.atom.xml +++ b/tests/output/basic/feeds/misc.atom.xml @@ -1,5 +1,6 @@ -A Pelican Blog/2012-02-29T00:00:00ZSecond article2012-02-29T00:00:00Ztag:,2012-02-29:second-article.html<p>This is some article, in english</p> +A Pelican Blog/2012-11-30T00:00:00ZFILENAME_METADATA example2012-11-30T00:00:00Ztag:,2012-11-30:filename_metadata-example.html<p>Some cool stuff!</p> +Second article2012-02-29T00:00:00Ztag:,2012-02-29:second-article.html<p>This is some article, in english</p> Unbelievable !2010-10-15T20:30:00Ztag:,2010-10-15:unbelievable.html<p>Or completely awesome. Depends the needs.</p> <p><a class="reference external" href="/a-markdown-powered-article.html">a root-relative link to markdown-article</a> <a class="reference external" href="/a-markdown-powered-article.html">a file-relative link to markdown-article</a></p> diff --git a/tests/output/basic/filename_metadata-example.html b/tests/output/basic/filename_metadata-example.html new file mode 100644 index 00000000..b7ae95a7 --- /dev/null +++ b/tests/output/basic/filename_metadata-example.html @@ -0,0 +1,66 @@ + + + + FILENAME_METADATA example + + + + + + + + + + + + + + +
      + +
      +
      +
      + + + + + \ No newline at end of file diff --git a/tests/output/basic/index.html b/tests/output/basic/index.html index 97bb5256..488d1b08 100644 --- a/tests/output/basic/index.html +++ b/tests/output/basic/index.html @@ -34,8 +34,32 @@ +
      +

      Other articles

      +
      +
        + + + +
      1. +
        +

        Second article

        +
        + +
        +
        Wed 29 February 2012 @@ -44,14 +68,12 @@

        tags: foobarbaz

        Translations: fr -

        This is some article, in english

        -
        - -
        -

        Other articles

        -
        -
          - +

          This is some article, in english

          + + read more + +
    2. +
    3. diff --git a/tests/output/custom/archives.html b/tests/output/custom/archives.html index 44bc876e..632387a4 100644 --- a/tests/output/custom/archives.html +++ b/tests/output/custom/archives.html @@ -37,6 +37,8 @@

      Archives for Alexis' log

      +
      Fri 30 November 2012
      +
      FILENAME_METADATA example
      Wed 29 February 2012
      Second article
      Wed 20 April 2011
      diff --git a/tests/output/custom/author/alexis-metaireau.html b/tests/output/custom/author/alexis-metaireau.html index eb39ae57..8bb0dd1c 100644 --- a/tests/output/custom/author/alexis-metaireau.html +++ b/tests/output/custom/author/alexis-metaireau.html @@ -134,7 +134,7 @@

    - Page 1 / 2 + Page 1 / 3 »

    diff --git a/tests/output/custom/author/alexis-metaireau2.html b/tests/output/custom/author/alexis-metaireau2.html index a87c85af..59926d8c 100644 --- a/tests/output/custom/author/alexis-metaireau2.html +++ b/tests/output/custom/author/alexis-metaireau2.html @@ -39,6 +39,31 @@
      +
    1. + + +
    2. - - - -

    « - Page 2 / 2 + Page 2 / 3 + »

    diff --git a/tests/output/custom/author/alexis-metaireau3.html b/tests/output/custom/author/alexis-metaireau3.html new file mode 100644 index 00000000..5f2ecbb1 --- /dev/null +++ b/tests/output/custom/author/alexis-metaireau3.html @@ -0,0 +1,115 @@ + + + + Alexis' log - Alexis Métaireau + + + + + + + + + + + + + + + +Fork me on GitHub + + + + + + +
    +
      +
    1. +
    +

    + « + Page 3 / 3 +

    +
    +
    +
    +

    blogroll

    + +
    + +
    + + + + + + \ No newline at end of file diff --git a/tests/output/custom/category/misc.html b/tests/output/custom/category/misc.html index 24a53791..33acbd70 100644 --- a/tests/output/custom/category/misc.html +++ b/tests/output/custom/category/misc.html @@ -38,8 +38,35 @@ +
    +

    Other articles

    +
    +
      + + + +
    1. - -
      -

      Other articles

      -
      -
        - +

        This is some article, in english

        + + read more +

        There are comments.

        + +
      1. diff --git a/tests/output/custom/feeds/all-en.atom.xml b/tests/output/custom/feeds/all-en.atom.xml index f8eb3219..5c8f9241 100644 --- a/tests/output/custom/feeds/all-en.atom.xml +++ b/tests/output/custom/feeds/all-en.atom.xml @@ -1,5 +1,6 @@ -Alexis' loghttp://blog.notmyidea.org/2012-02-29T00:00:00+01:00Second article2012-02-29T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2012-02-29:second-article.html<p>This is some article, in english</p> +Alexis' loghttp://blog.notmyidea.org/2012-11-30T00:00:00+01:00FILENAME_METADATA example2012-11-30T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2012-11-30:filename_metadata-example.html<p>Some cool stuff!</p> +Second article2012-02-29T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2012-02-29:second-article.html<p>This is some article, in english</p> A markdown powered article2011-04-20T00:00:00+02:00Alexis Métaireautag:blog.notmyidea.org,2011-04-20:a-markdown-powered-article.html<p>You're mutually oblivious.</p> <p><a href="http://blog.notmyidea.org/unbelievable.html">a root-relative link to unbelievable</a> <a href="http://blog.notmyidea.org/unbelievable.html">a file-relative link to unbelievable</a></p>Article 12011-02-17T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2011-02-17:article-1.html<p>Article 1</p> diff --git a/tests/output/custom/feeds/all.atom.xml b/tests/output/custom/feeds/all.atom.xml index b009d135..ae5fe30c 100644 --- a/tests/output/custom/feeds/all.atom.xml +++ b/tests/output/custom/feeds/all.atom.xml @@ -1,5 +1,6 @@ -Alexis' loghttp://blog.notmyidea.org/2012-03-02T14:01:01+01:00Trop bien !2012-03-02T14:01:01+01:00Alexis Métaireautag:blog.notmyidea.org,2012-03-02:oh-yeah-fr.html<p>Et voila du contenu en français</p> +Alexis' loghttp://blog.notmyidea.org/2012-11-30T00:00:00+01:00FILENAME_METADATA example2012-11-30T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2012-11-30:filename_metadata-example.html<p>Some cool stuff!</p> +Trop bien !2012-03-02T14:01:01+01:00Alexis Métaireautag:blog.notmyidea.org,2012-03-02:oh-yeah-fr.html<p>Et voila du contenu en français</p> Second article2012-02-29T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2012-02-29:second-article.html<p>This is some article, in english</p> Deuxième article2012-02-29T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2012-02-29:second-article-fr.html<p>Ceci est un article, en français.</p> A markdown powered article2011-04-20T00:00:00+02:00Alexis Métaireautag:blog.notmyidea.org,2011-04-20:a-markdown-powered-article.html<p>You're mutually oblivious.</p> diff --git a/tests/output/custom/feeds/all.rss.xml b/tests/output/custom/feeds/all.rss.xml index 786cb097..0ce2c837 100644 --- a/tests/output/custom/feeds/all.rss.xml +++ b/tests/output/custom/feeds/all.rss.xml @@ -1,5 +1,6 @@ -Alexis' loghttp://blog.notmyidea.org/Fri, 02 Mar 2012 14:01:01 +0100Trop bien !http://blog.notmyidea.org/oh-yeah-fr.html<p>Et voila du contenu en français</p> +Alexis' loghttp://blog.notmyidea.org/Fri, 30 Nov 2012 00:00:00 +0100FILENAME_METADATA examplehttp://blog.notmyidea.org/filename_metadata-example.html<p>Some cool stuff!</p> +Alexis MétaireauFri, 30 Nov 2012 00:00:00 +0100tag:blog.notmyidea.org,2012-11-30:filename_metadata-example.htmlTrop bien !http://blog.notmyidea.org/oh-yeah-fr.html<p>Et voila du contenu en français</p> Alexis MétaireauFri, 02 Mar 2012 14:01:01 +0100tag:blog.notmyidea.org,2012-03-02:oh-yeah-fr.htmlSecond articlehttp://blog.notmyidea.org/second-article.html<p>This is some article, in english</p> Alexis MétaireauWed, 29 Feb 2012 00:00:00 +0100tag:blog.notmyidea.org,2012-02-29:second-article.htmlfoobarbazDeuxième articlehttp://blog.notmyidea.org/second-article-fr.html<p>Ceci est un article, en français.</p> Alexis MétaireauWed, 29 Feb 2012 00:00:00 +0100tag:blog.notmyidea.org,2012-02-29:second-article-fr.htmlfoobarbazA markdown powered articlehttp://blog.notmyidea.org/a-markdown-powered-article.html<p>You're mutually oblivious.</p> diff --git a/tests/output/custom/feeds/misc.atom.xml b/tests/output/custom/feeds/misc.atom.xml index dbf8bbfd..45c996f3 100644 --- a/tests/output/custom/feeds/misc.atom.xml +++ b/tests/output/custom/feeds/misc.atom.xml @@ -1,5 +1,6 @@ -Alexis' loghttp://blog.notmyidea.org/2012-02-29T00:00:00+01:00Second article2012-02-29T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2012-02-29:second-article.html<p>This is some article, in english</p> +Alexis' loghttp://blog.notmyidea.org/2012-11-30T00:00:00+01:00FILENAME_METADATA example2012-11-30T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2012-11-30:filename_metadata-example.html<p>Some cool stuff!</p> +Second article2012-02-29T00:00:00+01:00Alexis Métaireautag:blog.notmyidea.org,2012-02-29:second-article.html<p>This is some article, in english</p> Unbelievable !2010-10-15T20:30:00+02:00Alexis Métaireautag:blog.notmyidea.org,2010-10-15:unbelievable.html<p>Or completely awesome. Depends the needs.</p> <p><a class="reference external" href="http://blog.notmyidea.org/a-markdown-powered-article.html">a root-relative link to markdown-article</a> <a class="reference external" href="http://blog.notmyidea.org/a-markdown-powered-article.html">a file-relative link to markdown-article</a></p> diff --git a/tests/output/custom/feeds/misc.rss.xml b/tests/output/custom/feeds/misc.rss.xml index bbc5a48e..a0fa290d 100644 --- a/tests/output/custom/feeds/misc.rss.xml +++ b/tests/output/custom/feeds/misc.rss.xml @@ -1,5 +1,6 @@ -Alexis' loghttp://blog.notmyidea.org/Wed, 29 Feb 2012 00:00:00 +0100Second articlehttp://blog.notmyidea.org/second-article.html<p>This is some article, in english</p> +Alexis' loghttp://blog.notmyidea.org/Fri, 30 Nov 2012 00:00:00 +0100FILENAME_METADATA examplehttp://blog.notmyidea.org/filename_metadata-example.html<p>Some cool stuff!</p> +Alexis MétaireauFri, 30 Nov 2012 00:00:00 +0100tag:blog.notmyidea.org,2012-11-30:filename_metadata-example.htmlSecond articlehttp://blog.notmyidea.org/second-article.html<p>This is some article, in english</p> Alexis MétaireauWed, 29 Feb 2012 00:00:00 +0100tag:blog.notmyidea.org,2012-02-29:second-article.htmlfoobarbazUnbelievable !http://blog.notmyidea.org/unbelievable.html<p>Or completely awesome. Depends the needs.</p> <p><a class="reference external" href="http://blog.notmyidea.org/a-markdown-powered-article.html">a root-relative link to markdown-article</a> <a class="reference external" href="http://blog.notmyidea.org/a-markdown-powered-article.html">a file-relative link to markdown-article</a></p> diff --git a/tests/output/custom/filename_metadata-example.html b/tests/output/custom/filename_metadata-example.html new file mode 100644 index 00000000..8f6353cb --- /dev/null +++ b/tests/output/custom/filename_metadata-example.html @@ -0,0 +1,116 @@ + + + + FILENAME_METADATA example + + + + + + + + + + + + + + + +Fork me on GitHub + + +
        +
        +
        +

        + FILENAME_METADATA example

        +
        + +
        +

        Some cool stuff!

        + +
        +
        +

        Comments !

        +
        + +
        + +
        +
        +
        +
        +

        blogroll

        + +
        + +
        + + + + + + \ No newline at end of file diff --git a/tests/output/custom/index.html b/tests/output/custom/index.html index eab96fa1..cc905735 100644 --- a/tests/output/custom/index.html +++ b/tests/output/custom/index.html @@ -38,8 +38,35 @@ +
        +

        Other articles

        +
        +
          + + + +
        1. - -
          -

          Other articles

          -
          -
            - +

            This is some article, in english

            + + read more +

            There are comments.

            +
      2. +
      3. - - - -

      - Page 1 / 2 + Page 1 / 3 »

      diff --git a/tests/output/custom/index2.html b/tests/output/custom/index2.html index 5269ed70..f0d2f948 100644 --- a/tests/output/custom/index2.html +++ b/tests/output/custom/index2.html @@ -39,6 +39,31 @@
        +
      1. + + +
      2. - - - -

      « - Page 2 / 2 + Page 2 / 3 + »

      diff --git a/tests/output/custom/index3.html b/tests/output/custom/index3.html new file mode 100644 index 00000000..60f8633d --- /dev/null +++ b/tests/output/custom/index3.html @@ -0,0 +1,115 @@ + + + + Alexis' log + + + + + + + + + + + + + + + +Fork me on GitHub + + + + + + +
      +
        +
      1. +
      +

      + « + Page 3 / 3 +

      +
      +
      +
      +

      blogroll

      + +
      + +
      + + + + + + \ No newline at end of file From 070fa1ff9dcb7603e0c555168f27bb057694a6b2 Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Fri, 30 Nov 2012 02:19:38 +0100 Subject: [PATCH 6/7] add more docs about FILENAME_METADATA --- docs/changelog.rst | 2 ++ docs/getting_started.rst | 29 ++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index f25ee3d9..ab3a4233 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -25,6 +25,8 @@ Release history file within the same directory as the original file to prevent the server (e.g. Nginx) from compressing files during an HTTP call. * Add AsciiDoc support +* Add ``FILENAME_METADATA`` new setting which adds support for metadata + extraction from the filename. 3.0 (2012-08-08) ================== diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 73378fc4..6be7fbb2 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -181,15 +181,26 @@ syntax for Markdown posts should follow this pattern:: This is the content of my super blog post. -Note that, aside from the title, none of this metadata is mandatory: if the date -is not specified, Pelican will rely on the file's "mtime" timestamp, and the -category can be determined by the directory in which the file resides. For -example, a file located at ``python/foobar/myfoobar.rst`` will have a category of -``foobar``. If you would like to organize your files in other ways where the -name of the subfolder would not be a good category name, you can set the -setting ``USE_FOLDER_AS_CATEGORY`` to ``False``. If summary isn't given, setting -``SUMMARY_MAX_LENGTH`` determines how many words from the beginning of an article -are used as the summary. +Note that, aside from the title, none of this metadata is mandatory: if the +date is not specified, Pelican can rely on the file's "mtime" timestamp through +the ``DEFAULT_DATE`` setting, and the category can be determined by the +directory in which the file resides. For example, a file located at +``python/foobar/myfoobar.rst`` will have a category of ``foobar``. If you would +like to organize your files in other ways where the name of the subfolder would +not be a good category name, you can set the setting ``USE_FOLDER_AS_CATEGORY`` +to ``False``. If summary isn't given, setting ``SUMMARY_MAX_LENGTH`` determines +how many words from the beginning of an article are used as the summary. + +You can also extract any metadata from the filename through a regexp to be set +in the ``FILENAME_METADATA`` setting. +All named groups that are matched will be set in the metadata object. The +default value for the ``FILENAME_METADATA`` setting will only extract the date +from the filename. For example, if you would like to extract both the date and +the slug, you could set something like: +``'(?P\d{4}-\d{2}-\d{2})_(?.*)'``. + +Please note that the metadata available inside your files takes precedence over +the metadata extracted from the filename. Generate your blog ------------------ From f86e1128f0b535efc8e20f1da2d1c045991051b7 Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Fri, 30 Nov 2012 09:48:30 +0100 Subject: [PATCH 7/7] docfix: fix example of FILENAME_METADATA regexp --- docs/getting_started.rst | 2 +- docs/settings.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 6be7fbb2..b0b5bf92 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -197,7 +197,7 @@ All named groups that are matched will be set in the metadata object. The default value for the ``FILENAME_METADATA`` setting will only extract the date from the filename. For example, if you would like to extract both the date and the slug, you could set something like: -``'(?P\d{4}-\d{2}-\d{2})_(?.*)'``. +``'(?P\d{4}-\d{2}-\d{2})_(?P.*)'``. Please note that the metadata available inside your files takes precedence over the metadata extracted from the filename. diff --git a/docs/settings.rst b/docs/settings.rst index 2ce44dfb..fc019757 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -59,7 +59,7 @@ Setting name (default value) What doe the filename. For example, if you would like to extract both the date and the slug, you could set something like: - ``'(?P\d{4}-\d{2}-\d{2})_(?.*)'``. + ``'(?P\d{4}-\d{2}-\d{2})_(?P.*)'``. `DELETE_OUTPUT_DIRECTORY` (``False``) Delete the content of the output directory before generating new files. `FILES_TO_COPY` (``()``) A list of files (or directories) to copy from the source (inside the