66 is_index :
77 type : boolean
88
9-
109jobs :
1110
1211 convert :
@@ -33,23 +32,82 @@ jobs:
3332 name : converted
3433 path : pages
3534
35+ - name : Checkout book.xml
36+ if : ${{ !inputs.is_index }}
37+ uses : actions/checkout@v6
38+ with :
39+ sparse-checkout : |
40+ en/${{ jobs.convert.outputs.chm_name }}/book.xml
41+ sparse-checkout-cone-mode : false
42+ path : book
43+
3644 - name : Install tools
3745 run : |
3846 sudo apt-get install -y webp minify parallel
3947
4048 - name : Setup Optimization Helpers
4149 run : |
4250 cat << 'EOF' > helpers.sh
51+ get_source_path() {
52+ local file=$1
53+
54+ file="${file#pages/}"
55+
56+ if [ "${{ inputs.is_index }}" = "true" ]; then
57+ if [[ "$file" =~ ^[a-z]{2}/ ]] || [[ "$file" =~ ^programming/ ]]; then
58+ echo "index/${file}"
59+ else
60+ echo "converter/templates/wwwroot/${file}"
61+ fi
62+ else
63+ if [[ "$file" =~ ^[a-z]{2}/ ]]; then
64+ local lang="${file%%/*}"
65+ echo "${lang}/${{ jobs.convert.outputs.chm_name }}/${file#*/}"
66+ else
67+ if [[ "$file" != */index.html ]]; then
68+ echo "$file"
69+ return
70+ fi
71+
72+ # Find the url needed in the book.xml
73+ local dir_path="${file%/index.html}"
74+ local last_folder="${dir_path##*/}"
75+ local lang="en"
76+ local url=""
77+
78+ if [[ "$last_folder" =~ ^[a-z]{2}$ ]]; then
79+ lang="$last_folder"
80+ url="${dir_path%/$lang}"
81+ else
82+ url="$dir_path"
83+ fi
84+
85+ local source_page_path
86+
87+ local xml_path="book/en/${{ jobs.convert.outputs.chm_name }}/book.xml"
88+ local u="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
89+ local l="abcdefghijklmnopqrstuvwxyz"
90+
91+ source_page_path=$(xmllint --xpath "string(//page[translate(@url, '$u', '$l')='$url']/@file)" "$xml_path" 2>/dev/null)
92+
93+ echo "${lang}/${source_page_path}"
94+ fi
95+ fi
96+ }
97+
4398 log_msg() {
4499 local status=$1; local file=$2; local msg=$3
100+ local source_file=$(get_source_path "$file")
101+
45102 if [ $status -eq 0 ]; then
46103 if [ -n "$msg" ]; then
47- echo "::notice file=$file ::Optimized \`$file\` despite \`$msg\`"
104+ echo "::notice file=$source_file ::Optimized \`$file\` despite \`$msg\`"
48105 fi
49106 else
50- echo "::warning file=$file ::Skipped \`$file\` because \`$msg\`"
107+ echo "::warning file=$source_file ::Skipped \`$file\` because \`$msg\`"
51108 fi
52109 }
110+ export -f get_source_path
53111 export -f log_msg
54112 EOF
55113 chmod +x helpers.sh
0 commit comments