Skip to content

Commit fbf874b

Browse files
Update doc anchors to be uniform (#62)
1 parent 4111293 commit fbf874b

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

.github/workflows/pages.yml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
steps:
2626
- name: Checkout
2727
uses: actions/checkout@v4
28-
28+
2929
- name: Setup .NET Core SDK
3030
uses: actions/setup-dotnet@v4
3131
with:
@@ -68,34 +68,56 @@ jobs:
6868
shell: pwsh
6969
run: .\docfx\docfx.exe docfx.json
7070

71-
- name: Inject canonical link into every index.html
71+
- name: Inject canonicals & fix index.html anchors
7272
shell: pwsh
7373
run: |
74-
$Origin = 'https://docs.richardson.dev'
74+
$Origin = 'https://docs.richardson.dev/AggregateConfigBuildTask'
7575
$SiteRoot = Resolve-Path _site
76+
77+
# Add canonical to every generated index.html
7678
Get-ChildItem $SiteRoot -Recurse -Filter index.html | ForEach-Object {
77-
$rel = ($_.FullName.Substring($SiteRoot.Path.Length) -replace '\\','/')
79+
$rel = ($_.FullName.Substring($SiteRoot.Path.Length) -replace '\\','/')
7880
$canon = $Origin + ($rel -replace 'index\.html$','')
81+
7982
(Get-Content $_.FullName -Raw) -replace '</head>', (
8083
"<link rel=`"canonical`" href=`"$canon`" />`n</head>"
8184
) | Set-Content $_.FullName
8285
}
8386
87+
# Replace anchor HREFs ending in "/index.html" (with or without fragment)
88+
Get-ChildItem $SiteRoot -Recurse -Filter *.html | ForEach-Object {
89+
(Get-Content $_.FullName -Raw) `
90+
-replace '(href=`"[^`"]*?)index\.html(?=[#`"])', '$1' `
91+
-replace '(href=`"[^`"]*?)index\.html`"', '$1`"' |
92+
Set-Content $_.FullName
93+
}
94+
8495
- name: Install html-minifier-terser
8596
run: npm install -g html-minifier-terser
8697

8798
- name: Minify HTML output
8899
shell: pwsh
89100
run: |
90101
html-minifier-terser `
91-
--input-dir _site `
102+
--input-dir _site `
92103
--output-dir _site `
93-
--file-ext html `
104+
--file-ext html `
94105
--collapse-whitespace `
106+
--collapse-boolean-attributes `
95107
--remove-comments `
96108
--remove-optional-tags `
109+
--remove-redundant-attributes `
110+
--remove-script-type-attributes `
111+
--remove-style-link-type-attributes `
112+
--remove-attribute-quotes `
113+
--use-short-doctype `
97114
--minify-css true `
98-
--minify-js true
115+
--minify-js true `
116+
--minify-urls true `
117+
--sort-attributes true `
118+
--sort-class-name true `
119+
--decode-entities true `
120+
--verbose
99121
100122
- name: Upload artifact
101123
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)