From 41c2d3a38e77b5a0db8ff9d8d3f49730355f554c Mon Sep 17 00:00:00 2001 From: Dillon Date: Mon, 16 Mar 2020 21:35:16 +0800 Subject: [PATCH] feat: add detection of the theme version and Hugo version (#173) * feat: add detection of the theme version and Hugo version * fix: hugo.IsProduction is incompatible in Hugo v0.62.0 --- assets/css/_page/_single.scss | 10 ++++++++++ assets/css/_variables.scss | 4 ++++ exampleSite/config.toml | 6 +++++- .../posts/theme-documentation-basics.en.md | 6 +++--- .../posts/theme-documentation-basics.fr.md | 6 +++--- .../posts/theme-documentation-basics.zh-cn.md | 6 +++--- .../posts/theme-documentation-content.en.md | 2 +- .../posts/theme-documentation-content.fr.md | 2 +- .../posts/theme-documentation-content.zh-cn.md | 2 +- layouts/_default/baseof.html | 16 ++++++++++------ layouts/partials/assets.html | 2 +- layouts/partials/comment.html | 2 +- layouts/partials/footer.html | 5 ++++- layouts/partials/head/meta.html | 1 + layouts/posts/single.html | 2 +- layouts/shortcodes/version.html | 1 + package-lock.json | 2 +- package.json | 2 +- ...css_90197bdac482216ecaaaae0fb88517c1.content} | 2 +- ...e.scss_90197bdac482216ecaaaae0fb88517c1.json} | 0 20 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 layouts/shortcodes/version.html rename resources/_gen/assets/scss/css/{style.template.scss_b8ba9a60a151126bfcde1421dc0b972d.content => style.template.scss_90197bdac482216ecaaaae0fb88517c1.content} (70%) rename resources/_gen/assets/scss/css/{style.template.scss_b8ba9a60a151126bfcde1421dc0b972d.json => style.template.scss_90197bdac482216ecaaaae0fb88517c1.json} (100%) diff --git a/assets/css/_page/_single.scss b/assets/css/_page/_single.scss index fa588f87..ff554cd7 100644 --- a/assets/css/_page/_single.scss +++ b/assets/css/_page/_single.scss @@ -314,6 +314,16 @@ word-break: break-all; } } + + .version { + font-weight: bold; + font-style: normal; + color: $global-highlight-color; + + .dark-theme & { + color: $global-highlight-color-dark; + } + } } @import "../_partial/_single/footer"; diff --git a/assets/css/_variables.scss b/assets/css/_variables.scss index 2bfe3033..980949fd 100644 --- a/assets/css/_variables.scss +++ b/assets/css/_variables.scss @@ -32,6 +32,10 @@ $global-link-hover-color-dark: #fff !default; // Color of the border $global-border-color: #dcdcdc !default; $global-border-color-dark: #4a4b50 !default; + +// Color of the highlight +$global-highlight-color: #df1a08 !default; +$global-highlight-color-dark: #fff !default; // ========== Global ========== // // ========== Scrollbar ========== // diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 6e6c5f02..43b67f45 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -216,10 +216,12 @@ enableEmoji = true enable = true # Disqus Comment Config (https://disqus.com/) [languages.en.params.comment.disqus] + enable = false # Disqus shortname to use Disqus in posts shortname = "" # Gitalk Comment Config (https://github.com/gitalk/gitalk) [languages.en.params.comment.gitalk] + enable = false owner = "" repo = "" clientId = "" @@ -436,10 +438,12 @@ enableEmoji = true enable = true # Disqus 评论系统设置 (https://disqus.com/) [languages.zh-cn.params.comment.disqus] + enable = false # Disqus 的 shortname,用来在文章中启用 Disqus 评论系统 shortname = "" # Gitalk 评论系统设置 (https://github.com/gitalk/gitalk) [languages.zh-cn.params.comment.gitalk] + enable = false owner = "" repo = "" clientId = "" @@ -691,7 +695,7 @@ enableEmoji = true [params] # LoveIt theme version # LoveIt 主题版本 - version = "0.1.X" + version = "0.2.X" # public git repo url only then enableGitInfo is true # 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效 gitRepo = "https://github.com/dillonzq/LoveIt" diff --git a/exampleSite/content/posts/theme-documentation-basics.en.md b/exampleSite/content/posts/theme-documentation-basics.en.md index 4616aacc..e42e702a 100644 --- a/exampleSite/content/posts/theme-documentation-basics.en.md +++ b/exampleSite/content/posts/theme-documentation-basics.en.md @@ -189,7 +189,7 @@ Note that some of these parameters are explained in details in other sections of defaultTheme = "auto" # public git repo url only then enableGitInfo is true gitRepo = "" - # LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 + # {{< version 0.1.1 >}} # which hash function used for SRI, when empty, no SRI is used ("sha256", "sha384", "sha512", "md5") fingerprint = "" # Header info @@ -349,13 +349,13 @@ Note that some of these parameters are explained in details in other sections of enable = true # Disqus Comment Config (https://disqus.com/) [params.comment.disqus] - # LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 + # {{< version 0.1.1 >}} enable = false # Disqus shortname to use Disqus in posts shortname = "" # Gitalk Comment Config (https://github.com/gitalk/gitalk) [params.comment.gitalk] - # LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 + # {{< version 0.1.1 >}} enable = false owner = "" repo = "" diff --git a/exampleSite/content/posts/theme-documentation-basics.fr.md b/exampleSite/content/posts/theme-documentation-basics.fr.md index ddbbd647..13fda298 100644 --- a/exampleSite/content/posts/theme-documentation-basics.fr.md +++ b/exampleSite/content/posts/theme-documentation-basics.fr.md @@ -189,7 +189,7 @@ Note that some of these parameters are explained in details in other sections of defaultTheme = "auto" # public git repo url only then enableGitInfo is true gitRepo = "" - # LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 + # {{< version 0.1.1 >}} # which hash function used for SRI, when empty, no SRI is used ("sha256", "sha384", "sha512", "md5") fingerprint = "" # Header info @@ -349,13 +349,13 @@ Note that some of these parameters are explained in details in other sections of enable = true # Disqus Comment Config (https://disqus.com/) [params.comment.disqus] - # LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 + # {{< version 0.1.1 >}} enable = false # Disqus shortname to use Disqus in posts shortname = "" # Gitalk Comment Config (https://github.com/gitalk/gitalk) [params.comment.gitalk] - # LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 + # {{< version 0.1.1 >}} enable = false owner = "" repo = "" diff --git a/exampleSite/content/posts/theme-documentation-basics.zh-cn.md b/exampleSite/content/posts/theme-documentation-basics.zh-cn.md index c540f021..e98be8b2 100644 --- a/exampleSite/content/posts/theme-documentation-basics.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-basics.zh-cn.md @@ -192,7 +192,7 @@ hugo defaultTheme = "auto" # 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效 gitRepo = "" - # LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 + # {{< version 0.1.1 >}} # 哪种哈希函数用来 SRI, 为空时表示不使用 SRI ("sha256", "sha384", "sha512", "md5") fingerprint = "" # 页面头部导航栏信息 @@ -351,13 +351,13 @@ hugo enable = true # Disqus 评论系统设置 (https://disqus.com/) [params.comment.disqus] - # LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 + # {{< version 0.1.1 >}} enable = false # Disqus 的 shortname,用来在文章中启用 Disqus 评论系统 shortname = "" # Gitalk 评论系统设置 (https://github.com/gitalk/gitalk) [params.comment.gitalk] - # LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 + # {{< version 0.1.1 >}} enable = false owner = "" repo = "" diff --git a/exampleSite/content/posts/theme-documentation-content.en.md b/exampleSite/content/posts/theme-documentation-content.en.md index 4ba405b1..aaed2c48 100644 --- a/exampleSite/content/posts/theme-documentation-content.en.md +++ b/exampleSite/content/posts/theme-documentation-content.en.md @@ -76,7 +76,7 @@ comment: true ``` * **title**: the title for the content. -* **subtitle**: the subtitle for the content. **LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.2.0** +* **subtitle**: the subtitle for the content. {{< version 0.2.0 >}} * **date**: the datetime assigned to this page, which is usually fetched from the `date` field in front matter, but this behaviour is configurabl in the [site configuration](../theme-documentation-basics/#site-configuration). * **lastmod**: the datetime at which the content was last modified. * **draft**: if `true`, the content will not be rendered unless the `--buildDrafts`/`-D` flag is passed to the `hugo` command. diff --git a/exampleSite/content/posts/theme-documentation-content.fr.md b/exampleSite/content/posts/theme-documentation-content.fr.md index 2724f864..149499b0 100644 --- a/exampleSite/content/posts/theme-documentation-content.fr.md +++ b/exampleSite/content/posts/theme-documentation-content.fr.md @@ -76,7 +76,7 @@ comment: true ``` * **title**: the title for the content. -* **subtitle**: the subtitle for the content. **LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.2.0** +* **subtitle**: the subtitle for the content. **{{< version 0.2.0 >}}** * **date**: the datetime assigned to this page, which is usually fetched from the `date` field in front matter, but this behaviour is configurabl in the [site configuration](../theme-documentation-basics/#site-configuration). * **lastmod**: the datetime at which the content was last modified. * **draft**: if `true`, the content will not be rendered unless the `--buildDrafts`/`-D` flag is passed to the `hugo` command. diff --git a/exampleSite/content/posts/theme-documentation-content.zh-cn.md b/exampleSite/content/posts/theme-documentation-content.zh-cn.md index 093e7077..2e3de1cc 100644 --- a/exampleSite/content/posts/theme-documentation-content.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-content.zh-cn.md @@ -76,7 +76,7 @@ comment: true ``` * **title**: 文章标题. -* **subtitle**: 文章副标题. **LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.2.0** +* **subtitle**: 文章副标题. **{{< version 0.2.0 >}}** * **date**: 这篇文章创建的日期时间. 它通常是从文章的前置参数中的 `date` 字段获取的, 但是也可以在 [网站配置](../theme-documentation-basics/#site-configuration) 中设置. * **lastmod**: 上次修改内容的日期时间. * **draft**: 如果设为 `true`, 除非 `hugo` 命令使用了 `--buildDrafts`/`-D` 参数, 这篇文章不会被渲染. diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index d40eaf9f..9a50e837 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,16 +1,20 @@ -{{- /* LoveIt theme version detection */ -}} -{{- if ne .Site.Params.version "0.1.X" -}} - {{- errorf "\n\nThere are two possible situations that led to this error:\n 1. You haven't copied the config.toml yet. See https://github.com/dillonzq/LoveIt#installation \n 2. You have an incompatible update. See https://github.com//dillonzq/LoveIt/blob/master/CHANGELOG.md \n\n有两种可能的情况会导致这个错误发生:\n 1. 你还没有复制 config.toml 参考 https://github.com/dillonzq/LoveIt#installation \n 2. 你进行了一次不兼容的更新 参考 https://github.com//dillonzq/LoveIt/blob/master/CHANGELOG.md \n" -}} -{{- end -}} - {{- $scratch := newScratch -}} {{- .Scratch.Set "scratch" $scratch -}} {{- if eq hugo.Environment "production" -}} - {{- $scratch.Set "production" true -}} {{- $scratch.Set "CDN" .Site.Params.cdn -}} {{- $scratch.Set "fingerprint" .Site.Params.fingerprint -}} {{- end -}} +{{- $scratch.Set "major-version" "0.2.X" -}} +{{- $scratch.Set "version" "0.2.0" -}} + +{{- /* LoveIt theme version detection */ -}} +{{- if not .Site.Params.version -}} + {{- errorf "\n\nYou haven't configured the LoveIt version param correctly yet. See https://hugoloveit.com/theme-documentation-basics/#basic-configuration \n你还没有正确配置 LoveIt 的版本参数 参考 https://hugoloveit.com/zh-cn/theme-documentation-basics/#basic-configuration \n" -}} +{{- else if ne .Site.Params.version ($scratch.Get "major-version") -}} + {{- errorf (printf "\n\n%s -> %s:\nYou have an incompatible update. See https://github.com/dillonzq/LoveIt/releases \n你进行了一次不兼容的更新 参考 https://github.com/dillonzq/LoveIt/releases \n" .Site.Params.version ($scratch.Get "major-version")) -}} +{{- end -}} + diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index a7c39b4d..4beb7f2c 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -243,6 +243,6 @@ {{- end -}} {{- /* Google analytics async */ -}} -{{- if $scratch.Get "production" | and .Site.GoogleAnalytics -}} +{{- if eq hugo.Environment "production" | and .Site.GoogleAnalytics -}} {{- template "_internal/google_analytics_async.html" . -}} {{- end -}} diff --git a/layouts/partials/comment.html b/layouts/partials/comment.html index 0c9d64ef..262d3403 100644 --- a/layouts/partials/comment.html +++ b/layouts/partials/comment.html @@ -1,6 +1,6 @@ {{- $scratch := .Scratch.Get "scratch" -}} -{{- if $scratch.Get "production" | and (ne .Site.Params.comment.enable false) | and (ne .Params.comment false) -}} +{{- if eq hugo.Environment "production" | and (ne .Site.Params.comment.enable false) | and (ne .Params.comment false) -}} {{- $CDN := $scratch.Get "CDN" -}} {{- /* Disqus Comment System */ -}} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index d6c72e40..f3489d89 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,8 +1,11 @@ +{{- $scratch := .Scratch.Get "scratch" -}} +