Add icon for external links in docs toc (#63) #60
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy content to Pages | |
on: | |
push: | |
branches: ["main"] | |
workflow_dispatch: | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
jobs: | |
deploy: | |
environment: | |
name: github-pages | |
#url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: windows-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '9.0.x' | |
dotnet-quality: 'preview' | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
- name: Download DocFX | |
shell: pwsh | |
run: | | |
Invoke-WebRequest -Uri https://github.com/dotnet/docfx/releases/download/v2.77.0/docfx-win-x64-v2.77.0.zip -OutFile docfx.zip | |
- name: Extract DocFX | |
shell: pwsh | |
run: | | |
Expand-Archive -Path docfx.zip -DestinationPath ./docfx | |
- name: Download material.zip | |
shell: pwsh | |
run: | | |
Invoke-WebRequest -Uri https://github.com/ovasquez/docfx-material/releases/download/1.0.0/material.zip -OutFile material.zip | |
- name: Extract material.zip | |
shell: pwsh | |
run: | | |
Expand-Archive -Path material.zip -DestinationPath ./ | |
- name: Add header to README.md | |
shell: pwsh | |
run: | | |
Add-Content -Path temp.md -Value "---" | |
Add-Content -Path temp.md -Value "outputFileName: index.html" | |
Add-Content -Path temp.md -Value "---" | |
Get-Content -Path README.md | Add-Content -Path temp.md | |
Move-Item -Path temp.md -Destination README.md -Force | |
- name: Build documentation | |
shell: pwsh | |
run: .\docfx\docfx.exe docfx.json | |
- name: Inject canonicals & fix index.html anchors | |
shell: pwsh | |
run: | | |
$Origin = 'https://docs.richardson.dev/AggregateConfigBuildTask' | |
$SiteRoot = Resolve-Path _site | |
# Add canonical to every generated index.html | |
Get-ChildItem $SiteRoot -Recurse -Filter index.html | ForEach-Object { | |
$rel = ($_.FullName.Substring($SiteRoot.Path.Length) -replace '\\','/') | |
$canon = $Origin + ($rel -replace 'index\.html$','') | |
(Get-Content $_.FullName -Raw) -replace '</head>', ( | |
"<link rel=`"canonical`" href=`"$canon`" />`n</head>" | |
) | Set-Content $_.FullName | |
} | |
# Replace anchor HREFs ending in "/index.html" (with or without fragment) | |
Get-ChildItem $SiteRoot -Recurse -Filter *.html | ForEach-Object { | |
(Get-Content $_.FullName -Raw) ` | |
-replace '(href=`"[^`"]*?)index\.html(?=[#`"])', '$1' ` | |
-replace '(href=`"[^`"]*?)index\.html`"', '$1`"' | | |
Set-Content $_.FullName | |
} | |
- name: Install html-minifier-terser | |
run: npm install -g html-minifier-terser | |
- name: Minify HTML output | |
shell: pwsh | |
run: | | |
html-minifier-terser ` | |
--input-dir _site ` | |
--output-dir _site ` | |
--file-ext html ` | |
--collapse-whitespace ` | |
--collapse-boolean-attributes ` | |
--remove-comments ` | |
--remove-optional-tags ` | |
--remove-redundant-attributes ` | |
--remove-script-type-attributes ` | |
--remove-style-link-type-attributes ` | |
--remove-attribute-quotes ` | |
--use-short-doctype ` | |
--minify-css true ` | |
--minify-js true ` | |
--minify-urls true ` | |
--sort-attributes true ` | |
--sort-class-name true ` | |
--decode-entities true ` | |
--verbose | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Documentation | |
path: | | |
./_site | |
- name: Upload to Pages | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: '_site/' | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |