urls.Ref
第一個參數是用於解析相對路徑的頁面上下文,通常是當前頁面。
第二個參數是頁面的路徑,可包含或不包含檔案副檔名,也可包含或不包含錨點。未以 /
開頭的路徑會先相對於給定的上下文解析,然後再解析為網站的其餘部分。或者,可以改為提供 選項映射。
{{ ref . "about" }}
{{ ref . "about#anchor" }}
{{ ref . "about.md" }}
{{ ref . "about.md#anchor" }}
{{ ref . "#anchor" }}
{{ ref . "/blog/my-post" }}
{{ ref . "/blog/my-post.md" }}
選項
除了指定路徑外,也可以提供選項映射:
- path
- (
string
)相對於內容目錄的頁面路徑。必填。 - lang
- (
string
)要搜尋頁面的語言(網站)。預設為當前語言。選填。 - outputFormat
- (
string
)要搜尋頁面的輸出格式。預設為當前輸出格式。選填。
要傳回頁面的另一語言版本的絕對永久連結:
{{ ref . (dict "path" "about.md" "lang" "fr") }}
要傳回頁面的另一輸出格式的絕對永久連結:
{{ ref . (dict "path" "about.md" "outputFormat" "rss") }}
預設情況下,如果 Hugo 無法解析路徑,會拋出錯誤並終止建置。您可以在網站配置中將此行為改為警告,並指定當無法解析路徑時返回的 URL。
hugo.
refLinksErrorLevel: warning
refLinksNotFoundURL: /some/other/url
refLinksErrorLevel = 'warning'
refLinksNotFoundURL = '/some/other/url'
{
"refLinksErrorLevel": "warning",
"refLinksNotFoundURL": "/some/other/url"
}