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
20 changed files with 53 additions and 26 deletions

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.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 -}}
<!DOCTYPE html>
<html lang="{{ .Site.LanguageCode }}">
<head>