Skip to content

Commit

Permalink
fix: admonition
Browse files Browse the repository at this point in the history
  • Loading branch information
HEIGE-PCloud committed Mar 28, 2024
1 parent 6cef8c4 commit 5c8f429
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions assets/css/_partial/_details.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}
}

i.details-icon {
.details-icon > svg {
color: $global-font-secondary-color;
@include transition(transform 0.2s ease);

Expand All @@ -24,7 +24,7 @@
}

&.open {
i.details-icon {
.details-icon > svg {
@include transform(rotate(90deg));
}

Expand Down
6 changes: 3 additions & 3 deletions assets/css/_partial/_single/_admonition.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
padding: .5rem 0;
}

i.icon {
span.icon > svg {
font-size: 0.85rem;
color: map-get($admonition-color-map, 'note');
position: absolute;
top: .6rem;
left: .4rem;
}

i.details-icon {
span.details-icon > svg {
position: absolute;
top: .6rem;
right: .3rem;
Expand All @@ -40,7 +40,7 @@
&.#{$type} {
border-left-color: $color;

i.icon {
span.icon > svg {
color: $color;
}
}
Expand Down
10 changes: 8 additions & 2 deletions layouts/partials/plugin/fontawesome.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{{- $path := printf "lib/fontawesome-free/svgs/%v/%v.svg" .Style .Icon -}}
{{- $resource := (resources.Get $path).Content -}}
{{- $resource | replaceRE `<svg xmlns="http://www.w3.org/2000/svg"` `<svg class="icon" xmlns="http://www.w3.org/2000/svg"` | safeHTML -}}

{{- $resource := (resources.Get $path) -}}
{{ if not $resource }}
{{- errorf "Fontawesome icon does not exist %v" $path -}}
{{- end -}}
{{- $resource := $resource.Content -}}
{{- $resource | replaceRE `<svg xmlns="http://www.w3.org/2000/svg" ` `<svg class="icon"
xmlns="http://www.w3.org/2000/svg" ` | safeHTML -}}
41 changes: 26 additions & 15 deletions layouts/shortcodes/admonition.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{{- $inner := .Inner | .Page.RenderString -}}

{{- $iconMap := dict "note" "fas fa-pencil-alt fa-fw" -}}
{{- $iconMap = dict "abstract" "fas fa-list-ul fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "info" "fas fa-info-circle fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "tip" "fas fa-lightbulb fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "success" "fas fa-check-circle fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "question" "fas fa-question-circle fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "warning" "fas fa-exclamation-triangle fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "failure" "fas fa-times-circle fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "danger" "fas fa-skull-crossbones fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "bug" "fas fa-bug fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "example" "fas fa-list-ol fa-fw" | merge $iconMap -}}
{{- $iconMap = dict "quote" "fas fa-quote-right fa-fw" | merge $iconMap -}}
{{- $iconDetails := "fas fa-angle-right fa-fw" -}}
{{- $iconMap := dict "note" (dict "Style" "solid" "Icon" "pencil-alt") -}}
{{- $iconMap = dict "abstract" (dict "Style" "solid" "Icon" "list-ul") | merge $iconMap -}}
{{- $iconMap = dict "info" (dict "Style" "solid" "Icon" "info-circle") | merge $iconMap -}}
{{- $iconMap = dict "tip" (dict "Style" "solid" "Icon" "lightbulb") | merge $iconMap -}}
{{- $iconMap = dict "success" (dict "Style" "solid" "Icon" "check-circle") | merge $iconMap -}}
{{- $iconMap = dict "question" (dict "Style" "solid" "Icon" "question-circle") | merge $iconMap -}}
{{- $iconMap = dict "warning" (dict "Style" "solid" "Icon" "exclamation-triangle") | merge $iconMap -}}
{{- $iconMap = dict "failure" (dict "Style" "solid" "Icon" "times-circle") | merge $iconMap -}}
{{- $iconMap = dict "danger" (dict "Style" "solid" "Icon" "skull-crossbones") | merge $iconMap -}}
{{- $iconMap = dict "bug" (dict "Style" "solid" "Icon" "bug") | merge $iconMap -}}
{{- $iconMap = dict "example" (dict "Style" "solid" "Icon" "list-ol") | merge $iconMap -}}
{{- $iconMap = dict "quote" (dict "Style" "solid" "Icon" "quote-right") | merge $iconMap -}}

{{- if .IsNamedParams -}}
{{- $type := .Get "type" | default "note" -}}
<div class="details admonition {{ $type }}{{ if .Get `open` | ne false }} open{{ end }}">
<div class="details-summary admonition-title">
<i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ .Get "title" | default (T $type) }}<i class="details-icon {{ $iconDetails }}"></i>
<span class="icon">
{{- partial "plugin/fontawesome.html" (index $iconMap $type | default (index $iconMap "note")) -}}
</span>
{{- .Get "title" | default (T $type) -}}
<span class="details-icon">
{{- partial "plugin/fontawesome.html" (dict "Style" "solid" "Icon" "angle-right") -}}
</span>
</div>
<div class="details-content">
<div class="admonition-content">
Expand All @@ -30,7 +35,13 @@
{{- $type := .Get 0 | default "note" -}}
<div class="details admonition {{ $type }}{{ if .Get 2 | ne false }} open{{ end }}">
<div class="details-summary admonition-title">
<i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ .Get 1 | default (T $type) }}<i class="details-icon {{ $iconDetails }}"></i>
<span class="icon">
{{- partial "plugin/fontawesome.html" (index $iconMap $type | default (index $iconMap "note")) -}}
</span>
{{ .Get 1 | default (T $type) }}
<span class="details-icon">
{{- partial "plugin/fontawesome.html" (dict "Style" "solid" "Icon" "angle-right") -}}
</span>
</div>
<div class="details-content">
<div class="admonition-content">
Expand Down

0 comments on commit 5c8f429

Please sign in to comment.