Skip to content

Commit 5d6a8f6

Browse files
authored
Added example for a blog that shows update dates (#8)
* added example for a blog that shows update dates these exist already in the template for the posts but were left out of the index pages for a tidier look. * implemented PR feedback - fixed typo - removed   - replaced "don't edit" warning with message about updates - added note on updates to README - fixed indentation
1 parent 2c9c0ee commit 5d6a8f6

File tree

9 files changed

+248
-0
lines changed

9 files changed

+248
-0
lines changed

examples/blog-update/.example.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
example:
2+
tags:
3+
- public # works without Insiders
4+
- blog # functionality demonstrated
5+
- simple # requires no extra plugins or other magic
6+
- customization # shows how to customize the theme
7+
authors:
8+
alexvoss:
9+
name: Alex Voss
10+
description: Collaborator
11+
avatar: https://github.com/alexvoss.png

examples/blog-update/docs/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# A blog with update dates shown
2+
3+
This example shows how to add a small customization that will show
4+
then blog posts were [updated] on the blog index pages. (The blog page
5+
template already contains this.)
6+
7+
It shows how to:
8+
9+
- add an update date in addition to the creation date for a post as in [My first post]
10+
- override the template index pages, so
11+
that the [main blog index], the [archive index] and the [categories
12+
index] show the update date
13+
14+
**Note**: Please note that when overriding templates you are copying
15+
part of the code that makes up Material for MkDocs and so need to take
16+
care when upgrading. The [changelog] contains a note on which
17+
templates have changed, if any.
18+
19+
If you have not already set up a blog for your site then please start
20+
with the [Basic blog] example.
21+
22+
[changelog]: https://squidfunk.github.io/mkdocs-material/changelog/
23+
[Basic blog]: ../blog-basic
24+
[My first post]: blog/2023/10/11/my-first-blog-post
25+
[main blog index]: blog
26+
[archive index]: blog/archive/2023
27+
[categories index]: blog/category/meta
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
authors:
2+
squidfunk:
3+
name: Martin Donath
4+
description: Creator
5+
avatar: https://github.com/squidfunk.png
6+
alexvoss:
7+
name: Alex Voss
8+
description: Weltenwanderer
9+
avatar: https://github.com/alexvoss.png
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Blog
2+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
authors:
3+
- alexvoss
4+
date:
5+
created: 2023-10-11
6+
updated: 2023-10-18
7+
categories:
8+
- meta
9+
---
10+
11+
# My first blog post
12+
13+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nec
14+
maximus ex. Sed consequat, nulla quis malesuada dapibus, elit metus vehicula
15+
erat, ut egestas tellus eros at risus. In hac habitasse platea dictumst.
16+
Phasellus id lacus pulvinar erat consequat pretium. Morbi malesuada arcu mauris
17+
Nam vel justo sem. Nam placerat purus non varius luctus. Integer pretium leo in
18+
sem rhoncus, quis gravida orci mollis. Proin id aliquam est. Vivamus in nunc ac
19+
metus tristique pellentesque. Suspendisse viverra urna in accumsan aliquet.
20+
21+
<!-- more -->
22+
23+
Donec volutpat, elit ac volutpat laoreet, turpis dolor semper nibh, et dictum
24+
massa ex pulvinar elit. Curabitur commodo sit amet dolor sed mattis. Etiam
25+
tempor odio eu nisi gravida cursus. Maecenas ante enim, fermentum sit amet
26+
molestie nec, mollis ac libero. Vivamus sagittis suscipit eros ut luctus.
27+
28+
Nunc vehicula sagittis condimentum. Cras facilisis bibendum lorem et feugiat.
29+
In auctor accumsan ligula, at consectetur erat commodo quis. Morbi ac nunc
30+
pharetra, pellentesque risus in, consectetur urna. Nulla id enim facilisis
31+
arcu tincidunt pulvinar. Vestibulum laoreet risus scelerisque porta congue.
32+
In velit purus, dictum quis neque nec, molestie viverra risus. Nam pellentesque
33+
tellus id elit ultricies, vel finibus erat cursus.
34+
35+
Edit: Nam placerat purus non varius luctus. Integer pretium leo in
36+
sem rhoncus, quis gravida orci mollis. Proin id aliquam est.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
authors:
3+
- squidfunk
4+
date: 2023-10-12
5+
categories:
6+
- hello
7+
---
8+
9+
# A second post
10+
11+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nec
12+
maximus ex. Sed consequat, nulla quis malesuada dapibus, elit metus vehicula
13+
erat, ut egestas tellus eros at risus. In hac habitasse platea dictumst.
14+
Phasellus id lacus pulvinar erat consequat pretium. Morbi malesuada arcu mauris
15+
Nam vel justo sem. Nam placerat purus non varius luctus. Integer pretium leo in
16+
sem rhoncus, quis gravida orci mollis. Proin id aliquam est. Vivamus in nunc ac
17+
metus tristique pellentesque. Suspendisse viverra urna in accumsan aliquet.
18+
19+
<!-- more -->
20+
21+
Donec volutpat, elit ac volutpat laoreet, turpis dolor semper nibh, et dictum
22+
massa ex pulvinar elit. Curabitur commodo sit amet dolor sed mattis. Etiam
23+
tempor odio eu nisi gravida cursus. Maecenas ante enim, fermentum sit amet
24+
molestie nec, mollis ac libero. Vivamus sagittis suscipit eros ut luctus.
25+
26+
Nunc vehicula sagittis condimentum. Cras facilisis bibendum lorem et feugiat.
27+
In auctor accumsan ligula, at consectetur erat commodo quis. Morbi ac nunc
28+
pharetra, pellentesque risus in, consectetur urna. Nulla id enim facilisis
29+
arcu tincidunt pulvinar. Vestibulum laoreet risus scelerisque porta congue.
30+
In velit purus, dictum quis neque nec, molestie viverra risus. Nam pellentesque
31+
tellus id elit ultricies, vel finibus erat cursus.
32+

examples/blog-update/mkdocs.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) 2016-2023 Martin Donath <[email protected]>
2+
# Alex Voss <[email protected]>
3+
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to
6+
# deal in the Software without restriction, including without limitation the
7+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8+
# sell copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
11+
# The above copyright notice and this permission notice shall be included in
12+
# all copies or substantial portions of the Software.
13+
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20+
# IN THE SOFTWARE.
21+
22+
# -----------------------------------------------------------------------------
23+
# Recommended: set up configuration validation, see https://t.ly/xpZXU
24+
# -----------------------------------------------------------------------------
25+
26+
# Project information
27+
site_name: Blog that shows post updates
28+
29+
# Theme
30+
theme:
31+
name: material
32+
custom_dir: overrides
33+
34+
watch:
35+
- overrides
36+
37+
# Plugins
38+
plugins:
39+
- search
40+
- blog
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{#-
2+
Remember to check the changelog when updating Material for MkDocs. If the
3+
template has changed it is generally a good idea to apply the customization
4+
to the new one instead of depending on an old template, which may cause
5+
problems downstream.
6+
-#}
7+
<article class="md-post md-post--excerpt">
8+
<header class="md-post__header">
9+
{% if post.authors %}
10+
<nav class="md-post__authors md-typeset">
11+
{% for author in post.authors %}
12+
<span class="md-author">
13+
<img src="{{ author.avatar }}" alt="{{ author.name }}">
14+
</span>
15+
{% endfor %}
16+
</nav>
17+
{% endif %}
18+
<div class="md-post__meta md-meta">
19+
<ul class="md-meta__list">
20+
<li class="md-meta__item">
21+
<time datetime="{{ post.config.date.created }}">
22+
{{- post.config.date.created | date -}}
23+
</time>
24+
<!-- start customization -->
25+
{% if post.config.date.updated %}
26+
<time datetime="{{ post.config.date.updated }}">
27+
({{ post.config.date.updated | date }})
28+
</time>
29+
{% endif %}
30+
<!-- end customization -->
31+
{#- Collapse whitespace -#}
32+
</li>
33+
{% if post.categories %}
34+
<li class="md-meta__item">
35+
{{ lang.t("blog.categories.in") }}
36+
{% for category in post.categories %}
37+
<a href="{{ category.url | url }}" class="md-meta__link">
38+
{{- category.title -}}
39+
</a>
40+
{%- if loop.revindex > 1 %}, {% endif -%}
41+
{% endfor -%}
42+
</li>
43+
{% endif %}
44+
{% if post.config.readtime %}
45+
{% set time = post.config.readtime %}
46+
<li class="md-meta__item">
47+
{% if time == 1 %}
48+
{{ lang.t("readtime.one") }}
49+
{% else %}
50+
{{ lang.t("readtime.other") | replace("#", time) }}
51+
{% endif %}
52+
</li>
53+
{% endif %}
54+
</ul>
55+
{% if post.config.draft %}
56+
<span class="md-draft">
57+
{{ lang.t("blog.draft") }}
58+
</span>
59+
{% endif %}
60+
</div>
61+
</header>
62+
<div class="md-post__content md-typeset">
63+
{{ post.content }}
64+
<nav class="md-post__action">
65+
<a href="{{ post.url | url }}">
66+
{{ lang.t("blog.continue") }}
67+
</a>
68+
</nav>
69+
</div>
70+
</article>

examples/blog-update/requirements.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2016-2023 Martin Donath <[email protected]>
2+
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to
5+
# deal in the Software without restriction, including without limitation the
6+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
# sell copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
# IN THE SOFTWARE.
20+
21+
mkdocs-material

0 commit comments

Comments
 (0)