chipzoller / hugo-clarity

A theme for Hugo based on VMware Clarity
Other
577 stars 262 forks source link

[Bug] Caret icon path is incorrect if iconsDir is changed. #416

Closed stdevel closed 1 year ago

stdevel commented 1 year ago

I confirm:

Hugo version

hugo v0.98.0+extended linux/amd64 BuildDate=unknown

Where is this bug showing up?

In the browser: Hugo builds the site, but something doesn't look right.

Operating system

Fedora 37

Browser (if applicable)

Firefox 108.0.1

Current behavior

When changing the iconsDir site variable, the icon caret-icon.svg isn't loaded properly. The folder icons/ is hardcoded and therefore an 404 error is generated.

Expected behavior

The icon path is changed properly.

Steps to reproduce

  1. Change the iconsDir variable in config/_default/params.toml
  2. Run hugo
  3. Open the website, the icon is not displayed

Relevant log output

No response

Related code

The error seems to be in file layouts/partials/nav.html, line 19:

 <a href="{{ $url }}" class="nav_item" title="{{ $name }}">{{ $name }} {{ with $children }}<img src='{{ absURL "icons/caret-icon.svg" }}' alt="icon" class="nav_icon">{{ end }}</a>

Preferred solution

I had a look at the nav.html file and added the missing directive for finding the iconsDir value (like in footer.html or favicon.html) - but unfortunately it is not working for me:

{{- $iconsDir := default "icons/" .Site.Params.iconsDir }}
{{- $menu := .menu }}
{{ $menuData := .context.Site.Data.menu }}
{{- $link := .context.Permalink }}
{{- $url := "" }}
{{- $name := "" }}
{{- $forwardSlash := "/" }}
{{- $children := false }}
{{- range $menu }}
  {{- if eq $menu $menuData }}
    {{- $children = .submenu }}
    {{- $name = .name }}
    {{- $url = absURL .link }}
  {{- else }}
    {{- $children = .Children }}
    {{- $name = .Name }}
    {{- $url = absLangURL .URL }}
  {{- end }}
  <div class="nav_parent{{ if (and (not .Children) (eq (trim $url $forwardSlash) (trim $link $forwardSlash))) }} nav_active{{ end}}">
    <a href="{{ $url }}" class="nav_item" title="{{ $name }}">{{ $name }} {{ with $children }}<img src='{{ absURL (printf "%s%s" $iconsDir "caret-icon.svg") }}' alt="icon" class="nav_icon">{{ end }}</a>
    {{- with $children }}
    <div class="nav_sub">
      <span class="nav_child"></span>
      {{- range . }}
        {{- if eq $menu $menuData }}
          {{- $name = .name }}
          {{- $url = absURL .link }}
        {{- else }}
          {{- $name = .Name }}
          {{- $url = absLangURL .URL }}
        {{- end }}
        <a href="{{ $url }}" class="nav_child nav_item" title="{{ $name }}">{{ $name }}</a>
      {{- end }}
    </div>
    {{- end }}
  </div>
{{- end }}

Line 1 and 20 has been changed.

I guess, I'm missing something here. I'm not an Hugo expert.

Other information

No response

onweru commented 1 year ago

Hi @stdevel, thanks, I will look into it.