mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 23:38:56 +00:00
♻️ Refactor: refactor typeit shortcode and feature (#420)
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
<main class="container{{ if (eq $toc.enable true) | and (eq $toc.position `left`) }} container-reverse{{ end }}">
|
||||
{{- block "content" . }}{{ end -}}
|
||||
</main>
|
||||
{{- partial "footer.html" . -}}
|
||||
{{- partialCached "footer.html" . -}}
|
||||
</div>
|
||||
|
||||
{{- /* Theme widgets */ -}}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
{{- $cdn := .Scratch.Get "cdn" | default dict -}}
|
||||
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
|
||||
{{- $config := (.Scratch.Get "this").config -}}
|
||||
{{- $config = dict "version" (.Scratch.Get "version") | merge $config -}}
|
||||
|
||||
{{- /* Search */ -}}
|
||||
{{- if .Site.Params.search | and .Site.Params.search.enable -}}
|
||||
@@ -70,11 +71,11 @@
|
||||
{{- end -}}
|
||||
|
||||
{{- /* TypeIt */ -}}
|
||||
{{- with (.Scratch.Get "this").typeitMap -}}
|
||||
{{- $typeit := $.Site.Params.typeit -}}
|
||||
{{- if .Store.Get "hasTyped" -}}
|
||||
{{- $typeit := .Site.Params.typeit -}}
|
||||
{{- $source := $cdn.typeitJS | default "lib/typeit/index.umd.js" -}}
|
||||
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
|
||||
{{- $config = dict "speed" $typeit.speed "cursorSpeed" $typeit.cursorSpeed "cursorChar" $typeit.cursorChar "duration" $typeit.duration "loop" $typeit.loop "data" . | dict "typeit" | merge $config -}}
|
||||
{{- $config = dict "speed" $typeit.speed "cursorSpeed" $typeit.cursorSpeed "cursorChar" $typeit.cursorChar "duration" $typeit.duration "loop" $typeit.loop | dict "typeit" | merge $config -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* KaTeX */ -}}
|
||||
|
||||
@@ -14,9 +14,8 @@
|
||||
<span class="header-title-pre">{{ . | safeHTML }}</span>
|
||||
{{- end -}}
|
||||
{{- if .typeit -}}
|
||||
{{- $id := dict "Content" .name "Scratch" $.Scratch "Id" "typeit-header-desktop" | partial "function/id.html" -}}
|
||||
<span id="{{ $id }}" class="typeit"></span>
|
||||
{{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
|
||||
{{- $.Store.Set "hasTyped" true -}}
|
||||
<span class="typeit"><template>{{ .name | default $.Site.Title }}</template></span>
|
||||
{{- else -}}
|
||||
<span class="header-title-text">{{ .name | default $.Site.Title }}</span>
|
||||
{{- end -}}
|
||||
@@ -29,9 +28,8 @@
|
||||
</a>
|
||||
{{- with .Site.Params.header.subtitle -}}
|
||||
{{- if .typeit -}}
|
||||
{{- $id := dict "Content" .name "Scratch" $.Scratch "Id" "typeit-header-subtitle-desktop" | partial "function/id.html" -}}
|
||||
<span id="{{ $id }}" class="typeit header-subtitle"></span>
|
||||
{{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
|
||||
{{- $.Store.Set "hasTyped" true -}}
|
||||
<span class="typeit header-subtitle"><template>{{ .name }}</template></span>
|
||||
{{- else -}}
|
||||
<span class="header-subtitle">{{ .name }}</span>
|
||||
{{- end -}}
|
||||
@@ -164,9 +162,8 @@
|
||||
<span class="header-title-pre">{{ . | safeHTML }}</span>
|
||||
{{- end -}}
|
||||
{{- if .typeit -}}
|
||||
{{- $id := dict "Content" .name "Scratch" $.Scratch "Id" "typeit-header-title-mobile" | partial "function/id.html" -}}
|
||||
<span id="{{ $id }}" class="typeit"></span>
|
||||
{{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
|
||||
{{- $.Store.Set "hasTyped" true -}}
|
||||
<span class="typeit"><template>{{ .name | default $.Site.Title }}</template></span>
|
||||
{{- else -}}
|
||||
<span class="header-title-text">{{ .name | default $.Site.Title }}</span>
|
||||
{{- end -}}
|
||||
@@ -179,9 +176,8 @@
|
||||
</a>
|
||||
{{- with .Site.Params.header.subtitle -}}
|
||||
{{- if .typeit -}}
|
||||
{{- $id := dict "Content" .name "Scratch" $.Scratch "Id" "typeit-header-subtitle-mobile" | partial "function/id.html" -}}
|
||||
<span id="{{ $id }}" class="typeit header-subtitle"></span>
|
||||
{{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
|
||||
{{- $.Store.Set "hasTyped" true -}}
|
||||
<span class="typeit header-subtitle"><template>{{ .name }}</template></span>
|
||||
{{- else -}}
|
||||
<span class="header-subtitle">{{- .name -}}</span>
|
||||
{{- end -}}
|
||||
|
||||
@@ -45,10 +45,9 @@
|
||||
{{- with $profile.subtitle -}}
|
||||
<p class="home-subtitle">
|
||||
{{- if $profile.typeit -}}
|
||||
{{- $id := dict "Content" . "Scratch" $.Scratch "Id" "typeit-profile-subtitle" | partial "function/id.html" -}}
|
||||
<span class="d-none">{{ . }}</span>
|
||||
<span id="{{ $id }}" class="typeit"></span>
|
||||
{{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
|
||||
{{- $.Store.Set "hasTyped" true -}}
|
||||
<span class="typeit"><template>{{ . }}</template></span>
|
||||
{{- else -}}
|
||||
{{- . -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{- .Scratch.Set "version" "v0.3.3-RC" -}}
|
||||
{{- .Scratch.Set "this" (dict "version" (.Scratch.Get "version") | dict "config") -}}
|
||||
{{- .Scratch.Set "this" dict -}}
|
||||
|
||||
{{- partial "init/detection-env.html" . -}}
|
||||
{{- partial "init/detection-version.html" . -}}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{{- /* trim the newline */ -}}
|
||||
{{- $content := trim (partial "function/dos2unix.html" .Inner) "\n" -}}
|
||||
{{- $classList := slice -}}
|
||||
{{- with .Get "class" -}}
|
||||
@@ -15,25 +16,26 @@
|
||||
{{- /* parsing code links */ -}}
|
||||
{{- $content = replaceRE `(<span[^<>]*>)([^<>]*)\[([^<>]+)\]\(([^<>]+)\)([^<>]*)(</span>)` "$1$2$6<a href=\"$4\">$3</a>$1$5$6" $content -}}
|
||||
{{- end -}}
|
||||
{{- /* split multiline string */ -}}
|
||||
{{- $content = split $content "\n" -}}
|
||||
{{- $classList = $classList | append "highlight" -}}
|
||||
{{- else -}}
|
||||
{{- $content = $content | .Page.RenderString -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* trim the newline */ -}}
|
||||
{{- $id := dict "Content" $content "Scratch" .Page.Scratch | partial "function/id.html" -}}
|
||||
{{- $key := .Get "group" | string | default $id -}}
|
||||
{{- $typeitMap := (.Page.Scratch.Get "this").typeitMap | default dict -}}
|
||||
{{- $group := index $typeitMap $key -}}
|
||||
{{- $group = $group | default slice | append $id -}}
|
||||
{{- dict $key $group | merge $typeitMap | .Page.Scratch.SetInMap "this" "typeitMap" -}}
|
||||
|
||||
{{- $attrs := printf `id="%v"` $id -}}
|
||||
{{- with $classList -}}
|
||||
{{- $attrs = delimit $classList " " | printf `%v class="%v"` $attrs -}}
|
||||
{{- $wrapperAttrs := `class="typeit"` -}}
|
||||
{{- with (.Get "group" | string) -}}
|
||||
{{- $wrapperAttrs = printf `%v data-group="%v"` $wrapperAttrs . -}}
|
||||
{{- end -}}
|
||||
{{- with $loop -}}
|
||||
{{- $wrapperAttrs = printf `%v data-loop="true"` $wrapperAttrs -}}
|
||||
{{- end -}}
|
||||
|
||||
<div class="typeit"{{ if ne $loop "" }} data-loop="{{ $loop }}"{{ end }}>{{ printf `<%v %v></%v>` $tag $attrs $tag | safeHTML }}</div>
|
||||
{{- /* EOF */ -}}
|
||||
{{- $innerAttrs := "" -}}
|
||||
{{- with $classList -}}
|
||||
{{- $innerAttrs = printf `class="%v"` (delimit $classList " ") -}}
|
||||
{{- end -}}
|
||||
|
||||
<div {{ $wrapperAttrs | safeHTMLAttr }}>
|
||||
{{- printf `<%v %v></%v>` $tag $innerAttrs $tag | safeHTML -}}
|
||||
<template>{{ printf "%v" $content | safeHTML }}</template>
|
||||
</div>
|
||||
{{- .Page.Store.Set "hasTyped" true -}}
|
||||
|
||||
Reference in New Issue
Block a user