Posts for: #Hugo

“Obviously, Dumbass”

If you eerily stalk my blog in ways that definitely make me uncomfortable, you might’ve noticed a minor change in my totients post. In the last section of code starting on line 25, you might notice that line 27 is now highlighted yellow. That accentuation was always intended to be there. The problem was that I had done it incorrectly, because I didn’t understand the fucking directions.

I was using:

```lang {linenostart=25,hl_lines=27}
Blah blah blah
Blah Blah blah
```

What I didn’t realize was that hl_lines is independent of linenostart. What does that mean? That means if I want line 27 highlighted in the code, I don’t set hl_lines=27. I set, in this particular example, hl_lines=3.

[]

Hugo Template Render Hooks

This was a tough nut to crack. I’m totally new to Go Html Templates and Go itself, and I’ve never really used anything outside of Jekyll. It took me a minute, but I wound up coming up with this:

{{ $image := (resources.Get .Destination) }}
{{ with $image }}
    {{ if eq $image.MediaType.SubType "svg" }}
        <a data-fancybox="image" href="{{ $image.RelPermalink }}" data-caption="{{ with $.Title }}{{ . }}{{ end }}">
            <img src="{{ $image.RelPermalink }}" {{ with $.Text }} alt="{{ . }}" {{ end }} {{ with $.Title}} title="{{ . }}"{{ end }} />
        </a>
    {{ else }}
        {{ $resize := .Fill "200x165 webp q80" }}
        <a data-fancybox="image" href="{{ $image.RelPermalink }}" data-caption="{{ with $.Title }}{{ . }}{{ end }}">
            <img src="{{ $resize.RelPermalink }}" {{ with $.Text }} alt="{{ . }}" {{ end }} {{ with $.Title}} title="{{ . }}"{{ end }} />
        </a>
    {{ end }}
{{ end }}

Apparently I have a *.svg file on my blog somewhere, because that was a thing I had to catch right away for this to work. So I had to move all my images out of static and into assets for it to work, first of all. Then I had to figure out how to query a parent context, so I could fill in Text and Title with the images. That’s what the $ is in $.Text. It’s the parent context outside of $image.

[]

Fancybox and Hugo Even

My theme apparently wraps every ![Image](source) in another set of <a href=""></a> tags that point to the source for the image. If you’re trying to generate galleries with a shortcode using fancyboxes, this default behavior is going to bite you in the ass. I forced the behavior to what I want/expect by copying assets/js/even.js and assets/js/main.js from themes/even into my blog root assets/js/. Then I hacked out the fancyboxes references in both files and regenerated. Boom, galleries work, and I didn’t lose anything of value in any previous posts. It’s a win/win for my specific situation.

[]

Lmfao

BEHOLD, FUCKING MEMES.

God damn, this thing is really flexible. Just added a layouts/shortcodes/gallery.html and slapped a little Go Html Template and some lightbox.js and whatever, and bing-o bang-o boom; motherfucker is an autogallery. BOOYAH, BITCH.

Cool as fuck.

Of course there’s a little more to it than that. Gotta do some page bundling as well, which is easy enough. Just run your hugo new post/2022-01-01-Title/index.md and dump your images into content/post/2022-01-01-Title/img.

[]

Pinning Posts in Hugo

Alright, in this post I’m going to show you how to pin posts in Hugo. But before you keep reading, I request you review the template you’re using and ensure it’s going to allow you to pin posts in the first place.

The thing you’re looking for is the index declaration in your index.html.

Example:

{{- define "content" -}}
  <section id="posts" class="posts">
    {{/* (index .Site.Paginate) */}}
    {{- $paginator := .Paginate (where (where .Site.RegularPages "Type" "post") ".Params.hiddenfromhomepage" "!=" true) }}
    {{- range $paginator.Pages -}}
      {{ .Render "summary" }}
    {{ end -}}
  </section>

For instance, in the above snipped, line number four is where you can find the $paginator that will tell you whether you’ll be able to pin posts. If you see mine, you’re good. Most are probably going to do this. If you see anything with “sortby” then you’re probably fucked, because your template is probably forcing your shit to sort by date, rather than just paginate as Hugo does by default.

[]