Revisions
This revisions table has been automatically generated
from the git
history
of this website repository, and the change
descriptions may not always be as useful as they
should.
You can consult the source of this file in its current
version here.
#+END_SRC
#+BEGIN_SRC sass :tangle site/style/plugins.sass
table
border-top : 2px solid black
border-bottom : 2px solid black
border-collapse : collapse
width : 35rem
td
border-bottom : 1px solid black
padding : .5em
#history .commit
font-size : smaller
font-family : 'Fira Code', monospace
width : 7em
text-align : center
#+END_SRC
*** Implementation
We use the built-in [[https://soupault.neocities.org/reference-manual/#widgets-preprocess-element][=preprocess_element=]] to implement, which means we need a
script which gets its input from the standard input, and echoes its output to
the standard input.
#+BEGIN_SRC toml :tangle soupault.conf
[widgets.generate-history]
widget = "preprocess_element"
selector = "#history"
command = 'scripts/history.sh templates/history.html'
action = "replace_content"
#+END_SRC
#+BEGIN_TODO
This plugin should be reimplemented using ~libgit2~ or other ~git~ libraries, in
a language more suitable than bash.
#+END_TODO
This plugin proceeds as follows:
1. Using an ad-hoc script, it generates a JSON containing for each revision
- The subject, date, hash, and abbreviated hash of the related commit
- The name of the file at the time of this commit
2. This JSON is passed to a mustache engine (~haskell-mustache~) with a
proper template
3. The content of the selected DOM element is replaced with the output of
~haskell-mustache~
This translates in Bash like this.
#+BEGIN_SRC bash :tangle scripts/history.sh :shebang "#!/usr/bin/bash"
function main () {
local file="${1}"
local template="${2}"
tmp_file=$(mktemp)
generate_json ${file} > ${tmp_file}
haskell-mustache ${template} ${tmp_file}
rm ${tmp_file}
}
#+END_SRC
The difficult part of this script is the definition of the =generate_json=
function. From a high-level perspective, this function is divided into three
steps.
1. We get an initial (but partial) set of data about the ~git~ commit of
~${file}~, from the most recent to the oldest
2. For each commit, we check whether or not ~${file}~ was renamed or not
3. Finally, we output a result (because we are writing a bash script)
#+BEGIN_SRC bash :tangle scripts/history.sh :noweb no-export
function generate_json () {
local file="${1}"
local logs=`<