diff options
| Commit | 8f5543f45eefc4211522c9eac84a22379fbc7636 (patch) | |
|---|---|---|
| Author | 2023-01-09 23:09:18 +0200 | |
| Committer | 2023-01-09 23:09:18 +0200 | |
| Files | cb603b54b8d6f06ce6ba4bb913c2d661031d4ea5 /generate-hooks | |
| syndamia.com-8f5543f45eefc4211522c9eac84a22379fbc7636.tar syndamia.com-8f5543f45eefc4211522c9eac84a22379fbc7636.tar.gz syndamia.com-8f5543f45eefc4211522c9eac84a22379fbc7636.zip | ||
| Parent | 2be7266903fbcdcaf87a97c02905e9fae99e542e (diff) | |
[hooks] Created a below header generation hook and removed old manual dates
1 files changed, 51 insertions, 0 deletions
| -rw-r--r-- | generate-hooks/create-pagenav.awk | 51 |
diff --git a/generate-hooks/create-pagenav.awk b/generate-hooks/create-pagenav.awk new file mode 100644 index 0000000..c7a8a05 --- /dev/null +++ b/generate-hooks/create-pagenav.awk @@ -0,0 +1,51 @@ +# +# == About == +# +# I call pagenav the stuff directly below the first h1. These include file dates +# and GitLab source link. +# Currently it only works for blog and tutorial pages. +# +# This is by far the most hard-coded and inefficient awk script in the generate-hooks. +# Creation and last edited dates are taken from git commits, and getting the correct info +# by file name can easily only be done with git log, which unfortunately is very slow. +# Another issue is that it depends on the build directories in build scripts, meaning +# it won't work without modification if you try to build it somewhere else. + +BEGIN { + fileCheck = ARGV[1] # FILENAME isn't available in BEGIN + + if (match(fileCheck, /(blog|tutorials)\/.*\//) == 0) { + found = 1 + } + else { + found = 0 + gsub(/^.*\/(synd|tiny.synd|website|tiny.website)\//, "", fileCheck); gsub(/\.html/, ".md", fileCheck) + + system("git log --follow --pretty=format:%ad --date=\"format:%d %B %Y\" -- src/" fileCheck " > /tmp/syndamiadotcom-pagenav") + + dateCreate = "" + dateEdited = "" + while ((getline < "/tmp/syndamiadotcom-pagenav") > 0) { + if (dateEdited == "") dateEdited = $0 + dateCreate = $0 + } + + elem = ORS \ +"<p>" ORS \ +" <a href=\"https://gitlab.com/Syndamia/syndamiadotcom/-/blob/master/src/" fileCheck "\">" ORS \ +" <strong>Article Source</strong>" ORS \ +" </a>" ORS \ +" <br>" ORS \ +" <strong>Created: " dateCreate "</strong> || <strong>Edited: " dateEdited "</strong>" ORS \ +"</p><br>" + } +} + +{ + print +} + +found == 0 && /<h1.*/ { + print elem + found = 1 +} |