Merge commit 'f96384a3b596f9bc0a3a035970b09b2c601f0ccb'

This commit is contained in:
Bjørn Erik Pedersen
2023-05-22 16:47:07 +02:00
341 changed files with 3107 additions and 4238 deletions

View File

@@ -1,71 +1,62 @@
---
title: urlize
# linktitle: urlize
description: Takes a string, sanitizes it for usage in URLs, and converts spaces to hyphens.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
categories: [functions]
menu:
docs:
parent: "functions"
parent: functions
keywords: [urls,strings]
signature: ["urlize INPUT"]
hugoversion:
deprecated: false
workson: []
relatedfuncs: []
---
The following examples pull from a content file with the following front matter:
{{< code file="content/blog/greatest-city.md" copy="false">}}
+++
{{< code-toggle file="content/blog/greatest-city.md" fm=true copy=false >}}
title = "The World's Greatest City"
location = "Chicago IL"
tags = ["pizza","beer","hot dogs"]
+++
{{< /code >}}
{{< /code-toggle >}}
The following might be used as a partial within a [single page template][singletemplate]:
{{< code file="layouts/partials/content-header.html" download="content-header.html" >}}
{{< code file="layouts/partials/content-header.html" >}}
<header>
<h1>{{.Title}}</h1>
<h1>{{ .Title }}</h1>
{{ with .Params.location }}
<div><a href="/locations/{{ . | urlize}}">{{.}}</a></div>
<div><a href="/locations/{{ . | urlize }}">{{ . }}</a></div>
{{ end }}
<!-- Creates a list of tags for the content and links to each of their pages -->
{{ with .Params.tags }}
<ul>
{{range .}}
{{ range .}}
<li>
<a href="/tags/{{ . | urlize }}">{{ . }}</a>
</li>
{{end}}
{{ end }}
</ul>
{{ end }}
</header>
{{< /code >}}
The preceding partial would then output to the rendered page as follows, assuming the page is being built with Hugo's default pretty URLs.
The preceding partial would then output to the rendered page as follows:
{{< output file="/blog/greatest-city/index.html" >}}
```html
<header>
<h1>The World&#39;s Greatest City</h1>
<div><a href="/locations/chicago-il">Chicago IL</a></div>
<ul>
<li>
<a href="/tags/pizza">pizza</a>
</li>
<li>
<a href="/tags/beer">beer</a>
</li>
<li>
<a href="/tags/hot-dogs">hot dogs</a>
</li>
</ul>
<h1>The World&#39;s Greatest City</h1>
<div><a href="/locations/chicago-il">Chicago IL</a></div>
<ul>
<li>
<a href="/tags/pizza">pizza</a>
</li>
<li>
<a href="/tags/beer">beer</a>
</li>
<li>
<a href="/tags/hot-dogs">hot dogs</a>
</li>
</ul>
</header>
{{< /output >}}
```
[singletemplate]: /templates/single-page-templates/