Skip to content

Commit

Permalink
feat: create last-modified mapping
Browse files Browse the repository at this point in the history
Whenever this package is built in CI a module
`modules/frus.xqm` is added to the built XAR.

This can then be used to optimize caching in hsg-shell.
  • Loading branch information
line-o committed Jan 17, 2025
1 parent 27b0848 commit 4ee3e87
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ jobs:
run: |
mkdir -p frus-toc
java -jar /usr/share/java/Saxon-HE.jar -s:volumes/ -xsl:modules/lib/frus-toc.xsl -o:frus-toc/ -it:main
- name: Create frus.xqm
run: |
./create-last-modified-module.sh bibliography/* volumes/* > modules/frus.xqm
# sanity check
- name: What happened
run: git status
Expand Down
36 changes: 36 additions & 0 deletions create-last-modified-module.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

# -----------------------------------------------------------------------------
# create an XQuery module
# exporting a map mapping relative file paths to their last commit date

# -----------------------------------------------------------------------------
# USAGE:
# ./create-last-modified-module.sh volumes/* bibliography/* > modules/frus.xqm

# -----------------------------------------------------------------------------
# build list of mappings

# helper function
# USAGE: join $separator $list
function join {
echo -n "$2"
[[ $# -gt 2 ]] && printf "$1%s" "${@:3}"
}

list=()

for file in "${@}"
do
iso=`git log -1 --format=%cd --date=iso-strict-local "$file"`
list+=" '$file': xs:dateTime('$iso')"
done

# -----------------------------------------------------------------------------
# output module

echo 'module namespace frus="http://history.state.gov/ns/site/frus/last-modified";'
echo "\n"
echo 'declare variable $frus:lm := map{';
join ",\n" $list
echo "\n};"

0 comments on commit 4ee3e87

Please sign in to comment.