mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Added a new setting OUTPUT_SOURCES_EXTENSION
Using this configurable setting users can control what extension will be appended to filenames by the SourcesGenerator. The default is to use the ``.text`` extension.
This commit is contained in:
parent
0a1a868b37
commit
a7dd21ffaf
3 changed files with 20 additions and 1 deletions
|
|
@ -72,6 +72,9 @@ Setting name (default value) What doe
|
||||||
`OUTPUT_SOURCES` (``False``) Set to True if you want to copy the articles and pages in their
|
`OUTPUT_SOURCES` (``False``) Set to True if you want to copy the articles and pages in their
|
||||||
original format (e.g. Markdown or ReStructeredText) to the
|
original format (e.g. Markdown or ReStructeredText) to the
|
||||||
specified OUTPUT_PATH.
|
specified OUTPUT_PATH.
|
||||||
|
`OUTPUT_SOURCES_EXTENSION` (``.text``) Controls the extension that will be used by the SourcesGenerator.
|
||||||
|
Defaults to .text. If the first character is not a `.` the
|
||||||
|
dot character will be prepended to the extension.
|
||||||
`RELATIVE_URLS` (``True``) Defines whether Pelican should use document-relative URLs or
|
`RELATIVE_URLS` (``True``) Defines whether Pelican should use document-relative URLs or
|
||||||
not. If set to ``False``, Pelican will use the SITEURL
|
not. If set to ``False``, Pelican will use the SITEURL
|
||||||
setting to construct absolute URLs.
|
setting to construct absolute URLs.
|
||||||
|
|
|
||||||
|
|
@ -492,9 +492,12 @@ class PdfGenerator(Generator):
|
||||||
self._create_pdf(page, pdf_path)
|
self._create_pdf(page, pdf_path)
|
||||||
|
|
||||||
class SourceFileGenerator(Generator):
|
class SourceFileGenerator(Generator):
|
||||||
|
def generate_context(self):
|
||||||
|
self.output_extension = self.settings['OUTPUT_SOURCES_EXTENSION']
|
||||||
|
|
||||||
def _create_source(self, obj, output_path):
|
def _create_source(self, obj, output_path):
|
||||||
filename = os.path.splitext(obj.save_as)[0]
|
filename = os.path.splitext(obj.save_as)[0]
|
||||||
dest = os.path.join(output_path, filename + '.text')
|
dest = os.path.join(output_path, filename + self.output_extension)
|
||||||
copy('', obj.filename, dest)
|
copy('', obj.filename, dest)
|
||||||
|
|
||||||
def generate_output(self, writer=None):
|
def generate_output(self, writer=None):
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
||||||
'DISPLAY_PAGES_ON_MENU': True,
|
'DISPLAY_PAGES_ON_MENU': True,
|
||||||
'PDF_GENERATOR': False,
|
'PDF_GENERATOR': False,
|
||||||
'OUTPUT_SOURCES': False,
|
'OUTPUT_SOURCES': False,
|
||||||
|
'OUTPUT_SOURCES_EXTENSION': '.text',
|
||||||
'DEFAULT_CATEGORY': 'misc',
|
'DEFAULT_CATEGORY': 'misc',
|
||||||
'DEFAULT_DATE': 'fs',
|
'DEFAULT_DATE': 'fs',
|
||||||
'WITH_FUTURE_DATES': True,
|
'WITH_FUTURE_DATES': True,
|
||||||
|
|
@ -175,4 +176,16 @@ def configure_settings(settings, default_settings=None, filename=None):
|
||||||
logger.warn("You must install the webassets module to use WEBASSETS.")
|
logger.warn("You must install the webassets module to use WEBASSETS.")
|
||||||
settings['WEBASSETS'] = False
|
settings['WEBASSETS'] = False
|
||||||
|
|
||||||
|
if 'OUTPUT_SOURCES_EXTENSION' in settings:
|
||||||
|
try:
|
||||||
|
if not isinstance(settings['OUTPUT_SOURCES_EXTENSION'], str):
|
||||||
|
raise ValueError
|
||||||
|
elif '.' is not settings['OUTPUT_SOURCES_EXTENSION'][0]:
|
||||||
|
settings['OUTPUT_SOURCES_EXTENSION'] = '.' + settings['OUTPUT_SOURCES_EXTENSION']
|
||||||
|
except(ValueError, IndexError):
|
||||||
|
logger.warn("Detected misconfiguration with OUTPUT_SOURCES_EXTENSION."
|
||||||
|
" falling back to the default extension " +
|
||||||
|
_DEFAULT_CONFIG['OUTPUT_SOURCES_EXTENSION'])
|
||||||
|
settings['OUTPUT_SOURCES_EXTENSION'] = _DEFAULT_CONFIG['OUTPUT_SOURCES_EXTENSION']
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue