Skip to content

Allow for raw HTML in extra head. #4793

@adiroiban

Description

@adiroiban

Is your feature request related to a problem? Please describe.

The frontmatter.head functionality is nice, but it would be great to allow inserting raw HTML.

My use case is this:

  • For my website I have a download page.
  • The download/release page is generate by the product build process, based on the available operating systems and CPU.
  • The download/release page is generated from a Jinja2 template
  • I would like to use vitepress to generate the Jinja2 template. This should allow injecting some Jinja2 markup in the header and the content

Inserting in the title already works.

The current code is here and it force rendering the content as HTML tags

async function renderHead(head: HeadConfig[]): Promise<string> {
const tags = await Promise.all(
head.map(async ([tag, attrs = {}, innerHTML = '']) => {
const openTag = `<${tag}${renderAttrs(attrs)}>`
if (tag !== 'link' && tag !== 'meta') {
if (
tag === 'script' &&
(attrs.type === undefined || attrs.type.includes('javascript'))
) {
innerHTML = await minifyScript(innerHTML, 'inline-script.js')
}
return `${openTag}${innerHTML}</${tag}>`
} else {
return openTag
}
})
)
return tags.join('\n ')
}

Describe the solution you'd like

Maybe not the ideal case... but this solution will keep the same interface.

The idea is that the RAW_VALUE marker is used to let vitepress know that we don't want to generate a tag.

---
head:
  - - meta
    - name: description
      content: hello
  - - RAW_VALUE
    - attr: ignored-but-required
    - "{%- block head %}{%- endblock %}"
---

Describe alternatives you've considered

As a workaround I can create a tag with a special tag, and than process the HTML file generated by vitepress and replace it with the jinja2 marker.

Additional context

The release notes for some project are generated at release time by tools like https://github.com/twisted/towncrier and these tools use a Jinja2 template to generate the final HTML.

What I am looking here is to have vitepress generate the Jinja2 template and then towncrier generate the final HTML.

vitepress knows about the top navigation and other links

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions