Skip to content

Commit

Permalink
Added example for a blog that shows update dates (#8)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexvoss authored Nov 24, 2023
1 parent 2c9c0ee commit 5d6a8f6
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/blog-update/.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
example:
tags:
- public # works without Insiders
- blog # functionality demonstrated
- simple # requires no extra plugins or other magic
- customization # shows how to customize the theme
authors:
alexvoss:
name: Alex Voss
description: Collaborator
avatar: https://github.com/alexvoss.png
27 changes: 27 additions & 0 deletions examples/blog-update/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# A blog with update dates shown

This example shows how to add a small customization that will show
then blog posts were [updated] on the blog index pages. (The blog page
template already contains this.)

It shows how to:

- add an update date in addition to the creation date for a post as in [My first post]
- override the template index pages, so
that the [main blog index], the [archive index] and the [categories
index] show the update date

**Note**: Please note that when overriding templates you are copying
part of the code that makes up Material for MkDocs and so need to take
care when upgrading. The [changelog] contains a note on which
templates have changed, if any.

If you have not already set up a blog for your site then please start
with the [Basic blog] example.

[changelog]: https://squidfunk.github.io/mkdocs-material/changelog/
[Basic blog]: ../blog-basic
[My first post]: blog/2023/10/11/my-first-blog-post
[main blog index]: blog
[archive index]: blog/archive/2023
[categories index]: blog/category/meta
9 changes: 9 additions & 0 deletions examples/blog-update/docs/blog/.authors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
authors:
squidfunk:
name: Martin Donath
description: Creator
avatar: https://github.com/squidfunk.png
alexvoss:
name: Alex Voss
description: Weltenwanderer
avatar: https://github.com/alexvoss.png
2 changes: 2 additions & 0 deletions examples/blog-update/docs/blog/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Blog

36 changes: 36 additions & 0 deletions examples/blog-update/docs/blog/posts/firstpost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
authors:
- alexvoss
date:
created: 2023-10-11
updated: 2023-10-18
categories:
- meta
---

# My first blog post

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nec
maximus ex. Sed consequat, nulla quis malesuada dapibus, elit metus vehicula
erat, ut egestas tellus eros at risus. In hac habitasse platea dictumst.
Phasellus id lacus pulvinar erat consequat pretium. Morbi malesuada arcu mauris
Nam vel justo sem. Nam placerat purus non varius luctus. Integer pretium leo in
sem rhoncus, quis gravida orci mollis. Proin id aliquam est. Vivamus in nunc ac
metus tristique pellentesque. Suspendisse viverra urna in accumsan aliquet.

<!-- more -->

Donec volutpat, elit ac volutpat laoreet, turpis dolor semper nibh, et dictum
massa ex pulvinar elit. Curabitur commodo sit amet dolor sed mattis. Etiam
tempor odio eu nisi gravida cursus. Maecenas ante enim, fermentum sit amet
molestie nec, mollis ac libero. Vivamus sagittis suscipit eros ut luctus.

Nunc vehicula sagittis condimentum. Cras facilisis bibendum lorem et feugiat.
In auctor accumsan ligula, at consectetur erat commodo quis. Morbi ac nunc
pharetra, pellentesque risus in, consectetur urna. Nulla id enim facilisis
arcu tincidunt pulvinar. Vestibulum laoreet risus scelerisque porta congue.
In velit purus, dictum quis neque nec, molestie viverra risus. Nam pellentesque
tellus id elit ultricies, vel finibus erat cursus.

Edit: Nam placerat purus non varius luctus. Integer pretium leo in
sem rhoncus, quis gravida orci mollis. Proin id aliquam est.
32 changes: 32 additions & 0 deletions examples/blog-update/docs/blog/posts/secondpost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
authors:
- squidfunk
date: 2023-10-12
categories:
- hello
---

# A second post

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nec
maximus ex. Sed consequat, nulla quis malesuada dapibus, elit metus vehicula
erat, ut egestas tellus eros at risus. In hac habitasse platea dictumst.
Phasellus id lacus pulvinar erat consequat pretium. Morbi malesuada arcu mauris
Nam vel justo sem. Nam placerat purus non varius luctus. Integer pretium leo in
sem rhoncus, quis gravida orci mollis. Proin id aliquam est. Vivamus in nunc ac
metus tristique pellentesque. Suspendisse viverra urna in accumsan aliquet.

<!-- more -->

Donec volutpat, elit ac volutpat laoreet, turpis dolor semper nibh, et dictum
massa ex pulvinar elit. Curabitur commodo sit amet dolor sed mattis. Etiam
tempor odio eu nisi gravida cursus. Maecenas ante enim, fermentum sit amet
molestie nec, mollis ac libero. Vivamus sagittis suscipit eros ut luctus.

Nunc vehicula sagittis condimentum. Cras facilisis bibendum lorem et feugiat.
In auctor accumsan ligula, at consectetur erat commodo quis. Morbi ac nunc
pharetra, pellentesque risus in, consectetur urna. Nulla id enim facilisis
arcu tincidunt pulvinar. Vestibulum laoreet risus scelerisque porta congue.
In velit purus, dictum quis neque nec, molestie viverra risus. Nam pellentesque
tellus id elit ultricies, vel finibus erat cursus.

40 changes: 40 additions & 0 deletions examples/blog-update/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2016-2023 Martin Donath <[email protected]>
# Alex Voss <[email protected]>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

# -----------------------------------------------------------------------------
# Recommended: set up configuration validation, see https://t.ly/xpZXU
# -----------------------------------------------------------------------------

# Project information
site_name: Blog that shows post updates

# Theme
theme:
name: material
custom_dir: overrides

watch:
- overrides

# Plugins
plugins:
- search
- blog
70 changes: 70 additions & 0 deletions examples/blog-update/overrides/partials/post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{#-
Remember to check the changelog when updating Material for MkDocs. If the
template has changed it is generally a good idea to apply the customization
to the new one instead of depending on an old template, which may cause
problems downstream.
-#}
<article class="md-post md-post--excerpt">
<header class="md-post__header">
{% if post.authors %}
<nav class="md-post__authors md-typeset">
{% for author in post.authors %}
<span class="md-author">
<img src="{{ author.avatar }}" alt="{{ author.name }}">
</span>
{% endfor %}
</nav>
{% endif %}
<div class="md-post__meta md-meta">
<ul class="md-meta__list">
<li class="md-meta__item">
<time datetime="{{ post.config.date.created }}">
{{- post.config.date.created | date -}}
</time>
<!-- start customization -->
{% if post.config.date.updated %}
<time datetime="{{ post.config.date.updated }}">
({{ post.config.date.updated | date }})
</time>
{% endif %}
<!-- end customization -->
{#- Collapse whitespace -#}
</li>
{% if post.categories %}
<li class="md-meta__item">
{{ lang.t("blog.categories.in") }}
{% for category in post.categories %}
<a href="{{ category.url | url }}" class="md-meta__link">
{{- category.title -}}
</a>
{%- if loop.revindex > 1 %}, {% endif -%}
{% endfor -%}
</li>
{% endif %}
{% if post.config.readtime %}
{% set time = post.config.readtime %}
<li class="md-meta__item">
{% if time == 1 %}
{{ lang.t("readtime.one") }}
{% else %}
{{ lang.t("readtime.other") | replace("#", time) }}
{% endif %}
</li>
{% endif %}
</ul>
{% if post.config.draft %}
<span class="md-draft">
{{ lang.t("blog.draft") }}
</span>
{% endif %}
</div>
</header>
<div class="md-post__content md-typeset">
{{ post.content }}
<nav class="md-post__action">
<a href="{{ post.url | url }}">
{{ lang.t("blog.continue") }}
</a>
</nav>
</div>
</article>
21 changes: 21 additions & 0 deletions examples/blog-update/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2016-2023 Martin Donath <[email protected]>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

mkdocs-material

0 comments on commit 5d6a8f6

Please sign in to comment.