HUGO

Calculating with dates

I am playing around with my Netlify headers/redirection/robots component. Right now I expire locally cached pages by hardcoding this years last day into the file for the Expires header.

Expires: Tue, 31-Dec-2020 23:59:59 GMT+0700

Is it somehow possible in Golang to formulate something like {{ today + 1 year }}?

I know that the cache control header perfectly does what I want to achieve, but there are too many clients, setups and use cases, that ignore that header and look for the Expires header.

Cache-Control: public, max-age=31536000, immutable

See https://golang.org/pkg/time/#Time.AddDate

1 Like

Netlification … cool.

A little tip, and I’m sure you know about and have considered this:

Hugo Modules allows mono-repos, see https://github.com/gohugoio/hugo-mod-jslibs for an example – the sub folders can be versioned individually.

1 Like

Perfect. The following does the trick:

Expires: {{ now.AddDate 1 0 0 | dateFormat "Mon, 02-Jan-2006 15:04:05 GMT-0700" }}

(1 for a year, 0 months, 0 days).

I am trying to wrap my head around Hugo modules, at least once a month, last time yesterday and somehow it does not compute, yet… Those modules just don’t show up in my repos. Won’t take much longer to get it running though. :slight_smile: I’ll check out hugo-mod-jslibs.

offtopic: hi @bep, can you point me to a doc that describes how to “version” modules in a monorepo for hugo? I did create github packages until I realized that that makes no sense for Go or Hugo at all. Is it just a github release foldername/versionnumber or is there something deeper behind it?

I moved my Hugo components into what I believe to be a monorepo :wink: but I am not sure about that last step. https://github.com/davidsneighbour/dnb-hugo

Nothing deeper that I know about; it’s that and you also ned to add the folder to the path when init/importing the module. I think it works great, and removes some administration for modules that are somewhat connected (esp. considering you can do hugo mod get -u ./... from the root to update all upstream deps recursively) …

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.