diff --git a/scripts/blog.py b/scripts/blog.py index 3a5a11b..3f7d5eb 100644 --- a/scripts/blog.py +++ b/scripts/blog.py @@ -47,6 +47,7 @@ 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' +ARTICLE_LIST_TEMPLATE_NAME = 'article_list.tmpl.html' BLOG_INDEX_PAGE_SIZE = 10 STATIC_RESOURCES = ( @@ -67,6 +68,8 @@ def update_statics(): 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) + global ARTICLE_LIST_TEMPLATE + ARTICLE_LIST_TEMPLATE = JINJA_ENV.get_template(ARTICLE_LIST_TEMPLATE_NAME) update_statics() @@ -354,6 +357,29 @@ def render_categories(docs, dest_top): with open(path, 'wt') as f: f.write(result) +def render_archive(docs, dest_top): + docs = sorted(docs.values(), 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 = ARTICLE_LIST_TEMPLATE.render( + posts=posts, + ) + path = os.path.join(dest_top, "articles", "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: @@ -397,6 +423,9 @@ def regen_all(source_top, dest_top, docs=None): # Render categories render_categories(docs, dest_top) + # Render archive + render_archive(docs, dest_top) + return docs diff --git a/static/article_list.tmpl.html b/static/article_list.tmpl.html new file mode 100644 index 0000000..0e52252 --- /dev/null +++ b/static/article_list.tmpl.html @@ -0,0 +1,54 @@ + + + + + Código para llevar + + + + + + + +
+ +
+ +