Probabilistic ".Next" page override

I have an experimental feature that I would like to implement on my website. The general concept is to model all page -> page transitions as a probabilistic event.

  • In the case of a permalink from one page to another, you can say it is drawing from a distribution over pages with 100% chance on that permalink’d page.
  • In the experimental case, all words on a page function as “links” – they can send you to a page that is drawn from a distribution over a set of pages.

I see that Hugo already models a collection of pages for each page to support the .Next page-variable. Is there a way for me to flag a page such that the .Next operation is overridden by my own logic which does the probabilistic transition? I’m guessing this can be flagged as a custom front matter field.

One requirement is that, while the server-side may maintain a “prior” distribution of next pages for any given content page, I would like to be able to provide additional context with the next-page-request made from the frontend, such that the backend can produce a modified “posterior” distribution, i.e. a modified distribution based on the word that a user clicked.

Let me know if there is a path to implementing “customizability” of the .Next page handler. I am willing to contribute if desired, or simply fork and host my own custom version. Or, if there is already a way to implement my probabilistic feature, advice on how to best approach this within Hugo would be much appreciated. Thank you!

You need to understand that Hugo is a static site generator, so any clicks will not have any direct effect on .Next unless youth store away those values and use that data to somehow control the build.

If my website is a graph of pages and links between them, then what I originally had in mind does indeed treats pages/content as static, but links between them are dynamic and dependent on posterior context.

However, if what you’re saying is that both pages and links are statically generated and cannot be changed unless I were to, say, trigger a re-deploy, then that is a model I can work with as well. This would mean that I would rebuild my site on a periodic basis, i.e. training my model on a recorded clicks and interactions, and then producing an updated graph.

Pages and links are statically generated, yes. When you write .Next and generate your site, the result is determined at generation time — it isn’t somehow deferred to runtime.

One way to accomplish what you want is to emit all the possibilities into some JS collection, and then have your links probabilistically select the result in the user-agent. This is practical for smaller sites but would be problematic for larger sites.