file-translating-p同时支持新旧模板

This commit is contained in:
darksun 2018-11-25 14:33:29 +08:00
parent d35302173d
commit 7ad23152c2
2 changed files with 18 additions and 13 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# 重新生成badge # 重新生成status data
set -o errexit set -o errexit
SCRIPTS_DIR=$(cd $(dirname "$0") && pwd) SCRIPTS_DIR=$(cd $(dirname "$0") && pwd)

View File

@ -1,27 +1,32 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
cd "$(dirname $0)/../.." # 进入TP root cd "$(dirname "$0")/../.." # 进入TP root
function file-translating-p () function file-translating-p ()
{ {
local file="$*" local file="$*"
head -n 3 "$file" |grep -E -i "translat|fanyi|翻译" >/dev/null 2>&1 if head -n 1 "${file}" |grep '\[^#\]:'>/dev/null 2>&1 ;then
# 新模板
head -n 12 "$file" |grep -v '\[^#\]:' |grep -E -i "translat|fanyi|翻译" >/dev/null 2>&1
else
# 旧模板
head -n 3 "$file" |grep -E -i "translat|fanyi|翻译" >/dev/null 2>&1
fi
} }
function get_status_of() function get_status_of()
{ {
local file="$@" local file="$*"
git log --date=short --pretty=format:"{\"file\":\"${file}\",\"time\":\"%ad\",\"user\":\"%an\"}" -n 1 "${file}" git log --date=short --pretty=format:"{\"file\":\"${file}\",\"time\":\"%ad\",\"user\":\"%an\"}" -n 1 "${file}"
} }
translating=$( git grep -niE "translat|fanyi|翻译" sources/*.md |awk -F ":" '{if ($2<=3) print $1}' |xargs -I{} git log --date=short --pretty=format:"{\"filename\":\"{}\",\"time\":\"%ad\",\"user\":\"%an\"}" -n 1 "{}") while read -r file;do
unselected=$( if file-translating-p "${file}";then
find sources -name "2*.md"|sort|while read file;do translating="${translating} $(get_status_of "${file}")"
if ! file-translating-p "${file}";then else
get_status_of "${file}" unselected="${unselected} $(get_status_of "${file}")"
fi fi
done done< <(find sources -name "2*.md")
)
( (
echo ${translating}|jq -s "." echo "${translating}"|jq -s "."
echo ${unselected} |jq -s "." echo "${unselected}"|jq -s "."
)|jq -s '{"translating":.[0],"unselected":.[1]}' )|jq -s '{"translating":.[0],"unselected":.[1]}'