diff --git a/CHANGELOG.md b/CHANGELOG.md index 68c39a6a..f2e1754c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - :bug: Fix: Giscus comments invalid config `inputPosition` - :bug: Fix: busuanzi logic error - :bug: Fix: close comment system logic error when the article was expired +- :truck: Perf: subdivide FixIt initialization - :art: Style: add theme colors variables and add common color styles - :art: Style: add scroll bar for auto toc ([#136](https://github.com/Lruihao/FixIt/issues/136)) - :wrench: Feat(cdn): add unpkg cdn support diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 498de75a..962b40ef 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,4 +1,4 @@ -{{- partial "init.html" . -}} +{{- partial "init/index.html" . -}} diff --git a/layouts/partials/init.html b/layouts/partials/init.html deleted file mode 100644 index 4b0cc501..00000000 --- a/layouts/partials/init.html +++ /dev/null @@ -1,66 +0,0 @@ -{{- $version := "v0.2.15-RC" -}} -{{ $latest := (getJSON "https://api.github.com/repos/Lruihao/FixIt/releases/latest").tag_name | default $version }} -{{- $VERSION := "0.2.X" -}} - -{{- /* FixIt theme version detection */ -}} -{{- if eq .Site .Sites.First -}} - {{- if (strings.HasSuffix $version "RC") -}} - {{- warnf "FixIt %v\n%v" $version (T "RCVersionWarn") -}} - {{- end -}} - {{- if not .Site.Params.version -}} - {{- errorf "FixIt %v\n%v" $version (T "configurationError") -}} - {{- else if ne .Site.Params.version $VERSION -}} - {{- errorf "FixIt %v\n%v" $version (dict "From" .Site.Params.version "To" $VERSION | T "compatibilityError") -}} - {{- end -}} -{{- end -}} - -{{- $params := .Params | merge .Site.Params.page -}} -{{- $toc := $params.toc -}} -{{- if eq $toc true -}} - {{- $toc = .Site.Params.page.toc | default dict -}} -{{- else if eq $toc false -}} - {{- $toc = dict "enable" false -}} -{{- end -}} - -{{- if hugo.IsProduction -}} - {{- $cdn := .Site.Params.cdn -}} - {{- with $cdn.data -}} - {{- $cdnData := printf "data/cdn/%v" . | resources.Get | transform.Unmarshal -}} - {{- $cdn = dict "simpleIconsPrefix" $cdnData.prefix.simpleIcons -}} - {{- $prefix := $cdnData.prefix.libFiles | default "" -}} - {{- range $key, $value := $cdnData.libFiles -}} - {{- $cdn = printf "%v%v" $prefix $value | dict $key | merge $cdn -}} - {{- end -}} - {{- end -}} - {{- .Scratch.Set "cdn" $cdn -}} - {{- .Scratch.Set "fingerprint" .Site.Params.fingerprint -}} - {{- .Scratch.Set "analytics" .Site.Params.analytics -}} - {{- .Scratch.Set "comment" $params.comment -}} - {{- if eq .Params.comment true -}} - {{- .Scratch.Set "comment" .Site.Params.page.comment -}} - {{- else if eq .Params.comment false -}} - {{- .Scratch.Set "comment" dict -}} - {{- end -}} -{{- else if eq .Site .Sites.First -}} - {{- warnf "FixIt %v\n%v" $version (T "devEnvWarn") -}} -{{- end -}} - -{{- /* Deprecated parameter detection */ -}} -{{- $warnErrors := slice -}} -{{- with .Site.Params.home.profile.gravatarSite -}} - {{- $warnErrors = $warnErrors | append "The parameter `home.profile.gravatarSite` is deprecated since v0.2.14, use `gravatar.host` instead." -}} -{{- end -}} -{{- with .Site.Params.ibruce.siteTime -}} - {{- $warnErrors = $warnErrors | append "The parameter `ibruce.siteTime` is deprecated since v0.2.14, use `footer.siteTime` instead." -}} -{{- end -}} -{{- if len $warnErrors -}} - {{- warnf "Deprecated parameter detection until %v\n - %v" $version (delimit $warnErrors "\n - ") -}} -{{- end -}} - -{{- .Scratch.Set "version" $version -}} -{{- .Scratch.Set "latest" $latest -}} -{{- .Scratch.Set "params" $params -}} -{{- .Scratch.Set "toc" $toc -}} -{{- .Scratch.Set "this" dict -}} - -{{- partial "plugin/compatibility.html" . -}} diff --git a/layouts/partials/init/detection-deprecated.html b/layouts/partials/init/detection-deprecated.html new file mode 100644 index 00000000..5368c536 --- /dev/null +++ b/layouts/partials/init/detection-deprecated.html @@ -0,0 +1,12 @@ +{{- /* Deprecated parameter detection */ -}} + +{{- $warnErrors := slice -}} +{{- with .Site.Params.home.profile.gravatarSite -}} + {{- $warnErrors = $warnErrors | append "The parameter `home.profile.gravatarSite` is deprecated since v0.2.14, use `gravatar.host` instead." -}} +{{- end -}} +{{- with .Site.Params.ibruce.siteTime -}} + {{- $warnErrors = $warnErrors | append "The parameter `ibruce.siteTime` is deprecated since v0.2.14, use `footer.siteTime` instead." -}} +{{- end -}} +{{- if len $warnErrors -}} + {{- warnf "Deprecated parameter detection until %v\n - %v" (.Scratch.Get "version") (delimit $warnErrors "\n - ") -}} +{{- end -}} \ No newline at end of file diff --git a/layouts/partials/init/detection-env.html b/layouts/partials/init/detection-env.html new file mode 100644 index 00000000..0eddabd3 --- /dev/null +++ b/layouts/partials/init/detection-env.html @@ -0,0 +1,26 @@ +{{- /* FixIt theme environment detection */ -}} + +{{- $params := .Scratch.Get "params" -}} + +{{- if hugo.IsProduction -}} + {{- $cdn := .Site.Params.cdn -}} + {{- with $cdn.data -}} + {{- $cdnData := printf "data/cdn/%v" . | resources.Get | transform.Unmarshal -}} + {{- $cdn = dict "simpleIconsPrefix" $cdnData.prefix.simpleIcons -}} + {{- $prefix := $cdnData.prefix.libFiles | default "" -}} + {{- range $key, $value := $cdnData.libFiles -}} + {{- $cdn = printf "%v%v" $prefix $value | dict $key | merge $cdn -}} + {{- end -}} + {{- end -}} + {{- .Scratch.Set "cdn" $cdn -}} + {{- .Scratch.Set "fingerprint" .Site.Params.fingerprint -}} + {{- .Scratch.Set "analytics" .Site.Params.analytics -}} + {{- .Scratch.Set "comment" $params.comment -}} + {{- if eq .Params.comment true -}} + {{- .Scratch.Set "comment" .Site.Params.page.comment -}} + {{- else if eq .Params.comment false -}} + {{- .Scratch.Set "comment" dict -}} + {{- end -}} +{{- else if eq .Site .Sites.First -}} + {{- warnf "FixIt %v\n%v" (.Scratch.Get "version") (T "devEnvWarn") -}} +{{- end -}} \ No newline at end of file diff --git a/layouts/partials/init/detection-version.html b/layouts/partials/init/detection-version.html new file mode 100644 index 00000000..9758aee5 --- /dev/null +++ b/layouts/partials/init/detection-version.html @@ -0,0 +1,19 @@ +{{- /* FixIt theme version detection */ -}} + +{{- $version := "v0.2.15-RC" -}} +{{ $header := dict "Authorization" "token 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" }} +{{ $latest := (getJSON "https://api.github.com/repos/Lruihao/FixIt/releases/latest" $header).tag_name }} + +{{- if eq .Site .Sites.First -}} + {{- if (strings.HasSuffix $version "RC") -}} + {{- warnf "FixIt %v\n%v" $version (T "RCVersionWarn") -}} + {{- end -}} + {{- if not .Site.Params.version -}} + {{- errorf "FixIt %v\n%v" $version (T "configurationError") -}} + {{- else if gt "0.2.0" (strings.TrimPrefix "v" .Site.Params.version) -}} + {{- errorf "FixIt %v\n%v" $version (dict "From" .Site.Params.version "To" $version | T "compatibilityError") -}} + {{- end -}} +{{- end -}} + +{{- .Scratch.Set "version" $version -}} +{{- .Scratch.Set "latest" $latest -}} \ No newline at end of file diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html new file mode 100644 index 00000000..f4558de0 --- /dev/null +++ b/layouts/partials/init/index.html @@ -0,0 +1,9 @@ +{{- .Scratch.Set "params" (.Params | merge .Site.Params.page) -}} +{{- .Scratch.Set "this" dict -}} + +{{- partial "init/detection-version.html" . -}} +{{- partial "init/detection-env.html" . -}} +{{- partial "init/detection-deprecated.html" . -}} +{{- partial "init/patch.html" . -}} + +{{- partial "plugin/compatibility.html" . -}} diff --git a/layouts/partials/init/patch.html b/layouts/partials/init/patch.html new file mode 100644 index 00000000..01dc6f92 --- /dev/null +++ b/layouts/partials/init/patch.html @@ -0,0 +1,10 @@ +{{- $params := .Scratch.Get "params" -}} + +{{- /* FixIt theme toc patch */ -}} +{{- $toc := $params.toc -}} +{{- if eq $toc true -}} + {{- $toc = .Site.Params.page.toc | default dict -}} +{{- else if eq $toc false -}} + {{- $toc = dict "enable" false -}} +{{- end -}} +{{- .Scratch.Set "toc" $toc -}} \ No newline at end of file