From 090a02a9e35b0a49117779611ecdb4483b2764bf Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Sun, 21 Nov 2010 01:49:37 +0000 Subject: [PATCH] Change the output directory structure and a bit the templates structure as well. --HG-- rename : pelican/themes/martyalchin/css/style.css => pelican/themes/martyalchin/static/css/style.css rename : pelican/themes/notmyidea/css/main.css => pelican/themes/notmyidea/static/css/main.css rename : pelican/themes/notmyidea/css/pygment.css => pelican/themes/notmyidea/static/css/pygment.css rename : pelican/themes/notmyidea/css/reset.css => pelican/themes/notmyidea/static/css/reset.css rename : pelican/themes/notmyidea/css/wide.css => pelican/themes/notmyidea/static/css/wide.css rename : pelican/themes/notmyidea/images/icons/delicious.png => pelican/themes/notmyidea/static/images/icons/delicious.png rename : pelican/themes/notmyidea/images/icons/lastfm.png => pelican/themes/notmyidea/static/images/icons/lastfm.png rename : pelican/themes/notmyidea/images/icons/linkedin.png => pelican/themes/notmyidea/static/images/icons/linkedin.png rename : pelican/themes/notmyidea/images/icons/rss.png => pelican/themes/notmyidea/static/images/icons/rss.png rename : pelican/themes/notmyidea/images/icons/twitter.png => pelican/themes/notmyidea/static/images/icons/twitter.png --- TODO | 2 -- pelican/generators.py | 16 ++++----- pelican/processors.py | 31 +++++++++++------- pelican/settings.py | 3 +- .../martyalchin/{ => static}/css/style.css | 0 .../themes/martyalchin/templates/base.html | 2 +- .../notmyidea/{ => static}/css/main.css | 0 .../notmyidea/{ => static}/css/pygment.css | 0 .../notmyidea/{ => static}/css/reset.css | 0 .../notmyidea/{ => static}/css/wide.css | 0 .../{ => static}/images/icons/delicious.png | Bin .../{ => static}/images/icons/lastfm.png | Bin .../{ => static}/images/icons/linkedin.png | Bin .../{ => static}/images/icons/rss.png | Bin .../{ => static}/images/icons/twitter.png | Bin pelican/themes/notmyidea/templates/base.html | 2 +- pelican/utils.py | 10 +++--- 17 files changed, 37 insertions(+), 29 deletions(-) rename pelican/themes/martyalchin/{ => static}/css/style.css (100%) rename pelican/themes/notmyidea/{ => static}/css/main.css (100%) rename pelican/themes/notmyidea/{ => static}/css/pygment.css (100%) rename pelican/themes/notmyidea/{ => static}/css/reset.css (100%) rename pelican/themes/notmyidea/{ => static}/css/wide.css (100%) rename pelican/themes/notmyidea/{ => static}/images/icons/delicious.png (100%) rename pelican/themes/notmyidea/{ => static}/images/icons/lastfm.png (100%) rename pelican/themes/notmyidea/{ => static}/images/icons/linkedin.png (100%) rename pelican/themes/notmyidea/{ => static}/images/icons/rss.png (100%) rename pelican/themes/notmyidea/{ => static}/images/icons/twitter.png (100%) diff --git a/TODO b/TODO index 858b441cd..9928ced2d 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,6 @@ * Add a way to support pictures (see how sphinx makes that) * Find a way to extend the existing templates instead of rewriting all from scratch. -* find a better way to specify the templates. an idea is simply to install the templates in a default path, and to add a way to specify them by default under a "_themes" dir. * Make the program support UTF8-encoded files as input (and later: any encoding?) -* Change the directory structure ? * Add status support (draft, published, hidden) * Add a serve + automatic generation behaviour. * Recompile only the changed files, not all. diff --git a/pelican/generators.py b/pelican/generators.py index fb6e48cec..f53747224 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -16,10 +16,10 @@ class Generator(object): """Handle all generation process: files writes, feed creation, and this kind of basic stuff""" - - def __init__(self, settings=None, path=None, theme=None, output_path=None, + + def __init__(self, settings=None, path=None, theme=None, output_path=None, markup=None): - """Read the settings, and performs some checks on the environement + """Read the settings, and performs some checks on the environment before doing anything else. """ if settings is None: @@ -64,7 +64,7 @@ def run(self, processors): for p in processors: p.process(context, self) - def generate_feed(self, elements, context, filename=None, + def generate_feed(self, elements, context, filename=None, relative_urls=True): """Generate a feed with the list of articles provided @@ -72,7 +72,7 @@ def generate_feed(self, elements, context, filename=None, the feed object. :param articles: the articles to put on the feed. - :param context: the context to get the feed metadatas. + :param context: the context to get the feed metadata. :param output_path: where to output the file. :param filename: the filename to output. :param relative_urls: use relative urls or absolutes ones @@ -104,11 +104,11 @@ def generate_feed(self, elements, context, filename=None, fp = open(complete_path, 'w') feed.write(fp, 'utf-8') print u' [ok] writing %s' % complete_path - + fp.close() return feed - def generate_file(self, name, template, context, relative_urls=True, + def generate_file(self, name, template, context, relative_urls=True, **kwargs): """Write the file with the given informations @@ -166,7 +166,7 @@ def get_files(self, path, exclude=[], extensions=None): files.extend([os.sep.join((root, f)) for f in temp_files if True in [f.endswith(ext) for ext in extensions]]) return files - + def _get_relative_siteurl(self, filename): """Return the siteurl relative to the given filename""" return '../' * filename.count('/') + '.' diff --git a/pelican/processors.py b/pelican/processors.py index e4248645b..e9720c55f 100644 --- a/pelican/processors.py +++ b/pelican/processors.py @@ -11,7 +11,7 @@ class Processor(object): def _update_context(self, context, items): - """Update the context with the given items from the currrent + """Update the context with the given items from the currrent processor. """ for item in items: @@ -24,20 +24,20 @@ def _update_context(self, context, items): class ArticlesProcessor(Processor): def __init__(self, settings=None): - self.articles = [] + self.articles = [] self.dates = {} self.years = {} self.tags = {} - self.categories = {} - + self.categories = {} + def generate_feeds(self, context, generator): - """Generate the feeds from the current context, and output files.""" + """Generate the feeds from the current context, and output files.""" generator.generate_feed(self.articles, context, context['FEED']) for cat, arts in self.categories.items(): arts.sort(key=attrgetter('date'), reverse=True) - generator.generate_feed(arts, context, + generator.generate_feed(arts, context, context['CATEGORY_FEED'] % cat) def generate_pages(self, context, generator): @@ -92,7 +92,7 @@ def preprocess(self, context, generator): # sort the articles by date self.articles.sort(key=attrgetter('date'), reverse=True) # and generate the output :) - self._update_context(context, ('articles', 'dates', 'years', + self._update_context(context, ('articles', 'dates', 'years', 'tags', 'categories')) def process(self, context, generator): @@ -116,11 +116,11 @@ def preprocess(self, context, generator): self.pages.append(page) context['PAGES'] = self.pages - + def process(self, context, generator): templates = generator.get_templates() for page in self.pages: - generator.generate_file('pages/%s' % page.url, + generator.generate_file('pages/%s' % page.url, templates['page'], context, page=page) self._update_context(context, ('pages',)) @@ -128,10 +128,17 @@ def process(self, context, generator): class StaticProcessor(Processor): """copy static paths to output""" + def _copy_paths(self, paths, source, destination, output_path, + final_path=None): + for path in paths: + copytree(path, source, os.path.join(output_path, destination), + final_path) + def process(self, context, generator): - for path in generator.settings['STATIC_PATHS']: - copytree(path, generator.theme, generator.output_path) - copytree('pics', generator.path, generator.output_path) + self._copy_paths(generator.settings['STATIC_PATHS'], generator.path, + 'static', generator.output_path) + self._copy_paths(generator.settings['THEME_PATHS'], generator.theme, + 'theme', generator.output_path, '.') class PdfProcessor(Processor): diff --git a/pelican/settings.py b/pelican/settings.py index dfd5c48d1..79de75cdc 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -6,7 +6,8 @@ 'THEME': _DEFAULT_THEME, 'OUTPUT_PATH': 'output/', 'MARKUP': ('rst', 'md'), - 'STATIC_PATHS': ['css', 'images'], + 'STATIC_PATHS': ['images',], + 'THEME_PATHS': ['static',], 'FEED': 'feeds/all.atom.xml', 'CATEGORY_FEED': 'feeds/%s.atom.xml', 'SITENAME': 'A Pelican Blog', diff --git a/pelican/themes/martyalchin/css/style.css b/pelican/themes/martyalchin/static/css/style.css similarity index 100% rename from pelican/themes/martyalchin/css/style.css rename to pelican/themes/martyalchin/static/css/style.css diff --git a/pelican/themes/martyalchin/templates/base.html b/pelican/themes/martyalchin/templates/base.html index 0e7ac866c..eea18f9b6 100644 --- a/pelican/themes/martyalchin/templates/base.html +++ b/pelican/themes/martyalchin/templates/base.html @@ -3,7 +3,7 @@ {% block title %}{{ SITENAME }}{%endblock%} - + diff --git a/pelican/themes/notmyidea/css/main.css b/pelican/themes/notmyidea/static/css/main.css similarity index 100% rename from pelican/themes/notmyidea/css/main.css rename to pelican/themes/notmyidea/static/css/main.css diff --git a/pelican/themes/notmyidea/css/pygment.css b/pelican/themes/notmyidea/static/css/pygment.css similarity index 100% rename from pelican/themes/notmyidea/css/pygment.css rename to pelican/themes/notmyidea/static/css/pygment.css diff --git a/pelican/themes/notmyidea/css/reset.css b/pelican/themes/notmyidea/static/css/reset.css similarity index 100% rename from pelican/themes/notmyidea/css/reset.css rename to pelican/themes/notmyidea/static/css/reset.css diff --git a/pelican/themes/notmyidea/css/wide.css b/pelican/themes/notmyidea/static/css/wide.css similarity index 100% rename from pelican/themes/notmyidea/css/wide.css rename to pelican/themes/notmyidea/static/css/wide.css diff --git a/pelican/themes/notmyidea/images/icons/delicious.png b/pelican/themes/notmyidea/static/images/icons/delicious.png similarity index 100% rename from pelican/themes/notmyidea/images/icons/delicious.png rename to pelican/themes/notmyidea/static/images/icons/delicious.png diff --git a/pelican/themes/notmyidea/images/icons/lastfm.png b/pelican/themes/notmyidea/static/images/icons/lastfm.png similarity index 100% rename from pelican/themes/notmyidea/images/icons/lastfm.png rename to pelican/themes/notmyidea/static/images/icons/lastfm.png diff --git a/pelican/themes/notmyidea/images/icons/linkedin.png b/pelican/themes/notmyidea/static/images/icons/linkedin.png similarity index 100% rename from pelican/themes/notmyidea/images/icons/linkedin.png rename to pelican/themes/notmyidea/static/images/icons/linkedin.png diff --git a/pelican/themes/notmyidea/images/icons/rss.png b/pelican/themes/notmyidea/static/images/icons/rss.png similarity index 100% rename from pelican/themes/notmyidea/images/icons/rss.png rename to pelican/themes/notmyidea/static/images/icons/rss.png diff --git a/pelican/themes/notmyidea/images/icons/twitter.png b/pelican/themes/notmyidea/static/images/icons/twitter.png similarity index 100% rename from pelican/themes/notmyidea/images/icons/twitter.png rename to pelican/themes/notmyidea/static/images/icons/twitter.png diff --git a/pelican/themes/notmyidea/templates/base.html b/pelican/themes/notmyidea/templates/base.html index bdeb7b9f3..99d6d3806 100644 --- a/pelican/themes/notmyidea/templates/base.html +++ b/pelican/themes/notmyidea/templates/base.html @@ -3,7 +3,7 @@ {% block title %}{{ SITENAME }}{%endblock%} - + diff --git a/pelican/utils.py b/pelican/utils.py index 1bcc86041..79bd4e38d 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -50,14 +50,16 @@ def slugify(value): value = unicode(re.sub('[^\w\s-]', '', value).strip().lower()) return re.sub('[-\s]+', '-', value) -def copytree(path, origin, destination): +def copytree(path, origin, destination, topath=None): """Copy path from origin to destination, silent any errors""" - + + if not topath: + topath = path try: fromp = os.path.expanduser(os.path.join(origin, path)) - to = os.path.expanduser(os.path.join(destination, path)) + to = os.path.expanduser(os.path.join(destination, topath)) shutil.copytree(fromp, to) - print u' [ok] copying %s' % fromp + print u' [ok] copying %s to %s' % (fromp, to) except OSError: pass