Skip to content
Snippets Groups Projects
Commit ef2d07f6 authored by Nikos Roussos's avatar Nikos Roussos
Browse files

Add tag archives/feeds

parent 28ff5a1d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -15,7 +15,7 @@
# See the file 'LICENSE' for more information.
 
 
from os import path, listdir, makedirs
from os import path, listdir, makedirs, mkdir
import sys
import yaml
import time
Loading
Loading
@@ -112,24 +112,42 @@ def generate_posts():
return posts, tag_set
 
 
def generate_archive(posts):
def generate_archive(posts, tag_set):
print('Generating blog archive...')
 
env = Environment()
env.loader = FileSystemLoader('templates')
tpl = env.get_template('blog.html')
html = tpl.render(dict(
sitename=cfg['sitename'],
page='archive',
title='blog',
posts=posts
))
with open('blog.html', 'w') as file:
file.write(html)
 
for tag in tag_set:
print('Generating {0} archive page...'.format(tag))
post_list = []
for post in posts:
if tag in post['tags']:
post_list.append(post)
tpl = env.get_template('blog.html')
html = tpl.render(dict(
sitename=cfg['sitename'],
title='blog: {0}'.format(tag),
posts=post_list
))
tagpath = path.join('tag', tag)
try:
mkdir(tagpath)
except OSError:
pass
with open('{0}/index.html'.format(tagpath), 'w') as file:
file.write(html)
 
def generate_feed(posts, tag_set):
def generate_feeds(posts, tag_set):
print('Generating atom feed...')
 
env = Environment()
Loading
Loading
@@ -144,11 +162,11 @@ def generate_feed(posts, tag_set):
file.write(xml)
 
for tag in tag_set:
post_list = posts
print('Generating {0} atom feed...'.format(tag))
for post in post_list:
if 'python' not in post['tags']:
post_list.pop()
post_list = []
for post in posts:
if tag in post['tags']:
post_list.append(post)
xml = env.get_template('feed.xml').render(
items=post_list,
sitename=cfg['sitename'],
Loading
Loading
@@ -156,15 +174,20 @@ def generate_feed(posts, tag_set):
rooturl=cfg['rooturl'],
tagtitle=' • {0}'.format(tag)
)
with open('{0}.xml'.format(tag), 'w') as file:
tagpath = path.join('tag', tag)
try:
mkdir(tagpath)
except OSError:
pass
with open('{0}/feed.xml'.format(tagpath), 'w') as file:
file.write(xml)
 
 
def main():
generate_pages()
posts, tag_set = generate_posts()
generate_archive(posts)
generate_feed(posts, tag_set)
generate_archive(posts, tag_set)
generate_feeds(posts, tag_set)
 
 
if __name__ == '__main__':
Loading
Loading
{% extends "base.html" %}
 
{% block title %}• {{ title }}{% endblock title %}
{% block content %}
<div class="container">
<div class="row">
Loading
Loading
Loading
Loading
@@ -75,3 +75,7 @@ a:visited {
color: #f06;
text-decoration: underline;
}
a.text-muted {
color: #555;
}
{% extends "base.html" %}
 
{% block title %}&bull; {{ title }}{% endblock title %}
{% block content %}
<div class="container">
<h3>Blog</h3>
<h3>{{ title }}</h3>
 
<table class="table table-responsive">
{% for post in posts %}
Loading
Loading
@@ -11,7 +13,7 @@
<td>
<a href="{{ post.link }}">{{ post.title }}</a><br>
{% for tag in post.tags %}
<span class="text-muted">#{{ tag }}</span>&nbsp;
<a href="/tag/{{ tag }}/" class="text-muted">#{{ tag }}</a>&nbsp;
{% endfor %}
</td>
</tr>
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment