website/include/functions.inc.shp

39 lines
1.3 KiB
Plaintext

<?shp
gen_titlebar() {
__tb_title="${1:-${TB_TITLE:-untitled}}"
__tb_color="${2:-${TB_COLOR:-random}}"
# make sure this matches /src/style/titlebars.css
set -- teal brown lgrey dgrey lblue purple white lblue dblue green pink
if [ "$__tb_color" = "random" ]; then
# gotta start with nonzero so printf doesn't interpret as octal
__d="1$(tr -Cd '[:digit:]' < /dev/urandom | dd bs=1 count=3 2>/dev/null)"
eval '__tb_color=${'$((__d % $# + 1))'}'
fi
printf '<div class="titlebar tb-%s" aria-hidden="true">
<span class="tbl" title="%s"></span>
<span class="tbr"></span>
</div>\n' "$__tb_color" "$__tb_title"
}
# get creation date via git, outputs in unix timestamp
# unless $2 is given. then it's as that format
# I don't actually use these two functions but I'm putting them here
# so I don't forget and just in case I *do* use them in the future
get_creation_time() {
if [ -z "$2" ]; then
git log --follow --date=unix --format=%ad --reverse -- "$1" | head -n 1
else
date -d "@$(git log --follow --date=unix --format=%ad --reverse -- "$1" | head -n 1)" +"$2"
fi
}
# get last modified date via git, outputs in unix timestamp
get_modified_time() {
if [ -z "$2" ]; then
git log --date=unix --format=%ad -1 -- "$1"
else
date -d "@$(git log --date=unix --format=%ad -1 -- "$1")" +"$2"
fi
}