Add canonical tags to docs for Google search crawler (#61) #58
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 canonical link into every index.html | |
| shell: pwsh | |
| run: | | |
| $Origin = 'https://docs.richardson.dev' | |
| $SiteRoot = Resolve-Path _site | |
| 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 | |
| } | |
| - 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 ` | |
| --remove-comments ` | |
| --remove-optional-tags ` | |
| --minify-css true ` | |
| --minify-js true | |
| - 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 |