aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMiroslav Kratochvil <miroslav.kratochvil@uni.lu>2023-06-22 11:43:39 +0200
committerMiroslav Kratochvil <miroslav.kratochvil@uni.lu>2023-06-22 11:43:39 +0200
commit2ea84315db882c3341ae25f0fe2591a2de109d49 (patch)
treef1acf23252898ff53fede0d38d71a4f653763e33 /scripts
parent73d1920b6296bf73fbef87c9e8460cd5d2c2071e (diff)
parenta2dd9384b4e0eb67346848bdb90a35b039640669 (diff)
downloadreploy-2ea84315db882c3341ae25f0fe2591a2de109d49.tar.gz
reploy-2ea84315db882c3341ae25f0fe2591a2de109d49.tar.bz2
Merge branch 'mk-modification-timestamps' into 'master'
add a script for sourcing the timestamps from gits Closes #2 See merge request R3-core/websites-dev/reploy!3
Diffstat (limited to 'scripts')
-rw-r--r--scripts/make-search-index.js39
-rwxr-xr-xscripts/source-timestamps.sh28
2 files changed, 67 insertions, 0 deletions
diff --git a/scripts/make-search-index.js b/scripts/make-search-index.js
new file mode 100644
index 0000000..37c5ce5
--- /dev/null
+++ b/scripts/make-search-index.js
@@ -0,0 +1,39 @@
+
+/*
+ * make-search-index.js
+ *
+ * This converts a "search data" file produced by the haskell site builder into
+ * a lunr.js index and saves it in JSON. Metadata for rendering search output
+ * (currently titles and tags) are stored separately in an extra file.
+ *
+ * Installing dependencies:
+ * yarnpkg add lunr
+ *
+ * Usage:
+ * site ....some args.... --search-data-output tmp/search-raw.json
+ * node scripts/make-search-index.js tmp/search-raw.json _site/search-index.json _site/search-metadata.json
+ */
+
+lunr = require("lunr")
+fs = require("fs")
+
+if(process.argv.length !== 5) {
+ console.error('Needs exactly 3 arguments (input json, output index).');
+ process.exit(1);
+}
+
+documents = JSON.parse(fs.readFileSync(process.argv[2], {encoding: 'utf8'}))
+
+var idx = lunr(function () {
+ this.ref('link')
+ this.field('title', {boost: 10})
+ this.field('text')
+ documents.forEach(function (doc) {
+ this.add(doc)
+ }, this)
+})
+
+fs.writeFileSync(process.argv[3], JSON.stringify(idx), {encoding: 'utf8'})
+fs.writeFileSync(process.argv[4], JSON.stringify(
+ Object.fromEntries(documents.map(x => [x.link, {"title": x.title, "tags": x.tags}]))
+ ), {encoding: 'utf8'})
diff --git a/scripts/source-timestamps.sh b/scripts/source-timestamps.sh
new file mode 100755
index 0000000..74ff9f0
--- /dev/null
+++ b/scripts/source-timestamps.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# change this with environment
+DEFAULT_NOT_SOURCE_REGEX="/\\/assets\\//"
+NOT_SOURCE_REGEX="${NOT_SOURCE_REGEX:-$DEFAULT_NOT_SOURCE_REGEX}"
+TIMESTAMP_SUFFIX="${SUFFIX:-.timestamp}"
+LOGFILE="${LOGFILE:-/dev/null}"
+
+[ -z "$1" ] && echo "$0: no inputs specified?" >/dev/stderr
+
+while [ -n "$1" ]
+do
+ echo "sourcing directory '$1' ..." >> "$LOGFILE"
+ find "$1" -type f -name '*.md' | grep -v "$NOT_SOURCE_REGEX" | while read file ; do
+ fn=`basename "$file"`
+ dir=`dirname "$file"`
+ tsfn="$fn.timestamp"
+ (
+ echo "making timestamp in '$dir' for file '$fn' ..." >> "$LOGFILE"
+ cd "$dir"
+ if [ -f "$tsfn" ]
+ then echo "... but it already exists; skipping!" >> "$LOGFILE"
+ else git log -n 1 --pretty=format:%cs -- "$fn" > "$tsfn"
+ fi
+ )
+ done
+ shift
+done