From 28ebcbfb59f16b21d6d3e5e2b3741b72ebaa9c57 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Sun, 26 Nov 2023 14:29:38 +0100 Subject: [PATCH] Added support for linking authors in blog posts Co-authored-by: alexvoss <4134224+alexvoss@users.noreply.github.com> --- docs/blog/.authors.yml | 2 ++ docs/plugins/blog.md | 1 + material/plugins/blog/author.py | 3 ++- material/templates/blog-post.html | 9 ++++++++- src/plugins/blog/author.py | 3 ++- src/templates/blog-post.html | 9 ++++++++- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/blog/.authors.yml b/docs/blog/.authors.yml index 6a4302069fc..cd63d30973c 100644 --- a/docs/blog/.authors.yml +++ b/docs/blog/.authors.yml @@ -3,7 +3,9 @@ authors: name: Martin Donath description: Creator avatar: https://avatars.githubusercontent.com/u/932156 + url: https://github.com/squidfunk alexvoss: name: Alex Voss description: Community support avatar: https://avatars.githubusercontent.com/u/4134224 + url: https://github.com/alexvoss diff --git a/docs/plugins/blog.md b/docs/plugins/blog.md index 488770799e7..227a30913fc 100644 --- a/docs/plugins/blog.md +++ b/docs/plugins/blog.md @@ -1205,6 +1205,7 @@ The provided path is resolved from the [`docs` directory][mkdocs.docs_dir]. name: string # Author name description: string # Author description avatar: url # Author avatar + url: url # Author website URL ``` Note that `` must be set to an identifier for associating authors diff --git a/material/plugins/blog/author.py b/material/plugins/blog/author.py index 1dcfc2de22a..5fb457b1929 100644 --- a/material/plugins/blog/author.py +++ b/material/plugins/blog/author.py @@ -19,7 +19,7 @@ # IN THE SOFTWARE. from mkdocs.config.base import Config -from mkdocs.config.config_options import DictOfItems, SubConfig, Type +from mkdocs.config.config_options import DictOfItems, Optional, SubConfig, Type # ----------------------------------------------------------------------------- # Classes @@ -30,6 +30,7 @@ class Author(Config): name = Type(str) description = Type(str) avatar = Type(str) + url = Optional(Type(str)) # ----------------------------------------------------------------------------- diff --git a/material/templates/blog-post.html b/material/templates/blog-post.html index 8e3e5f2c55d..6804a6af9fe 100644 --- a/material/templates/blog-post.html +++ b/material/templates/blog-post.html @@ -27,7 +27,14 @@ {{ author.name }} - {{ author.name }}
+ + {% if author.url %} + {{ author.name }} + {% else %} + {{ author.name }} + {% endif %} + +
{{ author.description }}
diff --git a/src/plugins/blog/author.py b/src/plugins/blog/author.py index 1dcfc2de22a..5fb457b1929 100644 --- a/src/plugins/blog/author.py +++ b/src/plugins/blog/author.py @@ -19,7 +19,7 @@ # IN THE SOFTWARE. from mkdocs.config.base import Config -from mkdocs.config.config_options import DictOfItems, SubConfig, Type +from mkdocs.config.config_options import DictOfItems, Optional, SubConfig, Type # ----------------------------------------------------------------------------- # Classes @@ -30,6 +30,7 @@ class Author(Config): name = Type(str) description = Type(str) avatar = Type(str) + url = Optional(Type(str)) # ----------------------------------------------------------------------------- diff --git a/src/templates/blog-post.html b/src/templates/blog-post.html index 73fb669f7dd..21abd499dc0 100644 --- a/src/templates/blog-post.html +++ b/src/templates/blog-post.html @@ -59,7 +59,14 @@ {{ author.name }} - {{ author.name }}
+ + {% if author.url %} + {{ author.name }} + {% else %} + {{ author.name }} + {% endif %} + +
{{ author.description }}