mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #2486 from bryanbrattlof/feature/1
Add relative_source_path attribute to content
This commit is contained in:
commit
e8c7756875
3 changed files with 68 additions and 31 deletions
|
|
@ -347,9 +347,9 @@ Article
|
||||||
|
|
||||||
The string representation of an Article is the `source_path` attribute.
|
The string representation of an Article is the `source_path` attribute.
|
||||||
|
|
||||||
=================== ===================================================
|
====================== ===================================================
|
||||||
Attribute Description
|
Attribute Description
|
||||||
=================== ===================================================
|
====================== ===================================================
|
||||||
author The :ref:`Author <object-author_cat_tag>` of
|
author The :ref:`Author <object-author_cat_tag>` of
|
||||||
this article.
|
this article.
|
||||||
authors A list of :ref:`Authors <object-author_cat_tag>`
|
authors A list of :ref:`Authors <object-author_cat_tag>`
|
||||||
|
|
@ -368,6 +368,7 @@ metadata Article header metadata `dict`.
|
||||||
save_as Location to save the article page.
|
save_as Location to save the article page.
|
||||||
slug Page slug.
|
slug Page slug.
|
||||||
source_path Full system path of the article source file.
|
source_path Full system path of the article source file.
|
||||||
|
relative_source_path Relative path from PATH_ to the article source file.
|
||||||
status The article status, can be any of 'published' or
|
status The article status, can be any of 'published' or
|
||||||
'draft'.
|
'draft'.
|
||||||
summary Rendered summary content.
|
summary Rendered summary content.
|
||||||
|
|
@ -378,7 +379,10 @@ title Title of the article.
|
||||||
translations List of translations
|
translations List of translations
|
||||||
:ref:`Article <object-article>` objects.
|
:ref:`Article <object-article>` objects.
|
||||||
url URL to the article page.
|
url URL to the article page.
|
||||||
=================== ===================================================
|
====================== ===================================================
|
||||||
|
|
||||||
|
.. _PATH: settings.html#PATH
|
||||||
|
|
||||||
|
|
||||||
.. _object-author_cat_tag:
|
.. _object-author_cat_tag:
|
||||||
|
|
||||||
|
|
@ -406,34 +410,38 @@ Page
|
||||||
|
|
||||||
The string representation of a Page is the `source_path` attribute.
|
The string representation of a Page is the `source_path` attribute.
|
||||||
|
|
||||||
=================== ===================================================
|
===================== ===================================================
|
||||||
Attribute Description
|
Attribute Description
|
||||||
=================== ===================================================
|
===================== ===================================================
|
||||||
author The :ref:`Author <object-author_cat_tag>` of
|
author The :ref:`Author <object-author_cat_tag>` of
|
||||||
this page.
|
this page.
|
||||||
content The rendered content of the page.
|
content The rendered content of the page.
|
||||||
date Datetime object representing the page date.
|
date Datetime object representing the page date.
|
||||||
date_format Either default date format or locale date format.
|
date_format Either default date format or locale date format.
|
||||||
default_template Default template name.
|
default_template Default template name.
|
||||||
in_default_lang Boolean representing if the article is written
|
in_default_lang Boolean representing if the article is written
|
||||||
in the default language.
|
in the default language.
|
||||||
lang Language of the article.
|
lang Language of the article.
|
||||||
locale_date Date formatted by the `date_format`.
|
locale_date Date formatted by the `date_format`.
|
||||||
metadata Page header metadata `dict`.
|
metadata Page header metadata `dict`.
|
||||||
save_as Location to save the page.
|
save_as Location to save the page.
|
||||||
slug Page slug.
|
slug Page slug.
|
||||||
source_path Full system path of the page source file.
|
source_path Full system path of the page source file.
|
||||||
status The page status, can be any of 'published', 'hidden' or
|
relative_source_path Relative path from PATH_ to the page source file.
|
||||||
'draft'.
|
status The page status, can be any of 'published', 'hidden' or
|
||||||
summary Rendered summary content.
|
'draft'.
|
||||||
tags List of :ref:`Tag <object-author_cat_tag>`
|
summary Rendered summary content.
|
||||||
objects.
|
tags List of :ref:`Tag <object-author_cat_tag>`
|
||||||
template Template name to use for rendering.
|
objects.
|
||||||
title Title of the page.
|
template Template name to use for rendering.
|
||||||
translations List of translations
|
title Title of the page.
|
||||||
:ref:`Article <object-article>` objects.
|
translations List of translations
|
||||||
url URL to the page.
|
:ref:`Article <object-article>` objects.
|
||||||
=================== ===================================================
|
url URL to the page.
|
||||||
|
===================== ===================================================
|
||||||
|
|
||||||
|
.. _PATH: settings.html#PATH
|
||||||
|
|
||||||
|
|
||||||
Feeds
|
Feeds
|
||||||
=====
|
=====
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ class Content(object):
|
||||||
regex_subs=settings.get('SLUG_REGEX_SUBSTITUTIONS', []))
|
regex_subs=settings.get('SLUG_REGEX_SUBSTITUTIONS', []))
|
||||||
|
|
||||||
self.source_path = source_path
|
self.source_path = source_path
|
||||||
|
self.relative_source_path = self.get_relative_source_path()
|
||||||
|
|
||||||
# manage the date format
|
# manage the date format
|
||||||
if not hasattr(self, 'date_format'):
|
if not hasattr(self, 'date_format'):
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,34 @@ class TestPage(LoggedTestCase):
|
||||||
page = Page(**self.page_kwargs)
|
page = Page(**self.page_kwargs)
|
||||||
self.assertEqual(page.save_as, "pages/foo-bar-fr.html")
|
self.assertEqual(page.save_as, "pages/foo-bar-fr.html")
|
||||||
|
|
||||||
|
def test_relative_source_path(self):
|
||||||
|
# 'relative_source_path' should be the relative path
|
||||||
|
# from 'PATH' to 'source_path'
|
||||||
|
page_kwargs = self._copy_page_kwargs()
|
||||||
|
|
||||||
|
# If 'source_path' is None, 'relative_source_path' should
|
||||||
|
# also return None
|
||||||
|
page_kwargs['source_path'] = None
|
||||||
|
page = Page(**page_kwargs)
|
||||||
|
self.assertIsNone(page.relative_source_path)
|
||||||
|
|
||||||
|
page_kwargs = self._copy_page_kwargs()
|
||||||
|
settings = get_settings()
|
||||||
|
full_path = page_kwargs['source_path']
|
||||||
|
|
||||||
|
settings['PATH'] = os.path.dirname(full_path)
|
||||||
|
page_kwargs['settings'] = settings
|
||||||
|
page = Page(**page_kwargs)
|
||||||
|
|
||||||
|
# if 'source_path' is set, 'relative_source_path' should
|
||||||
|
# return the relative path from 'PATH' to 'source_path'
|
||||||
|
self.assertEqual(
|
||||||
|
page.relative_source_path,
|
||||||
|
os.path.relpath(
|
||||||
|
full_path,
|
||||||
|
os.path.dirname(full_path)
|
||||||
|
))
|
||||||
|
|
||||||
def test_metadata_url_format(self):
|
def test_metadata_url_format(self):
|
||||||
# Arbitrary metadata should be passed through url_format()
|
# Arbitrary metadata should be passed through url_format()
|
||||||
page = Page(**self.page_kwargs)
|
page = Page(**self.page_kwargs)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue