From fc6391b041f79d7243f220258b63c3f74de3817e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E4=B8=9A=E5=8D=87?= Date: Fri, 24 Sep 2021 19:31:02 +0800 Subject: [PATCH] Add url parameter for macros --- README.md | 18 +++++++++++------- mkdocs_blogging_plugin/templates/blog.html | 5 +++-- setup.py | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8c22330..8ba744e 100644 --- a/README.md +++ b/README.md @@ -94,18 +94,20 @@ To customize the blog content, create an HTML template with name **other than** You can override how the plugin render a single blog through this method. -In your template, define a macro that renders a single blog with the provided parameters `title`, `description` and `time`. +In your template, define a macro that renders a single blog with the provided parameters `title`, `description`, `time` and `url`. Then add a line `{% extends "blog.html" %}` **below** the macro. Please note that `{{ caller() }}` must be present somewhere inside the macro. ```jinja -{% macro render_blog(title, description, time) -%} +{% macro render_blog(title, description, time, url) -%} +

{{ title }}

-
{{ description }}
-
{{ time }}
-
- {{ caller() }} +
+
{{ description }}
+
{{ time }}
+
+ {{ caller() }} {%- endmacro %} {% extends "blog.html" %} @@ -119,7 +121,9 @@ the top if you want to preserve the original style. ```jinja {% block style %} {{ super() }} - {# your style goes here #} + {% endblock %} ``` diff --git a/mkdocs_blogging_plugin/templates/blog.html b/mkdocs_blogging_plugin/templates/blog.html index 14dc00a..f3de15c 100644 --- a/mkdocs_blogging_plugin/templates/blog.html +++ b/mkdocs_blogging_plugin/templates/blog.html @@ -93,6 +93,7 @@ {% for pg in pg_group %} {# Setting variables. #} + {% set url = pg.canonical_url %} {% set title = pg.title %} {% if pg.meta and pg.meta.title_full %} {% set title = pg.meta.title_full %} @@ -112,12 +113,12 @@ {# Render blogs. If a marco is provided, then use the marco to render. #} {% if render_blog is defined %} - {% call render_blog(title, description, time) %} + {% call render_blog(title, description, time, url) %} {% endcall %} {% else %}

- {{ title }} + {{ title }}

{{ description }} diff --git a/setup.py b/setup.py index cb76d0a..392bf07 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="mkdocs-blogging-plugin", - version="0.2.0", + version="0.2.1", description="Mkdocs plugin that generates a blog index page sorted by creation date.", long_description=LONG_DESCRIPTION, long_description_content_type="text/markdown",