Skip to content

[Bug]: Don't replace hugo's default render-blockquote.html template unecessarily #2740

@solonovamax

Description

@solonovamax

Issue Check

  • I have checked existing Issues and I feel this bug has not been raised

Hugo Version Check

  • My Hugo version is within the supported range

Describe the Bug

With the addition of admonitions in #2643, the render-blockquote.html template was introduced unecessarily.

If you do this, then if users wish to override the block quote rendering for a certain type, this will be prioritized (afaik).

In the hugo docs, it says:

Although you can use one template with conditional logic as shown above, you can also create separate templates for each Type of blockquote:

layouts/
  └── _markup/
      ├── render-blockquote-alert.html
      └── render-blockquote-regular.html

I am currently in the process of semi-forking this theme and have introduced admonitions as well, and I did so by using render-blockquote-alert.html rather than render-blockquote.html.

Once I actually push it to github, you can feel free to take anything from it, however here is currently how I'm doing admonitions (some small segments were taken from how you were doing it, however the majority is from hugo-admonitions, which is where I suspect that the adminitions PR was largely based off of):

Alternate admonitions implementation
{{- $icons := dict
"abstract"   "lucide/file-text"
"bug"        "lucide/bug"
"caution"    "lucide/triangle-alert"
"code"       "lucide/code-xml"
"conclusion" "lucide/circle-check"
"danger"     "lucide/zap"
"error"      "lucide/x"
"example"    "lucide/pencil"
"experiment" "lucide/flask-conical"
"failure"    "lucide/x"
"goal"       "lucide/target"
"idea"       "lucide/lightbulb"
"important"  "lucide/circle-alert"
"info"       "lucide/info"
"memo"       "lucide/file-text"
"note"       "lucide/notebook-pen"
"notify"     "lucide/bell"
"question"   "lucide/circle-question-mark"
"quote"      "lucide/quote"
"success"    "lucide/check"
"task"       "lucide/list-checks"
"tip"        "lucide/flame"
"warning"    "lucide/triangle-alert"
}}

{{- $admonitionColor := dict
"abstract"   "rgb(32,  159, 181)"
"bug"        "rgb(210, 15,  57)"
"caution"    "rgb(230, 69,  83)"
"code"       "rgb(114, 135, 253)"
"conclusion" "rgb(157, 221, 120)"
"danger"     "rgb(210, 15,  57)"
"error"      "rgb(210, 15,  57)"
"example"    "rgb(124, 77,  255)"
"experiment" "rgb(124, 77,  255)"
"failure"    "rgb(255, 82,  82)"
"goal"       "rgb(70,  88,  255)"
"idea"       "rgb(247, 220, 111)"
"important"  "rgb(125, 77,  218)"
"info"       "rgb(4,   165, 229)"
"memo"       "rgb(9,   106, 225)"
"note"       "rgb(9,   106, 225)"
"notify"     "rgb(13,  72,  189)"
"question"   "rgb(100, 221, 23)"
"quote"      "rgb(114, 135, 253)"
"success"    "rgb(0,   200, 83)"
"task"       "rgb(136, 57,  239)"
"tip"        "rgb(23,  146, 153)"
"warning"    "rgb(223, 142, 29)"
}}

{{- /* Determine type and title */ -}}
{{- $rawType := .AlertType | lower -}}
{{- $type := cond (index $icons $rawType) $rawType "note" }}
{{- $title := or .AlertTitle (T (printf "admonitions.%s" $type)) (title $type) }}
{{- $iconName := .Attributes.icon | default (index $icons $type) | default "lucide/info" }}

{{- $style := printf "--admonition-color: %s;" (index $admonitionColor $type) -}}
{{- $class := printf "admonition %s border-1 border-(--admonition-color) rounded-lg my-4 shadow-r-sm dark:shadow-neutral-700/25 " $type -}}
{{- $headerClass := "admonition-header text-(--admonition-color) bg-(--admonition-color)/10 bg-opacity-10 rounded-t-lg px-4 py-2 font-semibold text-lg flex items-center" -}}
{{- $bodyClass := "admonition-body bg-neutral dark:bg-neutral-800 p-4 rounded-lg" -}}
{{- $iconClass := "relative inline-block align-middle icon mr-2" -}}

{{- $isCollapsible := in (slice "+" "-") .AlertSign -}}
{{- /* Yes, there's useless duplication here. But only because my IDE's formatter makes it look stupid if I remove the duplication. */ -}}
{{- if $isCollapsible -}}
    <details class="{{ $class }}"
             data-admonition-type="{{ $type }}"
             style="{{ $style | safeCSS }}"
             {{ if eq .AlertSign "+" }}open{{ end }}>
        <summary class="{{ $headerClass }} relative">
            {{- partial "icon.html" (dict "id" $iconName "class" $iconClass) -}}
            <span>{{ $title }}</span>
        </summary>

        {{- with .Text }}
            <div class="{{ $bodyClass }}">
                {{- . | safeHTML -}}
            </div>
        {{- end -}}
    </details>
{{- else -}}
    <div class="{{ $class }}"
         data-admonition-type="{{ $type }}"
         style="{{ $style | safeCSS }}">
        <div class="{{ $headerClass }}">
            {{- partial "icon.html" (dict "id" $iconName "class" $iconClass) -}}
            <span>{{- $title -}}</span>
        </div>

        {{- with .Text }}
            <div class="{{ $bodyClass }}">
                {{- . | safeHTML -}}
            </div>
        {{- end -}}
    </div>
{{- end -}}

To Reproduce

N/A

Expected Behaviour

N/A

Screenshots

No response

Platform

N/A

Hugo Version

N/A

Blowfish Version

N/A

Additional Context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions