From 177487cd91826e3ff91734ffa93ce9e2ea6467e5 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 13 Jan 2022 21:01:52 +0800 Subject: [PATCH] :bug: Fix: typeit print code error (#19) --- CHANGELOG.md | 1 + layouts/partials/function/id.html | 12 +++++++++--- layouts/partials/header.html | 8 ++++---- layouts/partials/home/profile.html | 2 +- layouts/shortcodes/typeit.html | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8470a139..7cba4f5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - :zap: Perf: optimize JS loading ([#25](https://github.com/Lruihao/FixIt/issues/25)) - :art: Perf: optimize footer code - :recycle: Refactor: header title DOM and add subtitle option ([#26](https://github.com/Lruihao/FixIt/issues/26)) +- :bug: Fix: typeit print code error ([#19](https://github.com/Lruihao/FixIt/issues/19)) - :bug: Fix: add scroll-margin to headerlink - :bug: Fix: pre element overflow error ([#29](https://github.com/Lruihao/FixIt/issues/29)) - :bug: Fix: toc-auto display error ([#21](https://github.com/Lruihao/FixIt/issues/21)) diff --git a/layouts/partials/function/id.html b/layouts/partials/function/id.html index a423e1d7..73fac683 100644 --- a/layouts/partials/function/id.html +++ b/layouts/partials/function/id.html @@ -1,7 +1,13 @@ {{- /* ID */ -}} -{{- $count := (.Scratch.Get "this").count | default 1 -}} -{{- $id := printf "id-%d" $count -}} -{{- $count | add 1 | .Scratch.SetInMap "this" "count" -}} +{{- $id := "" -}} +{{- with .Id -}} + {{- /* If an ID is specified, then just use it.*/ -}} + {{- $id = printf "%v" . -}} +{{- else -}} + {{- $count := ($.Scratch.Get "this").count | default 1 -}} + {{- $id = printf "id-%d" $count -}} + {{- $count | add 1 | $.Scratch.SetInMap "this" "count" -}} +{{- end -}} {{- with .Content -}} {{- dict $id . | dict "data" | dict "config" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}} {{- end -}} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index e977beb2..61f28b42 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -11,7 +11,7 @@ {{ . | safeHTML }} {{- end -}} {{- if .typeit -}} - {{- $id := dict "Content" .name "Scratch" $.Scratch | partial "function/id.html" -}} + {{- $id := dict "Content" .name "Scratch" $.Scratch "Id" "typeit-header-desktop" | partial "function/id.html" -}} {{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}} {{- else -}} @@ -26,7 +26,7 @@ {{- with .Site.Params.header.subtitle -}} {{- if .typeit -}} - {{- $id := dict "Content" .name "Scratch" $.Scratch | partial "function/id.html" -}} + {{- $id := dict "Content" .name "Scratch" $.Scratch "Id" "typeit-header-subtitle-desktop" | partial "function/id.html" -}} {{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}} {{- else -}} @@ -107,7 +107,7 @@ {{ . | safeHTML }} {{- end -}} {{- if .typeit -}} - {{- $id := dict "Content" .name "Scratch" $.Scratch | partial "function/id.html" -}} + {{- $id := dict "Content" .name "Scratch" $.Scratch "Id" "typeit-header-title-mobile" | partial "function/id.html" -}} {{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}} {{- else -}} @@ -122,7 +122,7 @@ {{- with .Site.Params.header.subtitle -}} {{- if .typeit -}} - {{- $id := dict "Content" .name "Scratch" $.Scratch | partial "function/id.html" -}} + {{- $id := dict "Content" .name "Scratch" $.Scratch "Id" "typeit-header-subtitle-mobile" | partial "function/id.html" -}} {{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}} {{- else -}} diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html index b1433156..41678ff6 100644 --- a/layouts/partials/home/profile.html +++ b/layouts/partials/home/profile.html @@ -30,7 +30,7 @@ {{- with $profile.subtitle -}}
]*>(?s)(.*)]*>(?s)(.*)