fix(worklog): 下放 LOG 目標頁計算並統一 hash

This commit is contained in:
2026-08-21 16:53:17 +00:00
parent e70ee90efe
commit f81da60d02
9 changed files with 73 additions and 27 deletions
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env sh
# worklog-target.sh: 產生 worklog wiki 目標頁。
# 用法:
# worklog-target.sh <owner/repo> [hash|page|contents|all]
set -eu
usage() {
echo 'usage: worklog-target.sh <owner/repo> [hash|page|contents|all]' >&2
exit 2
}
[ "$#" -ge 1 ] || usage
[ "$#" -le 2 ] || usage
repo=$1
field=${2:-page}
if [ -z "$repo" ]; then
usage
fi
if command -v sha1sum >/dev/null 2>&1; then
raw=$(printf '%s' "$repo" | sha1sum | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
raw=$(printf '%s' "$repo" | shasum -a 1 | awk '{print $1}')
else
echo 'no SHA-1 helper found' >&2
exit 1
fi
hash=$(printf '%s' "$raw" | cut -c1-8 | tr a-f A-F)
case "$hash" in
[0-9ABC]*) hash="H$(printf '%s' "$hash" | cut -c1-7)" ;;
esac
page="LOG_${hash}"
contents='LOG_CONTENTS'
case "$field" in
hash) printf '%s\n' "$hash" ;;
page) printf '%s\n' "$page" ;;
contents) printf '%s\n' "$contents" ;;
all)
printf 'HASH=%s\n' "$hash"
printf 'PAGE=%s\n' "$page"
printf 'CONTENTS=%s\n' "$contents"
;;
*) usage ;;
esac