Files
log/tools/report-template.sh
jiantw83 e6fafd4132 feat(report): 新增工作日誌總結技能
What: 新增 jsc-log:report,把工作日誌總結成年報、月報、週報或日報,寫進 wiki REPORT_{HASH}。另加 tools/report-range.sh 算期間、tools/report-template.sh 解析範本,以及四份報表範本與報表目錄範本。
Why: worklog 只記單筆工作,累積起來沒有工具看得出一週或一個月做了什麼、什麼在卡。要總結只能自己翻頁面加總。
How: 期間換算交給系統的 date,不自己算閏年與週界;週次採 ISO-8601。範本解析採工作目錄優先,.jsc/templates/report-{period}.md 蓋過技能自帶的那份,專案要換格式不必改技能。資料讀 LOG_CONTENTS 列出的所有日誌頁,取工作日期落在期間內的條目,只加總條目真的寫了的數字。
Who: 工作日誌的期間總結。
2026-08-26 10:47:07 +08:00

63 lines
2.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env sh
# report-template.sh — 解析報表範本的位置(供 jsc-log:report 呼叫)。
# 用法:
# report-template.sh resolve {daily|weekly|monthly|yearly} [起始目錄]
# report-template.sh list [起始目錄]
#
# 解析順序:工作目錄的 .jsc/templates/report-{period}.md 優先,沒有才用技能自帶的
# templates/report-{period}.md。專案要自訂報表格式時,放一份同名檔案就換掉範本,
# 不必改技能。起始目錄省略時用目前工作目錄。
#
# 輸出(resolve):{絕對路徑}<TAB>{project|skill}
# 輸出(list):每種期間一行 {period}<TAB>{絕對路徑}<TAB>{project|skill}
#
# 結束碼: 0=找到 2=用法錯誤 3=兩處都找不到範本(技能自帶的那份被刪了)
set -eu
HERE=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
SKILL_TPL=$(CDPATH= cd -- "$HERE/.." && pwd)/templates
TAB=$(printf '\t')
usage() {
echo "用法:report-template.sh {resolve {daily|weekly|monthly|yearly} [起始目錄]|list [起始目錄]}" >&2
exit 2
}
resolve_one() { # $1=period $2=起始目錄
_p="$1"; _d="$2"
_proj="$_d/.jsc/templates/report-$_p.md"
if [ -f "$_proj" ]; then
printf '%s%s%s\n' "$_proj" "$TAB" project
return 0
fi
_skill="$SKILL_TPL/report-$_p.md"
if [ -f "$_skill" ]; then
printf '%s%s%s\n' "$_skill" "$TAB" skill
return 0
fi
return 3
}
cmd="${1:-}"
case "$cmd" in
resolve)
period="${2:-}"
case "$period" in daily|weekly|monthly|yearly) ;; *) usage ;; esac
dir="${3:-$PWD}"
dir=$(CDPATH= cd -- "$dir" 2>/dev/null && pwd) || { echo "找不到目錄:${3:-$PWD}" >&2; exit 2; }
resolve_one "$period" "$dir" || {
echo "找不到 report-$period.md:$dir/.jsc/templates/ 與 $SKILL_TPL 都沒有" >&2
exit 3
} ;;
list)
dir="${2:-$PWD}"
dir=$(CDPATH= cd -- "$dir" 2>/dev/null && pwd) || { echo "找不到目錄:${2:-$PWD}" >&2; exit 2; }
rc=0
for p in daily weekly monthly yearly; do
out=$(resolve_one "$p" "$dir") || { printf '%s\t-\tmissing\n' "$p"; rc=3; continue; }
printf '%s\t%s\n' "$p" "$out"
done
exit "$rc" ;;
*) usage ;;
esac