Add category pages.
This commit is contained in:
parent
7d1524e270
commit
f25bfb1ef6
@ -46,6 +46,7 @@ ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
STATIC_PATH = os.path.join(ROOT_DIR, 'static')
|
||||
ARTICLE_TEMPLATE_NAME = 'article.tmpl.html'
|
||||
BLOG_INDEX_TEMPLATE_NAME = 'blog_index.tmpl.html'
|
||||
CATEGORY_LIST_TEMPLATE_NAME = 'category_list.tmpl.html'
|
||||
BLOG_INDEX_PAGE_SIZE = 10
|
||||
|
||||
STATIC_RESOURCES = (
|
||||
@ -64,6 +65,8 @@ def update_statics():
|
||||
ARTICLE_TEMPLATE = JINJA_ENV.get_template(ARTICLE_TEMPLATE_NAME)
|
||||
global BLOG_INDEX_TEMPLATE
|
||||
BLOG_INDEX_TEMPLATE = JINJA_ENV.get_template(BLOG_INDEX_TEMPLATE_NAME)
|
||||
global CATEGORY_LIST_TEMPLATE
|
||||
CATEGORY_LIST_TEMPLATE = JINJA_ENV.get_template(CATEGORY_LIST_TEMPLATE_NAME)
|
||||
|
||||
update_statics()
|
||||
|
||||
@ -319,6 +322,38 @@ def render_index(docs, dest_top):
|
||||
with open(os.path.join(dest_top, fname), 'wt') as f:
|
||||
f.write(result)
|
||||
|
||||
def render_categories(docs, dest_top):
|
||||
categories = {}
|
||||
for (doc, front_matter, out_path) in docs.values():
|
||||
for tag in split_tags(front_matter['tags']):
|
||||
if tag not in categories:
|
||||
categories[tag] = []
|
||||
categories[tag].append((doc, front_matter, out_path))
|
||||
|
||||
print("Found {} tags".format(len(categories), categories))
|
||||
for tag, docs in categories.items():
|
||||
docs = sorted(docs, key=lambda x: x[1]['date'], reverse=True)
|
||||
|
||||
posts = [
|
||||
{
|
||||
# "doc": doc,
|
||||
"title": front_matter['title'],
|
||||
"post_publication_date": front_matter['date'],
|
||||
"post_tags": split_tags(front_matter['tags']),
|
||||
# "summary": summarize(doc),
|
||||
"link": out_path.rstrip('/') + '/',
|
||||
}
|
||||
for (doc, front_matter, out_path) in docs
|
||||
]
|
||||
|
||||
result = CATEGORY_LIST_TEMPLATE.render(
|
||||
posts=posts,
|
||||
)
|
||||
path = os.path.join(dest_top, "tags", tag, "index.html")
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, 'wt') as f:
|
||||
f.write(result)
|
||||
|
||||
|
||||
def regen_all(source_top, dest_top, docs=None):
|
||||
if docs is None:
|
||||
@ -359,6 +394,9 @@ def regen_all(source_top, dest_top, docs=None):
|
||||
# Render index
|
||||
render_index(docs, dest_top)
|
||||
|
||||
# Render categories
|
||||
render_categories(docs, dest_top)
|
||||
|
||||
return docs
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
</time>
|
||||
<ul class="post-tags">
|
||||
{% for post_tag in post_tags %}
|
||||
<li class="post-tag">{{ post_tag }}</li>
|
||||
<li class="post-tag"><a href="../../tags/{{ post_tag }}/"</a>{{ post_tag }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -37,7 +37,7 @@
|
||||
</time>
|
||||
<ul class="post-tags">
|
||||
{% for post_tag in post.post_tags %}
|
||||
<li class="post-tag">{{ post_tag }}</li>
|
||||
<li class="post-tag"><a href="tags/{{ post_tag }}/"</a>{{ post_tag }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
54
static/category_list.tmpl.html
Normal file
54
static/category_list.tmpl.html
Normal file
@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Código para llevar</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="../../css/style.css" />
|
||||
<link rel="stylesheet" href="../../css/light-syntax.css" />
|
||||
<link rel="stylesheet" href="../../css/dark-syntax.css" />
|
||||
</head>
|
||||
<body class="blog">
|
||||
<div class="site-header">
|
||||
<h1 class="site-name"><a href="../../">Codigo para llevar [blog]</a></h1>
|
||||
<nav class="site-links">
|
||||
<span class="fancy-link">
|
||||
<a href="../../../">Home</a>
|
||||
</span>
|
||||
<span class="fancy-link">
|
||||
<a href="../../../notes/">Notes</a>
|
||||
</span>
|
||||
<span class="fancy-link">
|
||||
<a href="https://github.com/kenkeiras">GitHub</a>
|
||||
</span>
|
||||
<span class="fancy-link">
|
||||
<a href="https://gitlab.com/kenkeiras">GitLab</a>
|
||||
</span>
|
||||
<span class="fancy-link">
|
||||
<a href="https://programaker.com/users/kenkeiras">PrograMaker</a>
|
||||
</span>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="post-list content">
|
||||
<ul>
|
||||
{% for post in posts %}
|
||||
<li class="post">
|
||||
<div class="post-metadata">
|
||||
<time class="post-publication-date" datetime="{{ post.post_publication_date.date() }}">
|
||||
{{ post.post_publication_date.date() }}
|
||||
</time>
|
||||
</div>
|
||||
<h4 class="post-title"><a href="../../{{ post.link }}">{{ post.title }}</a></h4>
|
||||
<div class="post-metadata">
|
||||
<ul class="post-tags">
|
||||
{% for post_tag in post.post_tags %}
|
||||
<li class="post-tag"><a href="../../tags/{{ post_tag }}/"</a>{{ post_tag }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -486,6 +486,16 @@ article.post {
|
||||
content: '< ';
|
||||
}
|
||||
|
||||
/* Categories and archive */
|
||||
.post-list .post .post-metadata,
|
||||
.post-list .post h4 {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.post-list .post {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
/* Tables. */
|
||||
table, th, td, tr {
|
||||
border: 1px solid black;
|
||||
|
Loading…
Reference in New Issue
Block a user