HUGO
Menu
GitHub 87548 stars Mastodon

Title

返回給定資源的標題(如在 front matter 中所定義),或回退到相對路徑或哈希文件名,具體取決於資源類型。

Syntax

RESOURCE.Title

Returns

string

Resource 對象上的 Title 方法返回的值取決於資源類型。

全局資源

使用 全局資源 時,Title 方法返回資源的路徑,相對於 assets 目錄。

assets/
└── images/
    └── Sunrise in Bryce Canyon.jpg
{{ with resources.Get "images/Sunrise in Bryce Canyon.jpg" }}
  {{ .Title }} → /images/Sunrise in Bryce Canyon.jpg
{{ end }}

頁面資源

使用 頁面資源 時,如果在 front matter 的 resources 數組中創建了一個元素,Title 方法返回 title 參數的值。

content/
├── example/
│   ├── images/
│   │   └── a.jpg
│   └── index.md
└── _index.md
---
resources:
- src: images/a.jpg
  title: A beautiful sunrise in Bryce Canyon
title: Example
---
+++
title = 'Example'
[[resources]]
  src = 'images/a.jpg'
  title = 'A beautiful sunrise in Bryce Canyon'
+++
{
   "resources": [
      {
         "src": "images/a.jpg",
         "title": "A beautiful sunrise in Bryce Canyon"
      }
   ],
   "title": "Example"
}
{{ with .Resources.Get "images/a.jpg" }}
  {{ .Title }} → A beautiful sunrise in Bryce Canyon
{{ end }}

如果您不在 front matter 的 resources 數組中創建元素,Title 方法返回文件路徑,相對於頁面包。

content/
├── example/
│   ├── images/
│   │   └── Sunrise in Bryce Canyon.jpg
│   └── index.md
└── _index.md
{{ with .Resources.Get "Sunrise in Bryce Canyon.jpg" }}
  {{ .Title }} → images/Sunrise in Bryce Canyon.jpg
{{ end }}

遠程資源

使用 遠程資源 時,Title 方法返回哈希文件名。

{{ with resources.GetRemote "https://example.org/images/a.jpg" }}
  {{ .Title }} → /a_18432433023265451104.jpg
{{ end }}

Last updated: January 1, 0001
Improve this page