Skip to content

Commit

Permalink
Add url parameter for macros
Browse files Browse the repository at this point in the history
  • Loading branch information
liang2kl committed Sep 24, 2021
1 parent 81eba07 commit fc6391b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) -%}
<a href="{{ url }}">
<h3>{{ title }}</h3>
<div>{{ description }}</div>
<div>{{ time }}</div>
<hr/>
{{ caller() }}
</a>
<div>{{ description }}</div>
<div>{{ time }}</div>
<hr/>
{{ caller() }}
{%- endmacro %}
{% extends "blog.html" %}
Expand All @@ -119,7 +121,9 @@ the top if you want to preserve the original style.
```jinja
{% block style %}
{{ super() }}
{# your style goes here #}
<style>
{# your style goes here #}
</style>
{% endblock %}
```

Expand Down
5 changes: 3 additions & 2 deletions mkdocs_blogging_plugin/templates/blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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 %}
<div class="blog-post">
<h3 class="blog-post-title">
<a class="link" href="{{ pg.canonical_url }}">{{ title }}</a>
<a class="link" href="{{ url }}">{{ title }}</a>
</h3>
<p class="blog-post-description">
{{ description }}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit fc6391b

Please sign in to comment.