mirror of
https://github.com/venthur/blag.git
synced 2025-11-25 20:52:43 +00:00
Split Archive into Index and Archive
This commit is contained in:
43
blag/blag.py
43
blag/blag.py
@@ -263,6 +263,7 @@ def build(args: argparse.Namespace) -> None:
|
||||
|
||||
page_template = env.get_template('page.html')
|
||||
article_template = env.get_template('article.html')
|
||||
index_template = env.get_template('index.html')
|
||||
archive_template = env.get_template('archive.html')
|
||||
tags_template = env.get_template('tags.html')
|
||||
tag_template = env.get_template('tag.html')
|
||||
@@ -283,6 +284,7 @@ def build(args: argparse.Namespace) -> None:
|
||||
blog_description=config['description'],
|
||||
blog_author=config['author'],
|
||||
)
|
||||
generate_index(articles, index_template, args.output_dir)
|
||||
generate_archive(articles, archive_template, args.output_dir)
|
||||
generate_tags(articles, tags_template, tag_template, args.output_dir)
|
||||
|
||||
@@ -302,6 +304,8 @@ def process_markdown(
|
||||
If a markdown file has a `date` metadata field it will be recognized
|
||||
as article otherwise as page.
|
||||
|
||||
Articles are sorted by date in descending order.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
convertibles
|
||||
@@ -309,12 +313,12 @@ def process_markdown(
|
||||
input_dir
|
||||
output_dir
|
||||
page_template, archive_template
|
||||
templats for pages and articles
|
||||
templates for pages and articles
|
||||
|
||||
Returns
|
||||
-------
|
||||
list[tuple[str, dict[str, Any]]], list[tuple[str, dict[str, Any]]]
|
||||
articles and pages
|
||||
articles and pages, articles are sorted by date in descending order.
|
||||
|
||||
"""
|
||||
logger.info("Converting Markdown files...")
|
||||
@@ -401,12 +405,14 @@ def generate_feed(
|
||||
feed.write(fh, encoding='utf8')
|
||||
|
||||
|
||||
def generate_archive(
|
||||
def generate_index(
|
||||
articles: list[tuple[str, dict[str, Any]]],
|
||||
template: Template,
|
||||
output_dir: str,
|
||||
) -> None:
|
||||
"""Generate the archive page.
|
||||
"""Generate the index page.
|
||||
|
||||
This is used for the index (i.e. landing) page.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -428,6 +434,35 @@ def generate_archive(
|
||||
fh.write(result)
|
||||
|
||||
|
||||
def generate_archive(
|
||||
articles: list[tuple[str, dict[str, Any]]],
|
||||
template: Template,
|
||||
output_dir: str,
|
||||
) -> None:
|
||||
"""Generate the archive page.
|
||||
|
||||
This is used for the full archive.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
articles
|
||||
List of articles. Each article has the destination path and a
|
||||
dictionary with the content.
|
||||
template
|
||||
output_dir
|
||||
|
||||
"""
|
||||
archive = []
|
||||
for dst, context in articles:
|
||||
entry = context.copy()
|
||||
entry['dst'] = dst
|
||||
archive.append(entry)
|
||||
|
||||
result = template.render(dict(archive=archive))
|
||||
with open(f'{output_dir}/archive.html', 'w') as fh:
|
||||
fh.write(result)
|
||||
|
||||
|
||||
def generate_tags(
|
||||
articles: list[tuple[str, dict[str, Any]]],
|
||||
tags_template: Template,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ site.title }}{% endblock %}
|
||||
{% block title %}Archive{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% for entry in archive %}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<h2>{{ site.description }}</h2>
|
||||
<ul>
|
||||
<li><a href="/">Blog</a></li>
|
||||
<li><a href="/archive.html">Archive</a></li>
|
||||
<li><a href="/tags/">Tags</a></li>
|
||||
<li><a href="/atom.xml">Atom Feed</a></li>
|
||||
</ul>
|
||||
|
||||
23
blag/templates/index.html
Normal file
23
blag/templates/index.html
Normal file
@@ -0,0 +1,23 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ site.title }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% for entry in archive[:10] %}
|
||||
|
||||
{% if entry.title %}
|
||||
<h1><a href="{{entry.dst}}">{{entry.title}}</a></h1>
|
||||
|
||||
{% if entry.description %}
|
||||
<p>— {{ entry.description }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
<p>Written on {{ entry.date.date() }}.</p>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
<p><a href="/archive.html">all articles...</a></p>
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user