-
Hi, I am new here. I want to add the most recent blog posts at the end of the home page. For this, I overridden the
However, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hello @anp-scp, mkdocs-material/src/plugins/blog/plugin.py Lines 352 to 354 in 0fc36a1 From your code I guess that your home page is separate from the blog home page, right? Then I recommend using a
To get access to the pages you'd have to use some sort of hook: Rendering the Excerpts as in the Blog views would be tricky unless I'm missing something 🤔 All in a
|
Beta Was this translation helpful? Give feedback.
-
Hello, @kamilkrzyskow !!! Thanks for the help. It worked. Thanks again !!! |
Beta Was this translation helpful? Give feedback.
-
Here's the solution I reached following the pointers suggested by @kamilkrzyskow ✌️ :
def on_page_context(context, page, config, nav):
if page.meta.get("template") != "home.html": return
context["posts"] = config["plugins"]["material/blog"].blog.posts
return context
hooks:
- recent_post_hook.py
{% extends "main.html" %}
<!-- Page content -->
{% block container %}
<div class="md-content" data-md-component="content">
<div class="md-content__inner">
<!-- Header -->
<header class="md-typeset">
{{ page.content }}
<!-- 5 recent posts -->
<br>
<h1>Posts</h1>
<div class="custom_table">
<table>
<tbody>
{% for post in posts[:5] %}
<tr>
<td>
<time datetime="{{ post.config.date.created }}">
{{- post.config.date.created | date -}}
</time>
</td>
<td><a href="{{ post.url }}">{{ post.title }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<a class="pub_button pub_button_clickable" href="blog">All posts</a>
</header>
</div>
</div>
{% endblock %} NOTE: CSS classes |
Beta Was this translation helpful? Give feedback.
Here's the solution I reached following the pointers suggested by @kamilkrzyskow ✌️ :
recent_post_hook.py
) with the following method:mkdocs.yml
:5
recent blog posts (the blog posts seemed to be already in descending order of the creation date) at the end of the home page. I followed https://github.com/squidfunk/mkdo…