mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
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:
parent
69c5fe3891
commit
8310ec98c4
4 changed files with 311 additions and 301 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
from pelican.generator import generate_output
|
from pelican.bloggenerator import generate_blog
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="""A tool to generate a
|
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):
|
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)
|
args.settings)
|
||||||
print 'Done !'
|
print 'Done !'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,18 @@ from operator import attrgetter
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from feedgenerator import Atom1Feed
|
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',
|
_TEMPLATES = ('index', 'tag', 'tags', 'article', 'category', 'categories',
|
||||||
'archives')
|
'archives')
|
||||||
|
|
||||||
_DIRECT_TEMPLATES = ('index', 'tags', '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,
|
_DEFAULT_CONFIG = {'PATH': None,
|
||||||
'THEME': _DEFAULT_THEME,
|
'THEME': _DEFAULT_THEME,
|
||||||
'OUTPUT_PATH': 'output/',
|
'OUTPUT_PATH': 'output/',
|
||||||
|
|
@ -29,10 +34,10 @@ _DEFAULT_CONFIG = {'PATH': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def generate_output(path=None, theme=None, output_path=None, markup=None,
|
def generate_blog(path=None, theme=None, output_path=None, markup=None,
|
||||||
settings=None):
|
settings=None):
|
||||||
"""Given a list of files, a template and a destination,
|
"""Search the given path for files, and generate a static blog in output,
|
||||||
output the static files.
|
using the given theme.
|
||||||
|
|
||||||
That's the main logic of pelican.
|
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
|
# copy static paths to output
|
||||||
for path in context['STATIC_PATHS']:
|
for path in context['STATIC_PATHS']:
|
||||||
try:
|
try:
|
||||||
shutil.copytree(os.path.join(theme, path),
|
real_output = os.path.join(output_path, path)
|
||||||
os.path.join(output_path, path))
|
theme_path = os.path.join(theme, path)
|
||||||
except OSError:
|
|
||||||
|
print "updating %s" % real_output
|
||||||
|
shutil.rmtree(real_output)
|
||||||
|
shutil.copytree(theme_path, real_output)
|
||||||
|
|
||||||
|
except OSError as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -174,7 +184,7 @@ def generate_file(path, name, template, context, **kwargs):
|
||||||
pass
|
pass
|
||||||
with open(filename, 'w', encoding='utf-8') as f:
|
with open(filename, 'w', encoding='utf-8') as f:
|
||||||
f.write(output)
|
f.write(output)
|
||||||
print filename
|
print 'writing %s' % filename
|
||||||
|
|
||||||
|
|
||||||
def get_templates(path=None):
|
def get_templates(path=None):
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
{% for article in articles %}
|
{% for article in articles %}
|
||||||
{% if loop.index == 1 %}
|
{% if loop.index == 1 %}
|
||||||
<aside id="featured" class="body"><article>
|
<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.summary }}
|
||||||
</article></aside><!-- /#featured -->
|
</article></aside><!-- /#featured -->
|
||||||
<section id="content" class="body">
|
<section id="content" class="body">
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><article class="hentry">
|
<li><article class="hentry">
|
||||||
<header>
|
<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>
|
</header>
|
||||||
|
|
||||||
<div class="entry-content">
|
<div class="entry-content">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue