FirstSection
FirstSection
方法
section 是指頂層內容目錄,或是任何包含 _index.md 檔案的內容目錄。
考慮以下的內容結構:
content/
├── auctions/
│ ├── 2023-11/
│ │ ├── _index.md <-- 首個區段:auctions
│ │ ├── auction-1.md
│ │ └── auction-2.md <-- 首個區段:auctions
│ ├── 2023-12/
│ │ ├── _index.md
│ │ ├── auction-3.md
│ │ └── auction-4.md
│ ├── _index.md <-- 首個區段:auctions
│ ├── bidding.md
│ └── payment.md <-- 首個區段:auctions
├── books/
│ ├── _index.md <-- 首個區段:books
│ ├── book-1.md
│ └── book-2.md <-- 首個區段:books
├── films/
│ ├── _index.md <-- 首個區段:films
│ ├── film-1.md
│ └── film-2.md <-- 首個區段:films
└── _index.md <-- 首個區段:home
為了鏈接至當前頁面所屬的頂層區段,您可以使用以下代碼:
<a href="{{ .FirstSection.RelPermalink }}">{{ .FirstSection.LinkTitle }}</a>
這將返回當前頁面所在的頂層區段的連結,無論它是屬於 auctions
、books
還是其他區段。