YehYeh 記事本2.0

Version 0.8.3

竹科碼農的記事本

Section 的變數及方法

Section的定義

  1. content資料夾裡的第1級目錄
  2. content資料夾裡,不是第1級目錄的話,目錄裡要有_index.md才會被視為一個section

section tree - 巢狀Sections

content
└── blog        <-- Section, because first-level dir under content/
    ├── funny-cats
    │   ├── mypost.md
    │   └── kittens         <-- Section, because contains _index.md
    │       └── _index.md
    └── tech                <-- Section, because contains _index.md
        └── _index.md

.CurrentSection

  • page目前的section
  • 如果page本身是section或是首頁,則 .CurrentSection = .page

.FirstSection

  • 根目錄的第1級section
  • EX: /docs, /blog,…

.InSection $anotherPage

  • 指定的$anotherPage是否在目前的Section裡

.IsDescendant $anotherPage

  • 目前的page是否為指定$anotherPage的子孫

.Parent

  • 一個section的父section 或 一個page的section

.Section

  • 目前內容所屬於的section
  • 對於巢狀的section會是 根section
    • /blog/funny/mypost/ => blog

.Sections

  • 目前內容所屬於的sections

麵包屑導航 breadcrumbnav

<ol  class="nav navbar-nav">
    <!--傳入參數 "p1" = .,  "p2" = . -->
    {{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
</ol>


{{ define "breadcrumbnav" }}

    {{ if .p1.Parent }}        
        <!--傳入參數 "p1" = .p1.Parent,  "p2" =.p2-->
        {{ template "breadcrumbnav" (dict "p1" .p1.Parent "p2" .p2 )  }}
    {{ else if not .p1.IsHome }}
        <!--傳入參數 "p1" = .p1.Site.Home,  "p2" =.p2 -->
        {{ template "breadcrumbnav" (dict "p1" .p1.Site.Home "p2" .p2 )  }}
    {{ end }}

    <li{{ if eq .p1 .p2 }} class="active"{{ end }}>
        <a href="{{ .p1.Permalink }}">{{ .p1.Title }}</a>
    </li>

{{ end }}
Last updated on 2020-04-19
Published on 2020-04-19
Edit on GitHub