mkdocs-material icon indicating copy to clipboard operation
mkdocs-material copied to clipboard

Blog: Allow use of `post.title` in templates

Open copdips opened this issue 2 years ago • 10 comments

Context

No response

Description

Hello,

Current design is that when a blog excerpt is missing, the entire content is shown in the Blog view, the Category view and the Archive veiw.

This setting might seem to me a little bit too intrusive, as I would not like to see the whole content in list view, so is it possible to add an option to only display the blog titles and metadata when the except is missing ?

Thanks.

Related links

https://squidfunk.github.io/mkdocs-material/setup/setting-up-a-blog/#adding-an-excerpt

Use Cases

when people are migrating from another blog system to mkdoc material, and they don't have such <!-- more --> excerpt syntax yet in their orignal blogs. Showing the whole content in the list view is not expected.

Visuals

No response

Before submitting

copdips avatar Dec 12 '23 08:12 copdips

Thanks for suggesting. The blog plugin already has 52 settings, and we're not planning on adding settings that are solely in place to control templates. You can achieve this quite easily by theme extension by overriding the post.html partial, only showing titles + any options you like.

squidfunk avatar Dec 12 '23 10:12 squidfunk

@squidfunk I tried some combinaisions to replace {{ post.content }} in partials/post.html, none of them returns the title:

  • {{ post.config.title }}
  • {{ post.title }}
  • {{ post._title_from_render }}
  • {{ post.meta }} # this shows many info but without title neither

Could you please give a hint ?

copdips avatar Dec 12 '23 13:12 copdips

Oh right, the title is part of the content. Well, that's a little trickier than expected then. The easiest thing is probably to just insert <!-- more --> markers at the right place then, probably automatically with a hook.

squidfunk avatar Dec 12 '23 13:12 squidfunk

Hi @copdips, wondering what blogging system you are moving from? I had a look around and it does seem like some systems/themes do excerpts, while others do not. I always thought that they are a standard feature of blogging systems.

The reason I am interested is because I am working on a template for blogs in Material for MkDocs and am wondering about including some advice on migration paths.

alexvoss avatar Dec 12 '23 14:12 alexvoss

Big up for the idea to evaluate and document migration paths!

squidfunk avatar Dec 12 '23 14:12 squidfunk

@alexvoss I used Jekyll minimal mistakes previously.

It uses the excerpts part in the YAML header to extract the excerpts. However, if excerpts is empty, Jeklly minimal mistake will just show the title and the first line of the content, if the first line is too long, it will truncate it.

image

As a result, many of my blog posts do not have excerpts, but that's OK for me, as it does not display the entire content in list view.

copdips avatar Dec 12 '23 14:12 copdips

Thanks for this. Grabbing the first paragraph should be feasible, I think. A hook attaching itself to the on_page_markdown event would do. Fortunately, the blog plugin attaches itself with a low priority, so that it runs after other plugins/hooks. The main question seems to me to be how to parse the Markdown to find the first text paragraph. In a hook as opposed to a more generic plugin it might be possible to make some assumptions, though, which would make that easier.

alexvoss avatar Dec 12 '23 15:12 alexvoss

it would be nice to add post title in the post.metadata or post.config.

copdips avatar Dec 12 '23 15:12 copdips

Okay, I'll reopen this issue so we can check if we can somehow infer the title from the post. That should be possible somehow, but I'm not yet seeing it. I'll investigate in the future when I find some time.

squidfunk avatar Dec 12 '23 15:12 squidfunk

Okay, so I've investigated how we could add this functionality. The problem is not handing the post.title to the excerpt, as determined by MkDocs. The problem is that post.title does not include any formatting – this is all contained in post.content. I have an idea how this might be doable with some effort, i.e., to allow for more flexibility what gets extracted from posts, but it's nothing we can add quickly.

Thus, I recommend using the <!-- more --> separators in the meantime, either by adding them manually, or by writing a hook that adds them automatically after each headline, or whatever the structure of your blog posts is.

squidfunk avatar Dec 13 '23 18:12 squidfunk

We're currently not considering moving forward with this, due to how much of a hack the blog plugin already is – MkDocs just doesn't like generated content, and excerpts + views are generated. We already need to jump through a lot of hoops to make this happen. We will re-evaluate this feature request once we start working on the blog plugin again.

squidfunk avatar Jun 06 '24 11:06 squidfunk