urls.AbsURL
Syntax
urls.AbsURL 输入
Returns
string
Alias
absURL
对于多语言配置,请改用absLangURL
函数。该函数返回的URL取决于以下因素:
- 输入是否以斜杠开头
- 网站配置中的
baseURL
输入不以斜杠开头
如果输入不以斜杠开头,则无论baseURL
设置如何,得到的URL都是正确的。
假设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
输入以斜杠开头
如果输入以斜杠开头,并且baseURL
包含子目录,得到的URL将是不正确的。在有斜杠开头的情况下,该函数返回相对于baseURL
的协议+主机部分的URL。
假设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