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

override head tags on indivisual page #975

Closed
4 tasks done
sapphi-red opened this issue Jul 13, 2022 · 4 comments · Fixed by #976
Closed
4 tasks done

override head tags on indivisual page #975

sapphi-red opened this issue Jul 13, 2022 · 4 comments · Fixed by #976
Labels
bug Something isn't working

Comments

@sapphi-red
Copy link
Contributor

sapphi-red commented Jul 13, 2022

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

@sapphi-red sapphi-red changed the title override head on indivisual page override head tags on indivisual page Jul 13, 2022
@brc-dd brc-dd added the bug Something isn't working label Jul 13, 2022
@brc-dd
Copy link
Member

brc-dd commented Jul 13, 2022

Added a de-duplication strategy in #976.

But we need to consider what tags should be treated as same.

Took this from 0.x code. We had a hasTag function there (removed during cleanup - #725). It basically checks your first attribute.

As for the feature request part, we are tracking it at #551. (#588 is a possible implementation, it needs rewrite though.)

@sapphi-red
Copy link
Contributor Author

@brc-dd Thank you for the quick fix!
But I'm afraid it will cause bugs IIUC. For example, if someone uses <script type='module'>, it will be deduped.
To be safe, IMO it is better to limit this behavior to <meta> tag.

@brc-dd
Copy link
Member

brc-dd commented Jul 13, 2022

Limited it to meta for now. But we could make it run for all tags. People just will have to add an id attribute (similar to how Next.js needs id for script optimization). It would enable overrides like if someone wants to override scripts/styles for certain pages. For now lets leave this. Might consider it later. Although supporting a transform function for head in themeConfig would eliminate need for such stuff.

@sapphi-red
Copy link
Contributor Author

Sounds good to me 👍 Thank you again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants