I see that 0.13 brings support for dynamic content and wonder whether it would be possible to realize download counter with it?
There are pages on the web site containing links for audio (*.mp3) files and I’d like that whenever some visitor (public page) click and download some file, that it triggers some (probably) JS method and increase appropriate counter for the file, store it in JSON/CSV ‘database’ and then read from it and render the ‘download counter’ on the page besides file’s link.
You could accomplish something like this with Hugo + JS or something else. Hugo can render the pages from JSON file, but the pages will still be static HTML files. It will only change the values when you re-render the site.
You could accomplish something like this with Hugo + JS or something
else. Hugo can render the pages from JSON file, but the pages will
still be static HTML files. It will only change the values when you
re-render the site.
That’s acceptable and something I was thinking about: Hugo + JS + file
(JSON/CSV format) believing that there is no need for some ‘database’ as
suggested by bjornerik.
Oh you would definitely need server side state, but it could be a very simple script that modifies a JSON file. The point is you don’t need a database, you can so it really simply without any extra dependencies. I’m envisioning how the CGI counters worked in the 90’s. Just incremented to a file. It’s not very safe or secure, but it’s only a counter, so it may not need the extra complexity.
Best,Steve
Storing some value in a JSON / CSV is “server-side state” . My point is: This isn’t (in my head) solveable with Hugo alone, and not by Hugo + client side JS alone.
I know that this post is from '15 but does anyone have example code how to update on server json file?
Hugo is static builder and is not dynamic web server…i done in my blog page url links that downloads a file…file is read from json and retrieved its contents with $.getJSON and download link is increment by one and li span text is updated (it shows number of downloaded files)…then i $.ajax to call html page on server that needs to read local json file and update it. But as this is security restriction how can i do it in Hugo or shortcodes or any other way?
this is code that is calling on hugo server html file to update json file locally: