From e2ca6d76086eb3bbde961dfa2e7e1dd3a9a8452d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Sat, 17 Aug 2013 17:36:13 +0200 Subject: [PATCH] Add categories and tags to the replacement mechanism. --- docs/getting_started.rst | 4 ++++ pelican/contents.py | 4 ++++ pelican/tests/test_contents.py | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 6d9a8c41..bad9bbda 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -459,6 +459,10 @@ following to ``pelicanconf.py``:: And then the ``pdfs`` directory would also be copied to ``output/static/``. +You can also link to categories or tags, using the `|tag|tagname` and +`|category|foobar` syntax. + + Importing an existing blog -------------------------- diff --git a/pelican/contents.py b/pelican/contents.py index ed213c31..900049a2 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -216,6 +216,10 @@ class Content(object): else: logger.warning("Unable to find {fn}, skipping url" " replacement".format(fn=value)) + elif what == 'category': + origin = Category(value, self.settings).url + elif what == 'tag': + origin = Tag(value, self.settings).url return ''.join((m.group('markup'), m.group('quote'), origin, m.group('quote'))) diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index af97db3f..936903c1 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -180,6 +180,30 @@ class TestPage(unittest.TestCase): Page(**self.page_kwargs) self.assertTrue(content_object_init.has_receivers_for(Page)) + def test_get_content(self): + # Test that the content is updated with the relative links to + # filenames, tags and categories. + settings = get_settings() + args = self.page_kwargs.copy() + args['settings'] = settings + + # Tag + args['content'] = ('A simple test, with a ' + 'link') + page = Page(**args) + content = page.get_content('http://notmyidea.org') + self.assertEquals(content, ('A simple test, with a ' + 'link')) + + # Category + args['content'] = ('A simple test, with a ' + 'link') + page = Page(**args) + content = page.get_content('http://notmyidea.org') + self.assertEquals(content, + ('A simple test, with a ' + 'link')) + class TestArticle(TestPage): def test_template(self):