Skip to content

Commit cac1fe1

Browse files
EugeneHlushkomontogeek
authored andcommitted
misc(seo) add canonical to the pages html, use trailing slash for con… (#2999)
* misc(seo) add canonical to the pages html, use trailing slash for consistency with github pages * misc(seo) fix sitemap to not mention index.html for each page
1 parent cea1b0c commit cac1fe1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"lint:prose": "cp .proselintrc ~/ && proselint src/content",
4646
"lint:links": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ -i --todo https://img.shields.io --todo https://codecov.io/gh --todo 'content-type-mismatch https://travis-ci.org' --todo 'Asset is used as both Html and Image' | tee internal-links.tap | tap-spot",
4747
"linkcheck": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ --skip support__ --skip sidecar.gitter.im --skip vimdoc.sourceforge.net --skip img.shields.io --skip npmjs.com/package/ --skip opencollective.com/webpack --todo external-redirect | tee external-links.tap | tap-spot",
48-
"sitemap": "cd dist && sitemap-static --prefix=https://webpack.js.org/ > sitemap.xml",
48+
"sitemap": "cd dist && sitemap-static --pretty --prefix=https://webpack.js.org/ > sitemap.xml",
4949
"serve": "npm run build && sirv start ./dist --port 4000",
5050
"deploy": "gh-pages -d dist"
5151
},

src/server.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const bundles = [
2020
'/index.bundle.js'
2121
];
2222

23+
// As github pages uses trailing slash, we need to provide it to canonicals for consistency
24+
// between canonical href and final url served by github pages.
25+
function enforceTrailingSlash (url) {
26+
return url.replace(/\/?$/, '/');
27+
}
28+
2329
// Export method for `SSGPlugin`
2430
export default locals => {
2531
let { assets } = locals.webpackStats.compilation;
@@ -49,6 +55,7 @@ export default locals => {
4955
<link key={ path } rel="stylesheet" href={ `/${path}` } />
5056
))}
5157
<link rel="manifest" href="/manifest.json" />
58+
<link rel="canonical" href={enforceTrailingSlash(locals.path)} />
5259
</head>
5360
<body>
5461
<div id="root">

0 commit comments

Comments
 (0)