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
This commit is contained in:
Dillon 2020-03-16 21:35:16 +08:00 committed by GitHub
parent 9a7189c2a3
commit 41c2d3a38e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 53 additions and 26 deletions

View file

@ -314,6 +314,16 @@
word-break: break-all; 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"; @import "../_partial/_single/footer";

View file

@ -32,6 +32,10 @@ $global-link-hover-color-dark: #fff !default;
// Color of the border // Color of the border
$global-border-color: #dcdcdc !default; $global-border-color: #dcdcdc !default;
$global-border-color-dark: #4a4b50 !default; $global-border-color-dark: #4a4b50 !default;
// Color of the highlight
$global-highlight-color: #df1a08 !default;
$global-highlight-color-dark: #fff !default;
// ========== Global ========== // // ========== Global ========== //
// ========== Scrollbar ========== // // ========== Scrollbar ========== //

View file

@ -216,10 +216,12 @@ enableEmoji = true
enable = true enable = true
# Disqus Comment Config (https://disqus.com/) # Disqus Comment Config (https://disqus.com/)
[languages.en.params.comment.disqus] [languages.en.params.comment.disqus]
enable = false
# Disqus shortname to use Disqus in posts # Disqus shortname to use Disqus in posts
shortname = "" shortname = ""
# Gitalk Comment Config (https://github.com/gitalk/gitalk) # Gitalk Comment Config (https://github.com/gitalk/gitalk)
[languages.en.params.comment.gitalk] [languages.en.params.comment.gitalk]
enable = false
owner = "" owner = ""
repo = "" repo = ""
clientId = "" clientId = ""
@ -436,10 +438,12 @@ enableEmoji = true
enable = true enable = true
# Disqus 评论系统设置 (https://disqus.com/) # Disqus 评论系统设置 (https://disqus.com/)
[languages.zh-cn.params.comment.disqus] [languages.zh-cn.params.comment.disqus]
enable = false
# Disqus 的 shortname用来在文章中启用 Disqus 评论系统 # Disqus 的 shortname用来在文章中启用 Disqus 评论系统
shortname = "" shortname = ""
# Gitalk 评论系统设置 (https://github.com/gitalk/gitalk) # Gitalk 评论系统设置 (https://github.com/gitalk/gitalk)
[languages.zh-cn.params.comment.gitalk] [languages.zh-cn.params.comment.gitalk]
enable = false
owner = "" owner = ""
repo = "" repo = ""
clientId = "" clientId = ""
@ -691,7 +695,7 @@ enableEmoji = true
[params] [params]
# LoveIt theme version # LoveIt theme version
# LoveIt 主题版本 # LoveIt 主题版本
version = "0.1.X" version = "0.2.X"
# public git repo url only then enableGitInfo is true # public git repo url only then enableGitInfo is true
# 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效 # 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效
gitRepo = "https://github.com/dillonzq/LoveIt" gitRepo = "https://github.com/dillonzq/LoveIt"

View file

@ -189,7 +189,7 @@ Note that some of these parameters are explained in details in other sections of
defaultTheme = "auto" defaultTheme = "auto"
# public git repo url only then enableGitInfo is true # public git repo url only then enableGitInfo is true
gitRepo = "" 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") # which hash function used for SRI, when empty, no SRI is used ("sha256", "sha384", "sha512", "md5")
fingerprint = "" fingerprint = ""
# Header info # Header info
@ -349,13 +349,13 @@ Note that some of these parameters are explained in details in other sections of
enable = true enable = true
# Disqus Comment Config (https://disqus.com/) # Disqus Comment Config (https://disqus.com/)
[params.comment.disqus] [params.comment.disqus]
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 # {{< version 0.1.1 >}}
enable = false enable = false
# Disqus shortname to use Disqus in posts # Disqus shortname to use Disqus in posts
shortname = "" shortname = ""
# Gitalk Comment Config (https://github.com/gitalk/gitalk) # Gitalk Comment Config (https://github.com/gitalk/gitalk)
[params.comment.gitalk] [params.comment.gitalk]
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 # {{< version 0.1.1 >}}
enable = false enable = false
owner = "" owner = ""
repo = "" repo = ""

View file

