Add support of multiple static paths and feed generation.

This commit is contained in:
Alexis Metaireau 2010-08-19 02:43:53 +02:00
commit 75821fb644
9 changed files with 33 additions and 76 deletions

1
TODO
View file

@ -1,2 +1 @@
* Add RSS generation
* package it ! * package it !

View file

@ -9,6 +9,7 @@ from functools import partial
from operator import attrgetter from operator import attrgetter
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
from feedgenerator import Atom1Feed
import rstdirectives # import the directives to have pygments support import rstdirectives # import the directives to have pygments support
@ -20,7 +21,9 @@ _DEFAULT_THEME =\
_DEFAULT_CONFIG = {'PATH': None, _DEFAULT_CONFIG = {'PATH': None,
'THEME': _DEFAULT_THEME, 'THEME': _DEFAULT_THEME,
'OUTPUT_PATH': 'output/', 'OUTPUT_PATH': 'output/',
'MARKUP': 'rst'} 'MARKUP': 'rst',
'STATIC_PATHS': ['css', 'images'],
'FEED_FILENAME': 'atom.xml'}
def generate_output(path=None, theme=None, output_path=None, markup=None, def generate_output(path=None, theme=None, output_path=None, markup=None,
settings=None): settings=None):
@ -84,12 +87,31 @@ def generate_output(path=None, theme=None, output_path=None, markup=None,
generate('%s' % article.url, generate('%s' % article.url,
templates['article'], context, article=article) templates['article'], context, article=article)
# copy css path to output/css # generate atom feed
try: feed = Atom1Feed(
shutil.copytree(os.path.join(theme, 'css'), title=context['BLOGNAME'],
os.path.join(output_path, 'css')) link=context['BLOGURL'],
except OSError: feed_url='%s/%s' % (context['BLOGURL'], context['FEED_FILENAME']),
pass description=context['BLOGSUBTITLE'])
for article in articles:
feed.add_item(
title=article.title,
link='%s/%s' % (context['BLOGURL'], article.url),
description=article.content,
author_name=article.author,
pubdate=article.date)
fp = open(os.path.join(output_path, context['FEED_FILENAME']), 'w')
feed.write(fp, 'utf-8')
fp.close()
# 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:
pass
def generate_file(path, name, template, context, **kwargs): def generate_file(path, name, template, context, **kwargs):

View file

@ -1,66 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{{ BLOGNAME }}{%endblock%}</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/main.css" type="text/css" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="css/ie.css"/>
<script src="js/IE8.js" type="text/javascript"></script><![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="css/ie6.css"/><![endif]-->
</head>
<body id="index" class="home">
<header id="banner" class="body">
<h1><a href="#">{{ BLOGNAME }} <strong>{{ BLOGSUBTITLE }}</strong></a></h1>
<nav><ul>
<li class="active"><a href="{{ BLOGURL }}">blog</a></li>
{% for title, link in MENUITEMS %}
<li><a href="{{ link }}">{{ title }}</a></li>
{% endfor %}
</ul></nav>
</header><!-- /#banner -->
{% block content %}
{% endblock %}
<section id="extras" class="body">
{% if BLOGROLL %}
<div class="blogroll">
<h2>blogroll</h2>
<ul>
{% for name, link in BLOGROLL %}
<li><a href="{{ link }}">{{ name }}</a></li>
{% endfor %}
</ul>
</div><!-- /.blogroll -->
{% endif %}
{% if SOCIAL %}
<div class="social">
<h2>social</h2>
<ul>
<li><a href="{{ FEEDURL }}" rel="alternate">rss</a></li>
{% for name, link in SOCIAL %}
<li><a href="{{ link }}">{{ name }}</a></li>
{% endfor %}
</ul>
</div><!-- /.social -->
{% endif %}
</section><!-- /#extras -->
<footer id="contentinfo" class="body">
<address id="about" class="vcard body">
Proudly powered by <a href="#">pelican</a>, which takes great advantages of <a href="http://python.org">python</a>.
</address><!-- /#about -->
<p>The theme is by<a href="http://smashingmagazine.com">Smashing Magazine</a>, thanks!</p>
</footer><!-- /#contentinfo -->
</body>
</html>

View file

@ -281,7 +281,7 @@ img.left, figure.left {float: right; margin: 0 0 2em 2em;}
.social a[href*='digg.com'] {background-image: url('../images/icons/digg.png');} .social a[href*='digg.com'] {background-image: url('../images/icons/digg.png');}
.social a[href*='facebook.com'] {background-image: url('../images/icons/facebook.png');} .social a[href*='facebook.com'] {background-image: url('../images/icons/facebook.png');}
.social a[href*='last.fm'], .social a[href*='lastfm.'] {background-image: url('../images/icons/lastfm.png');} .social a[href*='last.fm'], .social a[href*='lastfm.'] {background-image: url('../images/icons/lastfm.png');}
.social a[href*='/feed/'] {background-image: url('../images/icons/rss.png');} .social a[href*='atom.xml'] {background-image: url('../images/icons/rss.png');}
.social a[href*='twitter.com'] {background-image: url('../images/icons/twitter.png');} .social a[href*='twitter.com'] {background-image: url('../images/icons/twitter.png');}
/* /*

Binary file not shown.

After

Width:  |  Height:  |  Size: 963 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 980 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 835 B

View file

@ -4,6 +4,8 @@
<title>{% block title %}{{ BLOGNAME }}{%endblock%}</title> <title>{% block title %}{{ BLOGNAME }}{%endblock%}</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="stylesheet" href="css/main.css" type="text/css" /> <link rel="stylesheet" href="css/main.css" type="text/css" />
<link href="atom.xml" type="application/atom+xml" rel="alternate" title="{{ BLOGNAME }} ATOM Feed" />
<!--[if IE]> <!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
@ -45,7 +47,7 @@
<div class="social"> <div class="social">
<h2>social</h2> <h2>social</h2>
<ul> <ul>
<li><a href="{{ FEEDURL }}" rel="alternate">rss</a></li> <li><a href="atom.xml" rel="alternate">atom feed</a></li>
{% for name, link in SOCIAL %} {% for name, link in SOCIAL %}
<li><a href="{{ link }}">{{ name }}</a></li> <li><a href="{{ link }}">{{ name }}</a></li>
{% endfor %} {% endfor %}