From 86f1b1987c68ebe429be3e9e801af6dbb98d2d0c Mon Sep 17 00:00:00 2001 From: Vimux Date: Tue, 20 Aug 2024 12:00:03 -0400 Subject: [PATCH] BREAKING CHANGE: fix Hugo's .Site.IsServer error (#375) As of Hugo 0.120.0, `.Site.IsServer` is deprecated, and starting with Hugo 0.132.0, it causes a build error. Unfortunately, this is a breaking upstream change that we can't "fix" on our end. As a result, we had to raise the minimum supported version to v0.54.0 and implement another workaround to ensure compatibility with older versions, not just Hugo v0.120.0 and all subsequent versions. Fix #369 --- .github/workflows/ci-test.yml | 3 ++- CONTRIBUTING.md | 2 +- exampleSite/content/docs/getting-started.md | 2 +- layouts/_default/baseof.html | 8 +++++++- layouts/partials/comments.html | 10 ++++++++-- theme.toml | 2 +- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 5609e81f..59167ce4 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -35,7 +35,7 @@ jobs: strategy: matrix: hugo: - - '0.48' # min version + - '0.54.0' # min version - '0.58.2' # https://github.com/gohugoio/hugoThemes/issues/682 - '0.59.1' # last major version without goldmark renderer - '0.60.1' # first major version with goldmark renderer @@ -44,6 +44,7 @@ jobs: - '0.86.1' # https://github.com/gohugoio/hugo/issues/9150 - '0.93.3' # https://github.com/gohugoio/hugo/commit/837fdfdf45014e3d5ef3b00b01548b68a4489c5f - '0.123.8' # https://github.com/gohugoio/hugo/issues/12080 + - '0.132.2' # .Site.IsServer deprecation ERROR - 'latest' fail-fast: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aab69c8c..4b0bebaa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -100,7 +100,7 @@ to those feedback, otherwise the PR will be closed after 2-4 weeks of inactivity ### Pull Request Contribution Prerequisites * You have Node & npm installed -* You have Hugo installed at v0.48.0+ +* You have Hugo installed at v0.54.0+ * You are familiar with Git ### Pull Request Process diff --git a/exampleSite/content/docs/getting-started.md b/exampleSite/content/docs/getting-started.md index 638383d0..71d71160 100644 --- a/exampleSite/content/docs/getting-started.md +++ b/exampleSite/content/docs/getting-started.md @@ -22,7 +22,7 @@ with the [Hugo](https://gohugo.io/) static site generator. ## Installation Before installing the **Mainroad** theme, make sure that you've -[installed **Hugo** (version 0.48 or later)](https://gohugo.io/getting-started/quick-start/#step-1-install-hugo) and +[installed **Hugo** (version 0.54.0 or later)](https://gohugo.io/getting-started/quick-start/#step-1-install-hugo) and [created a new site](https://gohugo.io/getting-started/quick-start/#step-2-create-a-new-site). To learn how to install Hugo, visit [Hugo Documentation](https://gohugo.io/getting-started/installing/). diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 919f19f9..e31fe1b3 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -35,7 +35,13 @@ {{- end }} - {{- if not .Site.IsServer }} + {{- $server := "" }} + {{- if gt (int (index (split hugo.Version ".") 1)) "120" }} + {{ $server = hugo.IsServer }} + {{- else }} + {{ $server = .Site.IsServer }} + {{- end -}} + {{- if not $server }} {{ template "_internal/google_analytics.html" . }} {{- end }} diff --git a/layouts/partials/comments.html b/layouts/partials/comments.html index 5b15071a..81e59433 100644 --- a/layouts/partials/comments.html +++ b/layouts/partials/comments.html @@ -1,5 +1,11 @@ -{{ if and .Site.Config.Services.Disqus.Shortname (index .Params "comments" | default "true") (not .Site.IsServer) }} +{{- $server := "" }} +{{- if ge (int (index (split hugo.Version ".") 1)) "120" }} + {{- $server = hugo.IsServer }} +{{- else }} + {{- $server = .Site.IsServer }} +{{- end }} +{{- if and .Site.Config.Services.Disqus.Shortname (index .Params "comments" | default "true") (not $server) }}
{{ template "_internal/disqus.html" . }}
-{{ end }} \ No newline at end of file +{{- end }} \ No newline at end of file diff --git a/theme.toml b/theme.toml index 4e5c65ea..047d02ac 100644 --- a/theme.toml +++ b/theme.toml @@ -6,7 +6,7 @@ homepage = "https://github.com/vimux/mainroad/" demosite = "https://mainroad-demo.netlify.app/" tags = ["blog", "responsive", "light", "multilingual", "customizable", "widgets", "wordpress"] features = ["blog", "responsive", "multilingual", "widgets", "rss", "disqus", "google analytics", "wordpress"] -min_version = "0.48" +min_version = "0.54.0" [author] name = "Vimux"