github.com/jbramsden/hugo@v0.47.1/docs/content/en/functions/relurl.md (about)

     1  ---
     2  title: relURL
     3  description: Given a string, prepends the relative URL according to a page's position in the project directory structure.
     4  godocref:
     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]
    13  signature: ["relURL INPUT"]
    14  workson: []
    15  hugoversion:
    16  relatedfuncs: [absURL]
    17  deprecated: false
    18  aliases: []
    19  ---
    20  
    21  Both `absURL` and `relURL` consider the configured value of `baseURL` in your site's [`config` file][configuration]. Given a `baseURL` set to `https://example.com/hugo/`:
    22  
    23  ```
    24  {{ "mystyle.css" | absURL }} → "https://example.com/hugo/mystyle.css"
    25  {{ "mystyle.css" | relURL }} → "/hugo/mystyle.css"
    26  {{ "http://gohugo.io/" | relURL }} →  "http://gohugo.io/"
    27  {{ "http://gohugo.io/" | absURL }} →  "http://gohugo.io/"
    28  ```
    29  
    30  The last two examples may look strange but can be very useful. For example, the following shows how to use `absURL` in [JSON-LD structured data for SEO][jsonld] where some of your images for a piece of content may or may not be hosted locally:
    31  
    32  {{< code file="layouts/partials/schemaorg-metadata.html" download="schemaorg-metadata.html" >}}
    33  <script type="application/ld+json">
    34  {
    35      "@context" : "http://schema.org",
    36      "@type" : "BlogPosting",
    37      "image" : {{ apply .Params.images "absURL" "." }}
    38  }
    39  </script>
    40  {{< /code >}}
    41  
    42  The above uses the [apply function][] and also exposes how the Go template parser JSON-encodes objects inside `<script>` tags. See [the safeJS template function][safejs] for examples of how to tell Hugo not to escape strings inside of such tags.
    43  
    44  {{% note "Ending Slash" %}}
    45  `absURL` and `relURL` are smart about missing slashes, but they will *not* add a closing slash to a URL if it is not present.
    46  {{% /note %}}
    47  
    48  [apply function]: /functions/apply/
    49  [configuration]: /getting-started/configuration/
    50  [jsonld]: https://developers.google.com/search/docs/guides/intro-structured-data
    51  [safejs]: /functions/safejs