From b8f3536104bdca26ccceee59b053ebe052760e65 Mon Sep 17 00:00:00 2001 From: Filipe Casal Date: Wed, 18 Dec 2024 10:53:26 +0000 Subject: [PATCH] Update theme for compatibility with new hugo. Update deployment action --- .github/workflows/gh-pages.yml | 92 ++++++++++++++----- themes/book/layouts/404.html | 2 +- themes/book/layouts/partials/docs/brand.html | 2 +- .../book/layouts/partials/docs/html-head.html | 5 +- themes/book/layouts/partials/docs/menu.html | 2 +- 5 files changed, 72 insertions(+), 31 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index d2aefc6..f9058de 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -1,35 +1,77 @@ -name: github pages +name: Deploy Hugo site to Pages on: + # Runs on pushes targeting the default branch push: branches: - - main # Set a branch to deploy + - main -jobs: - deploy: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - with: - submodules: true # Fetch Hugo themes (true OR recursive) - fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: - - name: Setup Hugo - uses: peaceiris/actions-hugo@v2 - with: - hugo-version: 'latest' - extended: true +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false - - name: Build - run: hugo --minify --buildDrafts=false +# Default to bash +defaults: + run: + shell: bash - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - if: github.ref == 'refs/heads/main' +jobs: + # Build job + build: + runs-on: ubuntu-latest + env: + HUGO_VERSION: 0.137.1 + steps: + - name: Install Hugo CLI + run: | + wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ + && sudo dpkg -i ${{ runner.temp }}/hugo.deb + - name: Install Dart Sass + run: sudo snap install dart-sass + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + persist-credentials: false + - name: Setup Pages + id: pages + uses: actions/configure-pages@v5 + - name: Install Node.js dependencies + run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" + - name: Build with Hugo + env: + HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache + HUGO_ENVIRONMENT: production + run: | + hugo \ + --gc \ + --minify \ + --baseURL "${{ steps.pages.outputs.base_url }}/" + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - cname: www.zkdocs.com - publish_dir: ./public + path: ./public -permissions: - contents: write \ No newline at end of file + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/themes/book/layouts/404.html b/themes/book/layouts/404.html index 3f76ed4..60dcdc6 100644 --- a/themes/book/layouts/404.html +++ b/themes/book/layouts/404.html @@ -29,7 +29,7 @@

{{ partial "docs/inject/body" . }} - {{ template "_internal/google_analytics_async.html" . }} + {{ template "_internal/google_analytics.html" . }} diff --git a/themes/book/layouts/partials/docs/brand.html b/themes/book/layouts/partials/docs/brand.html index ebb62d6..188632a 100644 --- a/themes/book/layouts/partials/docs/brand.html +++ b/themes/book/layouts/partials/docs/brand.html @@ -1,6 +1,6 @@

+ href="{{ cond (not .Site.Home.File) .Sites.Default.Home.RelPermalink .Site.Home.RelPermalink }}"> {{- with .Site.Params.BookLogo -}} Logo {{- end -}} diff --git a/themes/book/layouts/partials/docs/html-head.html b/themes/book/layouts/partials/docs/html-head.html index 333a885..103f05e 100644 --- a/themes/book/layouts/partials/docs/html-head.html +++ b/themes/book/layouts/partials/docs/html-head.html @@ -17,7 +17,7 @@ {{- end -}} -{{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | resources.ToCSS | resources.Minify | resources.Fingerprint }} +{{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | css.Sass | resources.Minify | resources.Fingerprint }} {{- if default true .Site.Params.BookSearch -}} @@ -32,8 +32,7 @@ {{ end -}} -{{- template "_internal/google_analytics_async.html" . -}} - +{{ template "_internal/google_analytics.html" . }} {{- with .OutputFormats.Get "rss" -}} {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} diff --git a/themes/book/layouts/partials/docs/menu.html b/themes/book/layouts/partials/docs/menu.html index d7ed940..8453e73 100644 --- a/themes/book/layouts/partials/docs/menu.html +++ b/themes/book/layouts/partials/docs/menu.html @@ -1,7 +1,7 @@