|
25 | 25 | steps:
|
26 | 26 | - name: Checkout
|
27 | 27 | uses: actions/checkout@v4
|
28 |
| - |
| 28 | + |
29 | 29 | - name: Setup .NET Core SDK
|
30 | 30 | uses: actions/setup-dotnet@v4
|
31 | 31 | with:
|
@@ -68,34 +68,56 @@ jobs:
|
68 | 68 | shell: pwsh
|
69 | 69 | run: .\docfx\docfx.exe docfx.json
|
70 | 70 |
|
71 |
| - - name: Inject canonical link into every index.html |
| 71 | + - name: Inject canonicals & fix index.html anchors |
72 | 72 | shell: pwsh
|
73 | 73 | run: |
|
74 |
| - $Origin = 'https://docs.richardson.dev' |
| 74 | + $Origin = 'https://docs.richardson.dev/AggregateConfigBuildTask' |
75 | 75 | $SiteRoot = Resolve-Path _site
|
| 76 | +
|
| 77 | + # Add canonical to every generated index.html |
76 | 78 | 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 '\\','/') |
78 | 80 | $canon = $Origin + ($rel -replace 'index\.html$','')
|
| 81 | +
|
79 | 82 | (Get-Content $_.FullName -Raw) -replace '</head>', (
|
80 | 83 | "<link rel=`"canonical`" href=`"$canon`" />`n</head>"
|
81 | 84 | ) | Set-Content $_.FullName
|
82 | 85 | }
|
83 | 86 |
|
| 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 | +
|
84 | 95 | - name: Install html-minifier-terser
|
85 | 96 | run: npm install -g html-minifier-terser
|
86 | 97 |
|
87 | 98 | - name: Minify HTML output
|
88 | 99 | shell: pwsh
|
89 | 100 | run: |
|
90 | 101 | html-minifier-terser `
|
91 |
| - --input-dir _site ` |
| 102 | + --input-dir _site ` |
92 | 103 | --output-dir _site `
|
93 |
| - --file-ext html ` |
| 104 | + --file-ext html ` |
94 | 105 | --collapse-whitespace `
|
| 106 | + --collapse-boolean-attributes ` |
95 | 107 | --remove-comments `
|
96 | 108 | --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 ` |
97 | 114 | --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 |
99 | 121 |
|
100 | 122 | - name: Upload artifact
|
101 | 123 | uses: actions/upload-artifact@v4
|
|
0 commit comments