Hugo 0.24: The Revival of the Archetypes!

So, I was pondering “what should bep spend his spare time on for Hugo 0.24?”. Seeing an interesting SPA (single page application) type of JavaScript-heavy static generator announcing their first beta, I thought about how Hugo fits into this “static generator” landscape? The strengths?

Content. Lots of content.

There are more to it, of course, but I decided to have a look at archetypes, a very useful feature, but with some flaws that prevent it from being really useful.

So the issues I’m going to fix are these:

One of them is a plain bug fix. making sure that the archetype fields order/comments etc. are preserved as is.

The “archetype template” issue is more interesting.

  • The archetype files should be able to use all the Hugo template funcs.
  • It would also be cool if you could do .Site.GetPage, .Site.Pages, .Site.Title etc.
  • That would come at a cost for big sites, so it should maybe be optional.
  • Picking the “correct site” in a multilingual setup should be possible, but maybe also add a .Sites property with a .GetByLang or something method…?
3 Likes

I was actually googling around about the sorting issue this afternoon!

I only have about 20 posts at the moment, but could “Hugo convert” be persuaded to re-apply the desired order of the frontmatter onto existing posts? ie converting from my existing toml files to toml, would then apply the “correct” ordering?

The sorting issue was just starting to affect me so this is great news. Awesome.

It would be really cool if you could construct an array of pages in the archetype, creating “virtual sections”. For instance, I currently implement monthly archives by running a pre-build script that fills content/archive with MD files containing only:

+++
date = "$year-$month-01T00:00:00"
title = "$monthname $year"
month = "$year-$month"
+++

And then having the single template for the section do:

{{ $month := .Params.month }}
{{ range where (($.Site.GetPage "section" "post").Pages.GroupByDate "2006-01") "Key" $month }}
  {{ range .Pages.ByDate }}
    {{ partial "article-summary.html" . }}
  {{ end }}
{{ end }}

-j

No, that is outside of the scope of the mentioned issue, and would be too much work.

Let’s not get carried away. Archetypes will still create 1 content file.

:slight_smile:

Retracting my like…

I thought hugo was a program to automate the BS, but you leave the BS to me?!? BAH! :wink:

Simply iterate the files, apply the new logic, and re-emit the front-matter. Not sure why that is super hard…

I could do this local but to make this useful to others, it should be built in!

So you deliberately decided to limit this to new posts only, seems very arbitrary!

Make the upgrades EASY! or at least easier!

Since the new logic is “to apply no logic”, this is impossible. I suspect you do not understand what this feature is about. And having some old pages with a sub-optimal sort order is not the end of the world, it is of no practical difference.

uhm, what?!?

One of them is a plain bug fix. making sure that the archetype fields order/comments etc. are
preserved as is.

So this will happen, but only for NEW posts, right?

But not in the general case…
ie, I apply a new arch case, AND THEN NOTHING WHAT-SO-EVER happens because of ?!?

I am losing your meaning here…

I purposefully insert an arch type, and the archetype is then ignored, OK GOT IT. makes total sense… WTF?

If you have concrete questions/suggestions, I’m listening, but I don’t understand what you are talking about here. And you should consider toning down the ALL CAPS usage.

The new logic is to preserve the sort order. that is not anywhere near equivalent to “to apply no logic”… before you relied on the default go map behavior. Now, new logic!

How does this make sense?

Given a map:

B: B
A: A
C: C

Preserving sort order will give this:

B: B
A: A
C: C

Decoding into a Go map may (may, as in: The order is undefined) give something like this:

A: A
B: B
C: C

And since I dont’t know which archetype file that was used to create the file in the first place (if any), there is no way that I know about that lets me recreate the original sort order, and I don’t see the big point in doing so, either.

But please prove me wrong.

The concrete question/suggestion at hand is archetypes and how they are applied.

I insert a new archetype. Well, it arches over the site, right? it should apply to the WHOLE site, since it arches over all of it… RIGHT? The entire site falls under this arch.

Your change, while helping for new posts, does nothing to help is migrate to this new, great, wonderful place, of hugo-ness…

Hugo is supposed to automate the BS, but in this case, we do nothing… just leave the unsorted mess as is, and pass by…

The feature is good, and I think needed! Thanks for that! really…
But there is a middle step, migration! Make that easy!

Trying to help, not being argumentative… Sorry if my tone or CAPS was misperceived, and thecaps were intentional… AKA slashdot rules…

OK, I suspect we are talking about different things. This is about the archetype files / i.e. the page templates used by hugo new, i.e. the command used to create new content pages (blog post, articles).

I, too, suspect we are talking past each other…

But again an archetype, the literal meaning, is an over arching thing, over all the other things…

if this does not apply to the sub-things, like the entire site, then it is not an archetype!

Or rename it to archetypes-for-new-things-only…

key words in your post “hugo new”.

And I want hugo convert… I think therein lies the difference in our thoughts!

Ah, yes… Good point! But the current archetype should over-ride the default, as hugo does for everything else! And since it is a new archetype, I am explicitly creating an ARCHE-type after all, it should over-ride ALL other defaults. If I install a new theme, this means I want to see all my pages re-styled, with this great way of theming things… It should change everything… by default! New Theme, new Look! and hugo automates this. Saving me the BS of changing many files, right?

And since I don’t know which archetype file that was used to create the file in the first place (if any), there is no way that I know about that lets me recreate the original sort order, and I don’t see the big point in doing so, either.

Perhaps some meta bread-crumbing could be inserted, like "# inherited from “archetype” XYZ… if XYZ is deleted, remove those tags from no longer existing archs. No archetype, call that “default”… Then rebase the comment, from whatever default archetype is currently in scope? maybe single, summary, etc?

3 cases maybe?

  1. no archetype, emit a meta comment “Default Archetype” or none…
  2. “XYZ archetype applied”
  3. XYZ deleted, then --verbose shows, “XYZ meta retracted!”

/themes/whatever/archetype should be identifiable in the metadata as different from site/xyz/archeype/X

I think the intersection of Archetypes and Themes is where the fun stuff happens!
New theme, new archetypes, new website look and feel! Your way, that does not happen…

1 Like

OK, I suspect we are talking about different things. This is about the archetype files / i.e. the page templates used by hugo new, i.e. the command used to create new content pages (blog post, articles).

Yes, but WHICH page templates? The theme level, the site level? New theme to me implies a new look and feel to the site. Right?