HUGO

How to add ASCII art as comments to <HEAD>

You put so much work into your website, so it deserves some ASCII art on the <head> of every page.
However, Hugo removes all HTML comments by default. Here’s a recipe how to get them back in.

.1. Convert some (or type, if you’re hardcore hax0r):
L33t: http://www.robertecker.com/hp/research/leet-converter.php?lang=en
ASCII: http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20
.2. Once done, wrap your ASCII with HTML comments <!-- and -->> (that’s how you want it to be in the final HTML code).
.3. Paste everything into Unicode coverter: https://www.branah.com/unicode-converter
.4. Copy paste result into Sublime etc, then replace every line break with \n (I use Sublime Text multiple cursors and Home/End keys)
.5. Add your comment as a custom variable in global config.toml or config.yaml in Hugo:
For example, config.toml:

[params]
headercommentblock = "PASTEHEREYOURASCII"

Double-check that it’s a single line. If not, replace line breaks with \n.

.6. Call comments: in head using safeHtml:
{{ .Site.Params.headercommentblock | safeHtml }}

.7. Voilà!

3 Likes

Slick! Thanks, @royston!

ascii art in head

1 Like

For what it’s worth, I had to put this line in the toml, above the menus. At first I tried putting it under the menus, to keep it out of the middle of the config for my own legibility, but it did not work.

This worked:

[params]
    categoriescss = "/css/categories.css"
    sidebartitle = "Rick Cogley Central"
    etc
    headercommentblock = "\u003c\u0021\u002d\u002d\n              \u005f\u005fetcetcetc\n\u002d\u002d\u003e\n"
    etc
    [[menu.main]]
        name ="BlogCogley"
        url = "/post"

But this did not:

[params]
    categoriescss = "/css/categories.css"
    sidebartitle = "Rick Cogley Central"
    etc
    [[menu.main]]
        name ="BlogCogley"
        url = "/post"
    [[menu.etc]]
    etc
    headercommentblock = "\u003c\u0021\u002d\u002d\n              \u005f\u005fetcetcetc\n\u002d\u002d\u003e\n"

For reference, I got this error when rendering -

...
ERROR: 2015/04/23 template: partials/meta.html:4:37: executing "partials/meta.html" at <safeHtml>: wrong number of args for safeHtml: want 1 got 0 in partials/meta.html    
...

good stuff!