urls.AbsURL

在多語言配置中,請改用 urls.AbsLangURL 函數。該函數返回的 URL 取決於以下因素:

  • 輸入是否以斜線開頭
  • 網站配置中的 baseURL

輸入未以斜線開頭

如果輸入未以斜線開頭,則生成的 URL 中的路徑將相對於網站配置中的 baseURL

baseURL = https://example.org/ 時:

{{ absURL "" }}          → https://example.org/
{{ absURL "articles" }}  → https://example.org/articles
{{ absURL "style.css" }} → https://example.org/style.css

baseURL = https://example.org/docs/ 時:

{{ absURL "" }}          → https://example.org/docs/
{{ absURL "articles" }}  → https://example.org/docs/articles
{{ absURL "style.css" }} → https://example.org/docs/style.css

輸入以斜線開頭

如果輸入以斜線開頭,則生成的 URL 中的路徑將相對於 baseURL 中的協議和主機部分。

baseURL = https://example.org/ 時:

{{ absURL "/" }}          → https://example.org/
{{ absURL "/articles" }}  → https://example.org/articles
{{ absURL "/style.css" }} → https://example.org/style.css

baseURL = https://example.org/docs/ 時:

{{ absURL "/" }}          → https://example.org/
{{ absURL "/articles" }}  → https://example.org/articles
{{ absURL "/style.css" }} → https://example.org/style.css