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

Metadata on a per-page basis #2142

Open
cr0mll opened this issue Jul 25, 2023 · 2 comments
Open

Metadata on a per-page basis #2142

cr0mll opened this issue Jul 25, 2023 · 2 comments
Labels
C-enhancement Category: Enhancement or feature request

Comments

@cr0mll
Copy link

cr0mll commented Jul 25, 2023

Problem

There should simply be a way to specify custom metadata for each page and maybe have some predefined metadata attributes such as keywords, author information, or time of creation/modification which mdbook handles on its own.

For example, page keywords are only specified for the book as a whole - you cannot have separate keywords for each page which can make it difficult for people using search engines to find the correct page.

However, this can be augmented by also allowing one to specify for example author information for each page. This is useful for projects with multiple contributors which would like to give proper credit.

Proposed Solution

The way https://chirpy.cotes.page/ do things seems like an appropriate way to implement. Metadata is inserted into each page as key-value pairs in a markdown comment at the top of each page.

The value of each metadata attribute should be accessible as a template in index.hbs with {{ attribute_name }}.

Notes

This is not a request to implement specific metadata tags such as keywords or author information, but simply a request to expose custom metadata for each page as templates in index.hbs.

@cr0mll cr0mll added the C-enhancement Category: Enhancement or feature request label Jul 25, 2023
@noraj
Copy link

noraj commented Sep 11, 2023

Metadata is inserted into each page as key-value pairs in a markdown comment at the top of each page.

It's called front-matter (like in hexo https://hexo.io/docs/front-matter). Generally the easiest front-matter for markdown format is using YAML.

Potentially inspirational projects:

Also Zola Rust staticgen has some front-matters: https://github.com/search?q=repo%3Agetzola%2Fzola%20frontmatter&type=code

@sspaeti
Copy link
Contributor

sspaeti commented Feb 20, 2024

I think this feature is very relevant if you want to share your book's subpage on socials and have an accurate description and feature image. I made a suggestion on how something like that could be implemented with front-matter in this comment: #1416 (comment).

I guess it wouldn't be too hard, we'd need a front-matter parser (here some I found):

And just include these in the index.hbs as illustrated in my comment. What do you think?

UPDATE: I made a PR that works for me, still a bit hacky, but can be improved: #2321.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement or feature request
Projects
None yet
Development

No branches or pull requests

3 participants