mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
tpl/urls: Add JoinPath template function
See https://pkg.go.dev/net/url#JoinPath Closes #9694
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
03cb38e6c6
commit
5b3e165bad
24
docs/content/en/functions/urls.JoinPath.md
Normal file
24
docs/content/en/functions/urls.JoinPath.md
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
title: urls.JoinPath
|
||||
description: Joins the provided elements into a URL string and cleans the result of any ./ or ../ elements.
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
keywords: [urls,path,join]
|
||||
signature: ["urls.JoinPath ELEMENT..."]
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ urls.JoinPath "" }} → "/"
|
||||
{{ urls.JoinPath "a" }} → "a"
|
||||
{{ urls.JoinPath "a" "b" }} → "a/b"
|
||||
{{ urls.JoinPath "/a" "b" }} → "/a/b"
|
||||
{{ urls.JoinPath "https://example.org" "b" }} → "https://example.org/b"
|
||||
|
||||
{{ urls.JoinPath (slice "a" "b") }} → "a/b"
|
||||
```
|
||||
|
||||
Unlike the [`path.Join`] function, `urls.JoinPath` retains consecutive leading slashes.
|
||||
|
||||
[`path.Join`]: /functions/path.join/
|
Reference in New Issue
Block a user