Skip to content

Commit

Permalink
⚡ Chore: simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Aug 30, 2024
1 parent 442ec84 commit 1f22b53
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
32 changes: 5 additions & 27 deletions layouts/_default/_markup/render-blockquote.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
{{- $icons := dict
"caution" "images/icons/alerts/stop.svg"
"important" "images/icons/alerts/report.svg"
"note" "images/icons/alerts/info.svg"
"tip" "images/icons/alerts/light-bulb.svg"
"warning" "images/icons/alerts/alert.svg"
-}}

{{- $Attrs := "" }}
{{- $attrs := "" }}
{{- range $key, $value := .Attributes }}
{{- if $value }}
{{- $Attrs = printf "%s %s=%q" $Attrs $key $value }}
{{- end }}
{{- $attrs = printf "%s %s=%q" $attrs $key $value }}
{{- end }}
{{- $Attrs = trim $Attrs " " }}
{{- $attrs = trim $attrs " " }}

{{- if eq .Type "alert" -}}
{{- with .Attributes.class }}
{{- $Attrs = trim (replace $Attrs . (printf "alert alert-%s %s" $.AlertType .)) " " }}
{{- else }}
{{- $Attrs = trim (printf "class=%q %s" (printf "alert alert-%s" $.AlertType) $Attrs) " " }}
{{- end -}}
<div {{ $Attrs | safeHTMLAttr }}>
{{- $icon := index $icons .AlertType -}}
<p class="alert-title">
{{- dict "Src" $icon | partial "plugin/icon.html" }}
{{- or (T (printf "alert.%v" .AlertType)) (title .AlertType) -}}
</p>
{{- .Text | safeHTML -}}
</div>
{{- dict "Text" .Text "Type" .AlertType "Attributes" .Attributes | partial "plugin/alert.html" -}}
{{- else -}}
<blockquote {{- with $Attrs }} {{ . | safeHTMLAttr }}{{ end }}>{{ .Text | safeHTML }}</blockquote>
<blockquote {{- with $attrs }} {{ . | safeHTMLAttr }}{{ end }}>{{ .Text | safeHTML }}</blockquote>
{{- end -}}
10 changes: 4 additions & 6 deletions layouts/partials/function/get-author-map.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{{- /*
Get author in map format.

@param {String|Map} . the author name or map
@returns {Map}

@example {{- $author := partial "function/get-author-map.html" .Params.author -}}
Get author in map format.
@param {String|Map} . the author name or map
@returns {Map}
@example {{- $author := partial "function/get-author-map.html" .Params.author -}}
*/ -}}

{{- if not (reflect.IsMap site.Params.author) -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.10-52184d96" -}}
{{- .Scratch.Set "version" "v0.3.10-442ec840" -}}
{{- .Scratch.Set "this" dict -}}

{{- partial "init/detection-env.html" . -}}
Expand Down
37 changes: 37 additions & 0 deletions layouts/partials/plugin/alert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{- /*
This partial is used to render an alert box.
@param {String} .Type the type of the alert box
@param {String} .Text the content of the alert box
@param {Map} [.Attributes] the attributes of the alert box
@example {{- dict "Text" .Text "Type" .AlertType "Attributes" .Attributes | partial "plugin/alert.html" -}}
*/ -}}

{{- $icons := dict
"caution" "images/icons/alerts/stop.svg"
"important" "images/icons/alerts/report.svg"
"note" "images/icons/alerts/info.svg"
"tip" "images/icons/alerts/light-bulb.svg"
"warning" "images/icons/alerts/alert.svg"
-}}

{{- $attrs := "" }}
{{- range $key, $value := .Attributes }}
{{- $attrs = printf "%s %s=%q" $attrs $key $value }}
{{- end }}

{{- with .Attributes.class }}
{{- $attrs = replace $attrs . (printf "alert alert-%s %s" $.Type .) }}
{{- else }}
{{- $attrs = printf "class=%q %s" (printf "alert alert-%s" $.Type) $attrs }}
{{- end }}
{{- $attrs = trim $attrs " " -}}

<div {{ $attrs | safeHTMLAttr }}>
{{- $icon := index $icons .Type -}}
<p class="alert-title">
{{- dict "Src" $icon | partial "plugin/icon.html" }}
{{- or (T (printf "alert.%v" .Type)) (title .Type) -}}
</p>
{{- .Text | safeHTML -}}
</div>
{{- /* EOF */ -}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/mapbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@

{{- $attrs := printf `style="width: %v; height: %v;"` $width $height -}}
<div class="mapbox" data-options="{{ $options | jsonify }}" {{ $attrs | safeHTMLAttr }}></div>
{{- /* EOF */ -}}
{{- /* EOF */ -}}

0 comments on commit 1f22b53

Please sign in to comment.