fix: add default canonical links to pages (#458)

* Remove non functioning canonical plugin

* Add custom plugin to add the canonical tag to blog posts

* refactor: simplify canonical plugin for all cases

* pass in CANONICAL_BASE as option to plugin

* Remove empty page

* Add a trailing slash to canonical url if not present

* match zero or more trailing slashes

* up comment

Co-authored-by: Daniel N <2color@users.noreply.github.com>
Co-authored-by: Chris Waring <106938+cwaring@users.noreply.github.com>
This commit is contained in:
Daniel Norman
2022-08-25 19:20:39 +02:00
committed by GitHub
parent 794f0d2ccd
commit 062afac2b1
5 changed files with 17 additions and 34 deletions
+4 -15
View File
@@ -38,8 +38,7 @@ const themeConfigDefaults = {
},
{
text: 'Security',
link:
'https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#security-issues',
link: 'https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#security-issues',
},
],
footerLegal: '',
@@ -106,13 +105,11 @@ module.exports = {
{ text: 'Press', link: 'https://ipfs.tech/media/' },
{
text: 'Code of conduct',
link:
'https://github.com/ipfs/community/blob/master/code-of-conduct.md',
link: 'https://github.com/ipfs/community/blob/master/code-of-conduct.md',
},
{
text: 'Security',
link:
'https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#security-issues',
link: 'https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#security-issues',
},
],
headerLinks: [
@@ -145,16 +142,8 @@ module.exports = {
notFoundPath: '/ipfs-404.html',
},
],
[
'vuepress-plugin-canonical',
CANONICAL_BASE
? {
baseURL: CANONICAL_BASE,
stringExtension: true,
}
: false,
],
[require('./plugins/pageData')],
[require('./plugins/canonical'), { CANONICAL_BASE }],
[require('./plugins/vuepress-plugin-trigger-scroll')],
[
'@vuepress/blog',
+13
View File
@@ -0,0 +1,13 @@
// 👇 ensure one trailing slash is present
const normalizePath = (path) => path.replace('/_blog', '').replace(/\/*$/, '/')
module.exports = ({ CANONICAL_BASE } = {}) => ({
name: 'vuepress-default-canonical',
extendPageData({ frontmatter, path }) {
// If no canonicalUrl is explicitly defined in the frontmatter, construct it from the permaLink or $page.path
if (!frontmatter.canonicalUrl && CANONICAL_BASE) {
frontmatter.canonicalUrl =
CANONICAL_BASE + normalizePath(frontmatter.permalink || path || '')
}
},
})
-5
View File
@@ -1,5 +0,0 @@
# Hello World
Welcome to the VuePress website starter kit
{{ $site }}