mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #510 from nrocco/sourcegen
New source file .text generator
This commit is contained in:
commit
48625964f1
6 changed files with 34 additions and 11 deletions
|
|
@ -53,14 +53,10 @@ List of signals
|
||||||
|
|
||||||
Here is the list of currently implemented signals:
|
Here is the list of currently implemented signals:
|
||||||
|
|
||||||
========================= ============================ ===========================================================================
|
========================= ============================ =========================================
|
||||||
Signal Arguments Description
|
Signal Arguments Description
|
||||||
========================= ============================ ===========================================================================
|
========================= ============================ =========================================
|
||||||
initialized pelican object
|
initialized pelican object
|
||||||
finalized pelican object invoked after all the generators are executed and just before pelican exits
|
|
||||||
usefull for custom post processing actions, such as:
|
|
||||||
- minifying js/css assets.
|
|
||||||
- notify/ping search engines with an updated sitemap.
|
|
||||||
article_generate_context article_generator, metadata
|
article_generate_context article_generator, metadata
|
||||||
article_generator_init article_generator invoked in the ArticlesGenerator.__init__
|
article_generator_init article_generator invoked in the ArticlesGenerator.__init__
|
||||||
get_generators generators invoked in Pelican.get_generator_classes,
|
get_generators generators invoked in Pelican.get_generator_classes,
|
||||||
|
|
@ -68,7 +64,7 @@ get_generators generators invoked in Pelican.ge
|
||||||
generator in a tuple or in a list.
|
generator in a tuple or in a list.
|
||||||
pages_generate_context pages_generator, metadata
|
pages_generate_context pages_generator, metadata
|
||||||
pages_generator_init pages_generator invoked in the PagesGenerator.__init__
|
pages_generator_init pages_generator invoked in the PagesGenerator.__init__
|
||||||
========================= ============================ ===========================================================================
|
========================= ============================ =========================================
|
||||||
|
|
||||||
The list is currently small, don't hesitate to add signals and make a pull
|
The list is currently small, don't hesitate to add signals and make a pull
|
||||||
request if you need them!
|
request if you need them!
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,12 @@ Setting name (default value) What doe
|
||||||
`PDF_GENERATOR` (``False``) Set to True if you want to have PDF versions
|
`PDF_GENERATOR` (``False``) Set to True if you want to have PDF versions
|
||||||
of your documents. You will need to install
|
of your documents. You will need to install
|
||||||
`rst2pdf`.
|
`rst2pdf`.
|
||||||
|
`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
|
||||||
|
specified OUTPUT_PATH.
|
||||||
|
`OUTPUT_SOURCES_EXTENSION` (``.text``) Controls the extension that will be used by the SourcesGenerator.
|
||||||
|
Defaults to ``.text``. If not a valid string the default value
|
||||||
|
will be used.
|
||||||
`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.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import argparse
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
|
|
||||||
from pelican.generators import (Generator, ArticlesGenerator, PagesGenerator,
|
from pelican.generators import (Generator, ArticlesGenerator, PagesGenerator,
|
||||||
StaticGenerator, PdfGenerator, LessCSSGenerator)
|
StaticGenerator, PdfGenerator, LessCSSGenerator, SourceFileGenerator)
|
||||||
from pelican.log import init
|
from pelican.log import init
|
||||||
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
||||||
from pelican.utils import clean_output_dir, files_changed, file_changed, NoFilesError
|
from pelican.utils import clean_output_dir, files_changed, file_changed, NoFilesError
|
||||||
|
|
@ -179,14 +179,14 @@ class Pelican(object):
|
||||||
if hasattr(p, 'generate_output'):
|
if hasattr(p, 'generate_output'):
|
||||||
p.generate_output(writer)
|
p.generate_output(writer)
|
||||||
|
|
||||||
signals.finalized.send(self)
|
|
||||||
|
|
||||||
def get_generator_classes(self):
|
def get_generator_classes(self):
|
||||||
generators = [StaticGenerator, ArticlesGenerator, PagesGenerator]
|
generators = [StaticGenerator, ArticlesGenerator, PagesGenerator]
|
||||||
if self.settings['PDF_GENERATOR']:
|
if self.settings['PDF_GENERATOR']:
|
||||||
generators.append(PdfGenerator)
|
generators.append(PdfGenerator)
|
||||||
if self.settings['LESS_GENERATOR']: # can be True or PATH to lessc
|
if self.settings['LESS_GENERATOR']: # can be True or PATH to lessc
|
||||||
generators.append(LessCSSGenerator)
|
generators.append(LessCSSGenerator)
|
||||||
|
if self.settings['OUTPUT_SOURCES']:
|
||||||
|
generators.append(SourceFileGenerator)
|
||||||
|
|
||||||
for pair in signals.get_generators.send(self):
|
for pair in signals.get_generators.send(self):
|
||||||
(funct, value) = pair
|
(funct, value) = pair
|
||||||
|
|
|
||||||
|
|
@ -515,6 +515,19 @@ class PdfGenerator(Generator):
|
||||||
for page in self.context['pages']:
|
for page in self.context['pages']:
|
||||||
self._create_pdf(page, pdf_path)
|
self._create_pdf(page, pdf_path)
|
||||||
|
|
||||||
|
class SourceFileGenerator(Generator):
|
||||||
|
def generate_context(self):
|
||||||
|
self.output_extension = self.settings['OUTPUT_SOURCES_EXTENSION']
|
||||||
|
|
||||||
|
def _create_source(self, obj, output_path):
|
||||||
|
filename = os.path.splitext(obj.save_as)[0]
|
||||||
|
dest = os.path.join(output_path, filename + self.output_extension)
|
||||||
|
copy('', obj.filename, dest)
|
||||||
|
|
||||||
|
def generate_output(self, writer=None):
|
||||||
|
logger.info(u' Generating source files...')
|
||||||
|
for object in chain(self.context['articles'], self.context['pages']):
|
||||||
|
self._create_source(object, self.output_path)
|
||||||
|
|
||||||
class LessCSSGenerator(Generator):
|
class LessCSSGenerator(Generator):
|
||||||
"""Compile less css files."""
|
"""Compile less css files."""
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
||||||
'SITENAME': 'A Pelican Blog',
|
'SITENAME': 'A Pelican Blog',
|
||||||
'DISPLAY_PAGES_ON_MENU': True,
|
'DISPLAY_PAGES_ON_MENU': True,
|
||||||
'PDF_GENERATOR': False,
|
'PDF_GENERATOR': 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 +177,11 @@ 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:
|
||||||
|
if not isinstance(settings['OUTPUT_SOURCES_EXTENSION'], str):
|
||||||
|
settings['OUTPUT_SOURCES_EXTENSION'] = _DEFAULT_CONFIG['OUTPUT_SOURCES_EXTENSION']
|
||||||
|
logger.warn("Detected misconfiguration with OUTPUT_SOURCES_EXTENSION."
|
||||||
|
" falling back to the default extension " +
|
||||||
|
_DEFAULT_CONFIG['OUTPUT_SOURCES_EXTENSION'])
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
from blinker import signal
|
from blinker import signal
|
||||||
|
|
||||||
initialized = signal('pelican_initialized')
|
initialized = signal('pelican_initialized')
|
||||||
finalized = signal('pelican_finalized')
|
|
||||||
article_generate_context = signal('article_generate_context')
|
article_generate_context = signal('article_generate_context')
|
||||||
article_generator_init = signal('article_generator_init')
|
article_generator_init = signal('article_generator_init')
|
||||||
get_generators = signal('get_generators')
|
get_generators = signal('get_generators')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue