Add some files to the output, rename generator.py to bloggenerator.py

--HG--
rename : pelican/generator.py => pelican/bloggenerator.py
This commit is contained in:
Alexis Metaireau 2010-09-27 15:45:02 +01:00
commit 8310ec98c4
4 changed files with 311 additions and 301 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/python
from pelican.generator import generate_output
from pelican.bloggenerator import generate_blog
import argparse
parser = argparse.ArgumentParser(description="""A tool to generate a
@ -22,7 +22,7 @@ parser.add_argument('-b', '--debug', dest='debug', action='store_true')
def run(args):
generate_output(args.path, args.templates, args.output, args.markup,
generate_blog(args.path, args.templates, args.output, args.markup,
args.settings)
print 'Done !'

View file

@ -11,13 +11,18 @@ from operator import attrgetter
from jinja2 import Environment, FileSystemLoader
from feedgenerator import Atom1Feed
import rstdirectives # import the directives to have pygments support
# import the directives to have pygments support
import rstdirectives
## Constants ##########################################################
_TEMPLATES = ('index', 'tag', 'tags', 'article', 'category', 'categories',
'archives')
_DIRECT_TEMPLATES = ('index', 'tags', 'categories', 'archives')
_DEFAULT_THEME =\
os.sep.join([os.path.dirname(os.path.abspath(__file__)), "themes"])
_DEFAULT_THEME = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
"themes"])
_DEFAULT_CONFIG = {'PATH': None,
'THEME': _DEFAULT_THEME,
'OUTPUT_PATH': 'output/',
@ -29,10 +34,10 @@ _DEFAULT_CONFIG = {'PATH': None,
}
def generate_output(path=None, theme=None, output_path=None, markup=None,
settings=None):
"""Given a list of files, a template and a destination,
output the static files.
def generate_blog(path=None, theme=None, output_path=None, markup=None,
settings=None):
"""Search the given path for files, and generate a static blog in output,
using the given theme.
That's the main logic of pelican.
@ -114,9 +119,14 @@ def generate_output(path=None, theme=None, output_path=None, markup=None,
# copy static paths to output
for path in context['STATIC_PATHS']:
try:
shutil.copytree(os.path.join(theme, path),
os.path.join(output_path, path))
except OSError:
real_output = os.path.join(output_path, path)
theme_path = os.path.join(theme, path)
print "updating %s" % real_output
shutil.rmtree(real_output)
shutil.copytree(theme_path, real_output)
except OSError as e:
pass
@ -174,7 +184,7 @@ def generate_file(path, name, template, context, **kwargs):
pass
with open(filename, 'w', encoding='utf-8') as f:
f.write(output)
print filename
print 'writing %s' % filename
def get_templates(path=None):

View file

@ -4,7 +4,7 @@
{% for article in articles %}
{% if loop.index == 1 %}
<aside id="featured" class="body"><article>
<hgroup> <h2>Last article</h2> <h3><a href="{{ article.url }}">{{ article.title }}</a></h3> </hgroup>
<hgroup> <h2>Last article</h2> <h3><a href="{{ BLOGURL }}/{{ article.url }}">{{ article.title }}</a></h3> </hgroup>
{{ article.summary }}
</article></aside><!-- /#featured -->
<section id="content" class="body">
@ -12,7 +12,7 @@
{% else %}
<li><article class="hentry">
<header>
<h2 class="entry-title"><a href="{{ article.url }}" rel="bookmark" title="Permalink to {{ article.title}}">{{ article.title }}</a></h2>
<h2 class="entry-title"><a href="{{ BLOGURL }}/{{ article.url }}" rel="bookmark" title="Permalink to {{ article.title}}">{{ article.title }}</a></h2>
</header>
<div class="entry-content">