Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog: Allow use of post.title in templates #6491

Open
4 tasks done
copdips opened this issue Dec 12, 2023 · 10 comments
Open
4 tasks done

Blog: Allow use of post.title in templates #6491

copdips opened this issue Dec 12, 2023 · 10 comments
Labels
change request Issue requests a new feature or improvement

Comments

@copdips
Copy link
Contributor

copdips commented Dec 12, 2023

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

@squidfunk
Copy link
Owner

squidfunk commented Dec 12, 2023

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 squidfunk closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2023
@squidfunk squidfunk added change request Issue requests a new feature or improvement resolved by customization Issue can be solved through customization labels Dec 12, 2023
@copdips
Copy link
Contributor Author

copdips commented Dec 12, 2023

@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 ?

@squidfunk
Copy link
Owner

squidfunk commented Dec 12, 2023

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.

@alexvoss
Copy link
Sponsor Collaborator

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.

@squidfunk
Copy link
Owner

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

@copdips
Copy link
Contributor Author

copdips commented Dec 12, 2023

@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.

@alexvoss
Copy link
Sponsor Collaborator

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.

@copdips
Copy link
Contributor Author

copdips commented Dec 12, 2023

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

@squidfunk
Copy link
Owner

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 squidfunk reopened this Dec 12, 2023
@squidfunk squidfunk removed the resolved by customization Issue can be solved through customization label Dec 12, 2023
@squidfunk squidfunk changed the title [Blog] Add option to disaply only title and some metadata when excerpt is missing Blog: Allow use of post.title in templates Dec 12, 2023
@squidfunk
Copy link
Owner

squidfunk commented Dec 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change request Issue requests a new feature or improvement
Projects
None yet
Development

No branches or pull requests

3 participants