@ -189,7 +189,7 @@ Note that some of these parameters are explained in details in other sections of
defaultTheme = "auto" defaultTheme = "auto"
# public git repo url only then enableGitInfo is true # public git repo url only then enableGitInfo is true
gitRepo = "" 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") # which hash function used for SRI, when empty, no SRI is used ("sha256", "sha384", "sha512", "md5")
fingerprint = "" fingerprint = ""
# Header info # Header info
@ -349,13 +349,13 @@ Note that some of these parameters are explained in details in other sections of
enable = true enable = true
# Disqus Comment Config (https://disqus.com/) # Disqus Comment Config (https://disqus.com/)
[params.comment.disqus] [params.comment.disqus]
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 # {{< version 0.1.1 >}}
enable = false enable = false
# Disqus shortname to use Disqus in posts # Disqus shortname to use Disqus in posts
shortname = "" shortname = ""
# Gitalk Comment Config (https://github.com/gitalk/gitalk) # Gitalk Comment Config (https://github.com/gitalk/gitalk)
[params.comment.gitalk] [params.comment.gitalk]
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 # {{< version 0.1.1 >}}
enable = false enable = false
owner = "" owner = ""
repo = "" repo = ""

View file

@ -192,7 +192,7 @@ hugo
defaultTheme = "auto" defaultTheme = "auto"
# 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效 # 公共 git 仓库路径,仅在 enableGitInfo 设为 true 时有效
gitRepo = "" gitRepo = ""
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 # {{< version 0.1.1 >}}
# 哪种哈希函数用来 SRI, 为空时表示不使用 SRI ("sha256", "sha384", "sha512", "md5") # 哪种哈希函数用来 SRI, 为空时表示不使用 SRI ("sha256", "sha384", "sha512", "md5")
fingerprint = "" fingerprint = ""
# 页面头部导航栏信息 # 页面头部导航栏信息
@ -351,13 +351,13 @@ hugo
enable = true enable = true
# Disqus 评论系统设置 (https://disqus.com/) # Disqus 评论系统设置 (https://disqus.com/)
[params.comment.disqus] [params.comment.disqus]
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 # {{< version 0.1.1 >}}
enable = false enable = false
# Disqus 的 shortname用来在文章中启用 Disqus 评论系统 # Disqus 的 shortname用来在文章中启用 Disqus 评论系统
shortname = "" shortname = ""
# Gitalk 评论系统设置 (https://github.com/gitalk/gitalk) # Gitalk 评论系统设置 (https://github.com/gitalk/gitalk)
[params.comment.gitalk] [params.comment.gitalk]
# LoveIt :(fas fa-greater-than-equal): :(far fa-file-archive): 0.1.1 # {{< version 0.1.1 >}}
enable = false enable = false
owner = "" owner = ""
repo = "" repo = ""

View file

@ -76,7 +76,7 @@ comment: true
``` ```
* **title**: the title for the content. * **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). * **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. * **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. * **draft**: if `true`, the content will not be rendered unless the `--buildDrafts`/`-D` flag is passed to the `hugo` command.

View file

@ -76,7 +76,7 @@ comment: true
``` ```
* **title**: the title for the content. * **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). * **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. * **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. * **draft**: if `true`, the content will not be rendered unless the `--buildDrafts`/`-D` flag is passed to the `hugo` command.

View file

@ -76,7 +76,7 @@ comment: true
``` ```
* **title**: 文章标题. * **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) 中设置. * **date**: 这篇文章创建的日期时间. 它通常是从文章的前置参数中的 `date` 字段获取的, 但是也可以在 [网站配置](../theme-documentation-basics/#site-configuration) 中设置.
* **lastmod**: 上次修改内容的日期时间. * **lastmod**: 上次修改内容的日期时间.
* **draft**: 如果设为 `true`, 除非 `hugo` 命令使用了 `--buildDrafts`/`-D` 参数, 这篇文章不会被渲染. * **draft**: 如果设为 `true`, 除非 `hugo` 命令使用了 `--buildDrafts`/`-D` 参数, 这篇文章不会被渲染.

View file

@ -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 := newScratch -}}
{{- .Scratch.Set "scratch" $scratch -}} {{- .Scratch.Set "scratch" $scratch -}}
{{- if eq hugo.Environment "production" -}} {{- if eq hugo.Environment "production" -}}
{{- $scratch.Set "production" true -}}
{{- $scratch.Set "CDN" .Site.Params.cdn -}} {{- $scratch.Set "CDN" .Site.Params.cdn -}}
{{- $scratch.Set "fingerprint" .Site.Params.fingerprint -}} {{- $scratch.Set "fingerprint" .Site.Params.fingerprint -}}
{{- end -}} {{- 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 -}}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{{ .Site.LanguageCode }}"> <html lang="{{ .Site.LanguageCode }}">
<head> <head>

View file

