Skip to content

Commit

Permalink
Update theme for compatibility with new hugo. Update deployment action
Browse files Browse the repository at this point in the history
  • Loading branch information
fcasal committed Dec 18, 2024
1 parent d91ba19 commit b8f3536
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 31 deletions.
92 changes: 67 additions & 25 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -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
# 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
2 changes: 1 addition & 1 deletion themes/book/layouts/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h3>
</main>

{{ partial "docs/inject/body" . }}
{{ template "_internal/google_analytics_async.html" . }}
{{ template "_internal/google_analytics.html" . }}
</body>

</html>
2 changes: 1 addition & 1 deletion themes/book/layouts/partials/docs/brand.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2 class="book-brand">
<a class="align-center"
href="{{ cond (not .Site.Home.File) .Sites.First.Home.RelPermalink .Site.Home.RelPermalink }}">
href="{{ cond (not .Site.Home.File) .Sites.Default.Home.RelPermalink .Site.Home.RelPermalink }}">
{{- with .Site.Params.BookLogo -}}
<img id="icon" src="{{ . | relURL }}" alt="Logo" />
{{- end -}}
Expand Down
5 changes: 2 additions & 3 deletions themes/book/layouts/partials/docs/html-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{- end -}}

<!-- Theme stylesheet, you can customize scss by creating `assets/custom.scss` in your website -->
{{- $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 }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" {{ template "integrity" $styles }}>

{{- if default true .Site.Params.BookSearch -}}
Expand All @@ -32,8 +32,7 @@
<script defer src="{{ $swJS.RelPermalink }}" {{ template "integrity" $swJS }}></script>
{{ end -}}

{{- template "_internal/google_analytics_async.html" . -}}

{{ template "_internal/google_analytics.html" . }}
<!-- RSS -->
{{- with .OutputFormats.Get "rss" -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
Expand Down
2 changes: 1 addition & 1 deletion themes/book/layouts/partials/docs/menu.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav>
{{ partial "docs/brand" . }}
{{ partial "docs/search" . }}
{{ if .Site.IsMultiLingual }}
{{ if hugo.IsMultilingual }}
{{ partial "docs/languages" . }}
{{ end }}

Expand Down

0 comments on commit b8f3536

Please sign in to comment.