-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat($core): add canonical link to frontmatter #2658
feat($core): add canonical link to frontmatter #2658
Conversation
Partial resolution to #2153 |
@d-pollard I can confirm (with your latest addition) that the This should definitely roll out ASAP - you're awesome! |
@d-pollard don't forget: the docs would need to be updated for this PR as well. Now you've got me thinking about injecting structured data in a similar way. It also would need to be updated on each route change. I wonder if I'm the only person that would like a hook in the Options API that would allow for injecting (via const structuredData = {
'@context': 'https://schema.org/',
'@type': 'WebSite',
name: this.meta_data.title + (this.$page.frontmatter.subtitle ? ' | ' + this.$page.frontmatter.subtitle : '') || null,
description: this.meta_data.description || null,
url: frontmatter.canonical,
image: {
'@type': 'ImageObject',
url: this.$site.themeConfig.domain + this.$site.themeConfig.defaultImage,
},
'@id': frontmatter.canonical,
} <script type="application/ld+json">{{ JSON.stringify(structuredData, null, 4) }}</script> I'm currently doing this with a custom component; however, it is technically rendered after the DOM, meaning it isn't available when the page is scraped (before JavaScript is enabled). |
Yeah we could definitely look into a custom hook Typically I write the feature in it's entirety then open another PR with docs code so that if the version changes, the feature code is still introduced and I can update the docs to reflect the proper version |
Like in this case, I have reservations about using just the keyword canonical so will probably change it to be more idiomatic (thinking |
@d-pollard I almost suggested a change regarding the I lean towards Edit: ... and definitely let me know if that custom hook for injecting other content comes about 💯 |
Yeah that makes sense, I'll make the changes probably tomorrow, and then document the feature once it's all merged in. Doing this makes me wonder if I could also use the same pattern to introduce vue-meta in a way that's backwards compatible |
I fibbed; I've updated the PR with the new terms; used |
That all looks good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks epic @d-pollard! Could we just add a small note inside of the docs to surface that this is now available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the collab effort @d-pollard and @adamdehaven!
Summary
What kind of change does this PR introduce? (check at least one)
If changing the UI of default theme, please provide the before/after screenshot:
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
fix #xxx[,#xxx]
, where "xxx" is the issue number)You have tested in the following browsers: (Providing a detailed version will be better.)
If adding a new feature, the PR's description includes:
To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.
Other information:
This feature introduces the ability to specify
canonical
in the frontmatter section on a page:Which will then render the proper head HTML tag, and also keep it updated when the page changes