如何在Go Hugo中将重复的YAML查询值简化为唯一值?

问题描述

  • 我使用Go Hugo;

  • 我使用YAML代替TOML;

  • 完整的YAML查询

    • 您可以看到thead > tr > th@H_404_15@的“名称”和“预览”值是如何重复的;
    • tbody > tr > td@H_404_15@也重复出现:
icons:
  - name: adwaita-plus
    title: Adwaita++
    table:
      thead:
        - tr:
          - th: Name
          - th: Preview
      tbody:
        - tr:
          - th: adwaita
            td:
              - apps
              - documents
              - downloads
        - tr:
          - th: aubergine
            td:
              - apps
              - documents
              - downloads
        - tr:
          - th: blue
            td:
              - apps
              - documents
              - downloads

  - name: suru-plus
    title: Suru++
    table:
      thead:
        - tr:
          - th: Name
          - th: Preview
      tbody:
        - tr:
          - th: "90ssummer"
            td:
              - apps
              - documents
              - downloads
        - tr:
          - th: aubergine
            td:
              - apps
              - documents
              - downloads
        - tr:
          - th: aurora
            td:
              - apps
              - documents
              - downloads
@H_404_15@

我简化为:

tbody:
  - tr:
    - th: 
        - "90ssummer"
        - aubergine
        - aurora
      td:
        - apps
        - documents
        - downloads
@H_404_15@

tbody:
  - tr:
    - th: "90ssummer"
    - th: aubergine
    - th: aurora
      td:
        - apps
        - documents
        - downloads
@H_404_15@

但是这些查询无效。我不知道如何简化值thead > tr > th@H_404_15@“名称”和“预览”。

如果您想查看小的Go Hugo HTML代码

{{ $path := "/assets/images/icons/"}}
{{ $data := (index .Site.Data.themes .Site.Language.Lang) }}

{{ range $data.themes.icons }}
  {{ $iconi := . }} 
  {{/*  $iconi = $data[icons][i]  */}}

  {{/*  {{ $iconi.name }}  */}}
  <h1>{{ $iconi.title }}</h1>

  {{ $table := $iconi.table }}
  
  {{ $thead := $table.thead }}
  {{ $tbody := $table.tbody }}
  
  <table>
  <thead>
  {{/* begin range $thead */}}
  {{ range $thead }}
    {{ $theadi := . }} 
    {{/*  begin range $theadi */}}
    {{ range $theadi }}
    {{ $tr := . }}
    {{/*  begin range $tr */}}
      <tr>
        {{ range $tr }}
          {{ $tri := . }}
          {{ $th := $tri.th }}
          <th class="c">
            {{ $th }}
          </th>
        {{ end }}
      </tr>
    {{/* end range $tr */}}
    {{ end }}
    {{/*  end range $theadi */}}
  {{ end }}
  {{/* end range $thead */}}
  </thead>

  {{/*  begin range $tbody */}}
  <tbody>
    {{ range $tbody }}
      {{ $tbodyi := . }}
      {{/*  begin range $tbodyi  */}}
      {{ range $tbodyi }}
        {{ $tr := . }}
        {{/*  begin range $tr */}}
        <tr>
          {{ range $tr }}
            {{ $tri := . }}
    
            {{ $td := $tri.td }}
            {{ $th := $tri.th }}
            
            <th>
              {{ $th }}
            </th>
            <td>
              {{ range $td }}
                <img alt="folder-{{ $th }}-{{ . }}" class="icons" src="{{ $path}}{{ $iconi.name }}/folder-{{ $th }}-{{ . }}.svg">
              {{ end }}
            </td>
    
          {{ end }} {{/* end range $tr */}}
        </tr>
      {{ end }} {{/*  end range $tbodyi */}}
    {{ end }} {{/*  end range $tbody  */}}
  </tbody>

  </table>

{{ end }}
@H_404_15@

外观如何:

preview of table example

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)