mirror of
https://github.com/ipfs/ipfs-blog.git
synced 2026-07-13 21:31:16 +02:00
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:
+4
-15
@@ -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',
|
||||
|
||||
@@ -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 || '')
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -1,5 +0,0 @@
|
||||
# Hello World
|
||||
|
||||
Welcome to the VuePress website starter kit
|
||||
|
||||
{{ $site }}
|
||||
Reference in New Issue
Block a user