hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

absurl.md (1901B)

    1 ---
    2 title: absURL
    3 description: Creates an absolute URL based on the configured baseURL.
    4 date: 2017-02-01
    5 publishdate: 2017-02-01
    6 lastmod: 2017-02-01
    7 categories: [functions]
    8 menu:
    9   docs:
   10     parent: "functions"
   11 keywords: [urls]
   12 signature: ["absURL INPUT"]
   13 workson: []
   14 hugoversion:
   15 relatedfuncs: [relURL]
   16 deprecated: false
   17 aliases: []
   18 ---
   19 
   20 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/`:
   21 
   22 ```
   23 {{ "mystyle.css" | absURL }} → "https://example.com/hugo/mystyle.css"
   24 {{ "mystyle.css" | relURL }} → "/hugo/mystyle.css"
   25 {{ "http://gohugo.io/" | relURL }} →  "http://gohugo.io/"
   26 {{ "http://gohugo.io/" | absURL }} →  "http://gohugo.io/"
   27 ```
   28 
   29 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 (SEO)][jsonld], where some of your images for a piece of content may or may not be hosted locally:
   30 
   31 {{< code file="layouts/partials/schemaorg-metadata.html" download="schemaorg-metadata.html" >}}
   32 <script type="application/ld+json">
   33 {
   34     "@context" : "http://schema.org",
   35     "@type" : "BlogPosting",
   36     "image" : {{ apply .Params.images "absURL" "." }}
   37 }
   38 </script>
   39 {{< /code >}}
   40 
   41 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.
   42 
   43 {{% note "Ending Slash" %}}
   44 `absURL` and `relURL` are smart about missing slashes, but they will *not* add a closing slash to a URL if it is not present.
   45 {{% /note %}}
   46 
   47 [apply function]: /functions/apply/
   48 [configuration]: /getting-started/configuration/
   49 [jsonld]: https://developers.google.com/search/docs/guides/intro-structured-data
   50 [safejs]: /functions/safejs