Skip to content

Commit 4111293

Browse files
Add canonical tags to docs for Google search crawler (#61)
Warning from Google: `Page is not indexed: Duplicate without user-selected canonical` due to `/index.html` and `/` hosting the same content.
1 parent b4dc815 commit 4111293

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

.github/workflows/pages.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,35 @@ jobs:
6868
shell: pwsh
6969
run: .\docfx\docfx.exe docfx.json
7070

71+
- name: Inject canonical link into every index.html
72+
shell: pwsh
73+
run: |
74+
$Origin = 'https://docs.richardson.dev'
75+
$SiteRoot = Resolve-Path _site
76+
Get-ChildItem $SiteRoot -Recurse -Filter index.html | ForEach-Object {
77+
$rel = ($_.FullName.Substring($SiteRoot.Path.Length) -replace '\\','/')
78+
$canon = $Origin + ($rel -replace 'index\.html$','')
79+
(Get-Content $_.FullName -Raw) -replace '</head>', (
80+
"<link rel=`"canonical`" href=`"$canon`" />`n</head>"
81+
) | Set-Content $_.FullName
82+
}
83+
84+
- name: Install html-minifier-terser
85+
run: npm install -g html-minifier-terser
86+
87+
- name: Minify HTML output
88+
shell: pwsh
89+
run: |
90+
html-minifier-terser `
91+
--input-dir _site `
92+
--output-dir _site `
93+
--file-ext html `
94+
--collapse-whitespace `
95+
--remove-comments `
96+
--remove-optional-tags `
97+
--minify-css true `
98+
--minify-js true
99+
71100
- name: Upload artifact
72101
uses: actions/upload-artifact@v4
73102
with:

0 commit comments

Comments
 (0)