@ -243,6 +243,6 @@
{{- end -}} {{- end -}}
{{- /* Google analytics async */ -}} {{- /* Google analytics async */ -}}
{{- if $scratch.Get "production" | and .Site.GoogleAnalytics -}} {{- if eq hugo.Environment "production" | and .Site.GoogleAnalytics -}}
{{- template "_internal/google_analytics_async.html" . -}} {{- template "_internal/google_analytics_async.html" . -}}
{{- end -}} {{- end -}}

View file

@ -1,6 +1,6 @@
{{- $scratch := .Scratch.Get "scratch" -}} {{- $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" -}} {{- $CDN := $scratch.Get "CDN" -}}
{{- /* Disqus Comment System */ -}} {{- /* Disqus Comment System */ -}}

View file

@ -1,8 +1,11 @@
{{- $scratch := .Scratch.Get "scratch" -}}
<footer class="footer"> <footer class="footer">
<div class="copyright"> <div class="copyright">
{{- /* Hugo and LoveIt */ -}} {{- /* Hugo and LoveIt */ -}}
<div class="copyright-line"> <div class="copyright-line">
{{- printf (T "poweredBySome") `<a href="https://gohugo.io/" target="_blank" rel="external nofollow noopener noreffer">Hugo</a>` | safeHTML }} | {{ T "theme" }} - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="external nofollow noopener noreffer"><i class="far fa-heart fa-fw"></i> LoveIt</a> {{- $hugo := printf `<a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo %s">Hugo</a>` hugo.Version -}}
{{- printf (T "poweredBySome") $hugo | safeHTML }} | {{ T "theme" }} - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt v{{ $scratch.Get "version" }}"><i class="far fa-heart fa-fw"></i> LoveIt</a>
</div> </div>
<div class="copyright-line"> <div class="copyright-line">

View file

@ -1,5 +1,6 @@
{{- template "_internal/opengraph.html" . -}} {{- template "_internal/opengraph.html" . -}}
{{- template "_internal/twitter_cards.html" . -}} {{- template "_internal/twitter_cards.html" . -}}
{{- hugo.Generator -}}
<meta name="theme-color" content="#ffffff"> <meta name="theme-color" content="#ffffff">
<meta name="msapplication-TileColor" content="#da532c"> <meta name="msapplication-TileColor" content="#da532c">

View file

@ -37,7 +37,7 @@
<i class="far fa-calendar-alt fa-fw"></i><time datetime={{ $publish_date }}>{{ $publish_date }}</time>&nbsp; <i class="far fa-calendar-alt fa-fw"></i><time datetime={{ $publish_date }}>{{ $publish_date }}</time>&nbsp;
<i class="fas fa-pencil-alt fa-fw"></i>{{ T "wordCount" .WordCount }}&nbsp; <i class="fas fa-pencil-alt fa-fw"></i>{{ T "wordCount" .WordCount }}&nbsp;
<i class="far fa-clock fa-fw"></i>{{ T "readingTime" .ReadingTime }}&nbsp; <i class="far fa-clock fa-fw"></i>{{ T "readingTime" .ReadingTime }}&nbsp;
{{- if $scratch.Get "production" | and .Site.Params.comment.valine.enable | and .Site.Params.comment.valine.visitor -}} {{- if eq hugo.Environment "production" | and .Site.Params.comment.valine.enable | and .Site.Params.comment.valine.visitor -}}
<span id="{{ .RelPermalink | relURL }}" class="leancloud_visitors" data-flag-title="{{ .Title }}"> <span id="{{ .RelPermalink | relURL }}" class="leancloud_visitors" data-flag-title="{{ .Title }}">
<i class="far fa-eye fa-fw"></i><span class=leancloud-visitors-count></span>&nbsp;{{ T "views" }} <i class="far fa-eye fa-fw"></i><span class=leancloud-visitors-count></span>&nbsp;{{ T "views" }}
</span>&nbsp; </span>&nbsp;

View file

@ -0,0 +1 @@
<span class="version"><i class="far fa-heart fa-fw"></i> LoveIt <i class="fas fa-greater-than-equal fa-fw"></i> <a href="https://github.com/dillonzq/LoveIt/releases/tag/v{{ .Get 0 }}" rel="noopener noreffer" target="_blank" title="LoveIt v{{ .Get 0 }}">{{ .Get 0 }}</a></span>

2
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "loveit-src", "name": "loveit-src",
"version": "0.1.2", "version": "0.2.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View file

@ -1,6 +1,6 @@
{ {
"name": "loveit-src", "name": "loveit-src",
"version": "0.1.4", "version": "0.2.0",
"description": "LoveIt theme source file", "description": "LoveIt theme source file",
"main": "index.js", "main": "index.js",
"dependencies": {}, "dependencies": {},