github.com/rabbouni145/gg@v0.47.1/docs/content/en/functions/urlize.md (about)

     1  ---
     2  title: urlize
     3  # linktitle: urlize
     4  description: Takes a string, sanitizes it for usage in URLs, and converts spaces to hyphens.
     5  date: 2017-02-01
     6  publishdate: 2017-02-01
     7  lastmod: 2017-02-01
     8  categories: [functions]
     9  menu:
    10    docs:
    11      parent: "functions"
    12  keywords: [urls,strings]
    13  godocref:
    14  signature: ["urlize INPUT"]
    15  hugoversion:
    16  deprecated: false
    17  workson: []
    18  relatedfuncs: []
    19  ---
    20  
    21  The following examples pull from a content file with the following front matter:
    22  
    23  {{< code file="content/blog/greatest-city.md" copy="false">}}
    24  +++
    25  title = "The World's Greatest City"
    26  location = "Chicago IL"
    27  tags = ["pizza","beer","hot dogs"]
    28  +++
    29  {{< /code >}}
    30  
    31  The following might be used as a partial within a [single page template][singletemplate]:
    32  
    33  {{< code file="layouts/partials/content-header.html" download="content-header.html" >}}
    34  <header>
    35      <h1>{{.Title}}</h1>
    36      {{ with .Params.location }}
    37          <div><a href="/locations/{{ . | urlize}}">{{.}}</a></div>
    38      {{ end }}
    39      <!-- Creates a list of tags for the content and links to each of their pages -->
    40      {{ with .Params.tags }}
    41      <ul>
    42          {{range .}}
    43              <li>
    44                  <a href="/tags/{{ . | urlize }}">{{ . }}</a>
    45              </li>
    46          {{end}}
    47      </ul>
    48      {{ end }}
    49  </header>
    50  {{< /code >}}
    51  
    52  The preceding partial would then output to the rendered page as follows, assuming the page is being built with Hugo's default pretty URLs.
    53  
    54  {{< output file="/blog/greatest-city/index.html" >}}
    55  <header>
    56      <h1>The World's Greatest City</h1>
    57      <div><a href="/locations/chicago-il/">Chicago IL</a></div>
    58      <ul>
    59          <li>
    60              <a href="/tags/pizza">pizza</a>
    61          </li>
    62          <li>
    63              <a href="/tags/beer">beer</a>
    64          </li>
    65          <li>
    66              <a href="/tags/hot-dogs">hot dogs</a>
    67          </li>
    68      </ul>
    69  </header>
    70  {{< /output >}}
    71  
    72  
    73  [singletemplate]: /templates/single-page-templates/