Random homepage post, random next item link and random class

I have a statamic site that’s looks a little bit like this site:

I want to change from statamic to hugo because I want my sites over at netlify. But first I have to know it the things I want are really possible.

  • When you go to the url it should go to a random post
  • When you click show next item it should get a random post url
  • When you go to a new post it should add a random class to the html/body

When that is possible I am ready to switch

The fundamental thing here is that Hugo is a static site generator. You can easily create “randomness” at build time (see shuffle etc.), but at runtime you need client side scripting to do that.

So rebuilding at interval could give you the “static randomness”, but I’m not sure Netlify supports cron type of deployments.

You can rebuild at intervals at Netlify with webhooks triggered by IFTTT or Zapier.

You could use client-side Javascript to randomly select a page if the Javascript code knows what URLs are valid.

Stupid from me, static and dynamic that’s never possible. I leave it like I have it right now and going to try hugo with a different kind of project. Thank you all!

I think the javascript solution is the best solution. I make a list.json with code

'use strict';

var _ = require('lodash');
var express = require('express');
var fs = require('fs');
var http = require('http');
var app = express();
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var cookieSession = require('cookie-session');

var pageCollector = (function(){
    var dir2read = '/Users/ari/Sites/mousikobostani.gitlab.io/public/post/';
    return {
        getFiles: function(res){
            fs.readdir(dir2read, function(err, files){
                if(err) throw err;
                console.log(files);
                res.json(files);
            });
        }
    };
})();

http.createServer(app).listen(process.env.PORT || 3612);


app.use(express.bodyParser());

app.get('/', function(req, res){
    pageCollector.getFiles(res);
})

and I put it to static folder.
Any help about how can I use it to select random item and open it.
Thanks in advance