mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Add the PATH_METADATA setting
Sometimes the base filename doesn't have everything you need. Remember that os.sep is platform dependent, so using it in a regular expression for this setting may not be portable (boo MS Windows!).
This commit is contained in:
parent
c46ca5d5d1
commit
bfa8851af0
3 changed files with 10 additions and 2 deletions
|
|
@ -59,6 +59,8 @@ Setting name (default value) What doe
|
|||
For example, if you would like to extract both the
|
||||
date and the slug, you could set something like:
|
||||
``'(?P<date>\d{4}-\d{2}-\d{2})_(?P<slug>.*)'``.
|
||||
`PATH_METADATA` (``''``) Like ``FILENAME_METADATA``, but parsed from a page's
|
||||
full path relative to the content source directory.
|
||||
`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
|
||||
|
|
|
|||
|
|
@ -353,19 +353,24 @@ def parse_path_metadata(path, settings=None, process=None):
|
|||
>>> import pprint
|
||||
>>> settings = {
|
||||
... 'FILENAME_METADATA': '(?P<slug>[^.]*).*',
|
||||
... 'PATH_METADATA':
|
||||
... '(?P<category>[^/]*)/(?P<date>\d{4}-\d{2}-\d{2})/.*',
|
||||
... }
|
||||
>>> reader = Reader(settings=settings)
|
||||
>>> metadata = parse_path_metadata(
|
||||
... path='my-cat/2013-01-01/my-slug.html',
|
||||
... settings=settings,
|
||||
... process=reader.process_metadata)
|
||||
>>> pprint.pprint(metadata)
|
||||
{'slug': 'my-slug'}
|
||||
>>> pprint.pprint(metadata) # doctest: +ELLIPSIS
|
||||
{'category': <pelican.urlwrappers.Category object at ...>,
|
||||
'date': datetime.datetime(2013, 1, 1, 0, 0),
|
||||
'slug': 'my-slug'}
|
||||
"""
|
||||
metadata = {}
|
||||
base, ext = os.path.splitext(os.path.basename(path))
|
||||
if settings:
|
||||
for key,data in [('FILENAME_METADATA', base),
|
||||
('PATH_METADATA', path),
|
||||
]:
|
||||
regexp = settings.get(key)
|
||||
if regexp:
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
|||
'DEFAULT_ORPHANS': 0,
|
||||
'DEFAULT_METADATA': (),
|
||||
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2}).*',
|
||||
'PATH_METADATA': '',
|
||||
'FILES_TO_COPY': (),
|
||||
'DEFAULT_STATUS': 'published',
|
||||
'ARTICLE_PERMALINK_STRUCTURE': '',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue