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

     1  ---
     2  title: base64
     3  description: "`base64Encode` and `base64Decode` let you easily decode content with a base64 encoding and vice versa through pipes."
     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: []
    13  relatedfuncs: []
    14  signature: ["base64Decode INPUT", "base64Encode INPUT"]
    15  workson: []
    16  hugoversion:
    17  deprecated: false
    18  draft: false
    19  aliases: []
    20  ---
    21  
    22  An example:
    23  
    24  {{< code file="base64-input.html" >}}
    25  <p>Hello world = {{ "Hello world" | base64Encode }}</p>
    26  <p>SGVsbG8gd29ybGQ = {{ "SGVsbG8gd29ybGQ=" | base64Decode }}</p>
    27  {{< /code >}}
    28  
    29  {{< output file="base-64-output.html" >}}
    30  <p>Hello world = SGVsbG8gd29ybGQ=</p>
    31  <p>SGVsbG8gd29ybGQ = Hello world</p>
    32  {{< /output >}}
    33  
    34  You can also pass other data types as arguments to the template function which tries to convert them. The following will convert *42* from an integer to a string because both `base64Encode` and `base64Decode` always return a string.
    35  
    36  ```
    37  {{ 42 | base64Encode | base64Decode }}
    38  => "42" rather than 42
    39  ```
    40  
    41  ## `base64` with APIs
    42  
    43  Using base64 to decode and encode becomes really powerful if we have to handle
    44  responses from APIs.
    45  
    46  ```
    47  {{ $resp := getJSON "https://api.github.com/repos/gohugoio/hugo/readme"  }}
    48  {{ $resp.content | base64Decode | markdownify }}
    49  ```
    50  
    51  The response of the GitHub API contains the base64-encoded version of the [README.md](https://github.com/gohugoio/hugo/blob/master/README.md) in the Hugo repository. Now we can decode it and parse the Markdown. The final output will look similar to the rendered version on GitHub.