diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9e274964..f0390873 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,7 +20,7 @@ jobs: registry-url: https://registry.npmjs.org/ - name: Deploy to NPM - run: npm run build && npm run bump + run: npm run bump working-directory: web-embeds env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/packages/web-shared/components/ContentSingle.js b/packages/web-shared/components/ContentSingle.js index ef2196c1..3531e359 100644 --- a/packages/web-shared/components/ContentSingle.js +++ b/packages/web-shared/components/ContentSingle.js @@ -124,6 +124,22 @@ function ContentSingle(props = {}) { } }, [invalidPage, navigate]); + // Try and convince Google that this is the canonical URL + const canonicalUrl = `${window.location.origin}/?id=${searchParams.get('id')}`; + + // Some websites have existing canonical links that need to be updated. + useEffect(() => { + const canonicalLink = document.querySelector('link[rel="canonical"]'); + if (canonicalLink) { + const oldValue = canonicalLink.getAttribute('href'); + canonicalLink.setAttribute('href', canonicalUrl); + // Reset when we are done. + return () => { + canonicalLink.setAttribute('href', oldValue); + }; + } + }, []); + if (props.loading || invalidPage) { return ( {/* TODO: Max width set to 750px due to low resolution pictures. Can be increased as higher quality images are used */} diff --git a/web-embeds/package.json b/web-embeds/package.json index 84c084e0..58ab79f9 100644 --- a/web-embeds/package.json +++ b/web-embeds/package.json @@ -60,9 +60,9 @@ "dev": "craco start", "build": "node scripts/build.js", "test": "craco test", - "bump": "./scripts/bump.sh && npm publish && npm version 0.0.1 && npm run flush-cdn", - "bump:minor": "./scripts/bump.sh minor && npm publish && npm version 0.0.1 && npm run flush-cdn", - "bump:major": "./scripts/bump.sh major && npm publish && npm version 0.0.1 && npm run flush-cdn", + "bump": "yarn build && ./scripts/bump.sh && npm publish && npm version 0.0.1 && npm run flush-cdn", + "bump:minor": "yarn build && ./scripts/bump.sh minor && npm publish && npm version 0.0.1 && npm run flush-cdn", + "bump:major": "yarn build && ./scripts/bump.sh major && npm publish && npm version 0.0.1 && npm run flush-cdn", "format": "prettier --write .", "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .", "flush-cdn": "./flush-cdn-cache.sh"