Skip to content

override head tags on indivisual page #975

Closed
@sapphi-red

Description

@sapphi-red

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

Vite sets OGP tags globally by .vitepress/config.ts.

But we want to override OGP tags for some indivisual pages (for example, Vite 3 release post).
Now we set those by frontmatter and actually seems to work.
Though the tags are duplicated like this:

  <meta property="og:type" content="website">
  <meta property="og:title" content="Vite">
  <meta property="og:image" content="https://vitejs.dev/og-image.png">
  <meta property="og:url" content="https://vitejs.dev">
  <meta property="twitter:description" content="Next Generation Frontend Tooling">
  <meta property="twitter:title" content="Vite">
  <meta property="twitter:card" content="summary_large_image">
  <meta property="twitter:image" content="https://vitejs.dev/og-image.png">
  <meta property="twitter:url" content="https://vitejs.dev">
  <script>(()=>{const e=localStorage.getItem("vitepress-theme-appearance"),a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
  <meta name="og:type" content="website">
  <meta name="og:title" content="Announcing Vite 3">
  <meta name="og:image" content="https://vitejs.dev/og-image-announcing-vite3.png">
  <meta name="og:url" content="https://vitejs.dev/blog/announcing-vite3">
  <meta name="twitter:description" content="Vite 3 Release Announcement">
  <meta name="twitter:title" content="Announcing Vite 3">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:image" content="https://vitejs.dev/og-image-announcing-vite3.png">
  <meta name="twitter:url" content="https://vitejs.dev/blog/announcing-vite3">

The OGP spec does not mention anything when a multiple tags existed. So I think this behavior is implementation dependent.

Describe the solution you'd like

Give a way to declare that a head tag should only exist once on config.

But we need to consider what tags should be treated as same. For example, <meta property="og:title" content="foo" > and <meta property="og:title" content="bar" > are same, when tag name and the value of property attribute is same.

Describe alternatives you've considered

Give a way to declare that a head tag should override it on frontmatter.

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions