diff --git a/build.sh b/build.sh index af6df40..225e078 100755 --- a/build.sh +++ b/build.sh @@ -28,7 +28,7 @@ rm -f "${target_zip}" # doc_dir: cd here before building. # main_file: build this tex file. Usually main.tex function build() { - local target_dir="${1}" + local b_target_dir="${1}" local job_name="${2}" local doc_dir="${3}" local main_file="${4}" @@ -41,7 +41,6 @@ function build() { --web-bundle "https://static.betalupi.com/tectonic/texlive2023.tar" ) - # Build handout echo "\\def\\argNoSolutions{1}\\input{${main_file}}" | \ tectonic \ @@ -49,13 +48,13 @@ function build() { --outfmt pdf \ - - stat=$? + handout_stat=$? - if [[ $stat == 0 ]]; then - mkdir -p "${target_dir}" - mv texput.pdf "${target_dir}/${job_name}.pdf" + if [[ $handout_stat == 0 ]]; then + mkdir -p "${b_target_dir}" + mv texput.pdf "${b_target_dir}/${job_name}.pdf" else - rmdir --ignore-fail-on-non-empty "${target_dir}" + rmdir --ignore-fail-on-non-empty "${b_target_dir}" rm -f texput.pdf echo "|> Handout build failed" echo "" @@ -69,30 +68,46 @@ function build() { --outfmt pdf \ - - stat=$? + solution_stat=$? - if [[ $stat == 0 ]]; then - mkdir -p "${target_dir}" - mv texput.pdf "${target_dir}/${job_name}.sols.pdf" + if [[ $solution_stat == 0 ]]; then + mkdir -p "${b_target_dir}" + mv texput.pdf "${b_target_dir}/${job_name}.sols.pdf" else - rmdir --ignore-fail-on-non-empty "${target_dir}" + rmdir --ignore-fail-on-non-empty "${b_target_dir}" rm -f texput.pdf echo "|> Solution build failed" fi # Clean up if files contents are identical - if cmp --silent -- "${target_dir}/${job_name}.sols.pdf" "${target_dir}/${job_name}.pdf"; then - echo "|> Versions identical, removing ${job_name}.sols.pdf" - rm "${target_dir}/${job_name}.sols.pdf" - fi + #if [[ $(cmp -bl "${b_target_dir}/${job_name}.sols.pdf" "${b_target_dir}/${job_name}.pdf" | wc -l) < 200 ]]; then + # echo "|> Versions identical, removing ${job_name}.sols.pdf" + # rm "${b_target_dir}/${job_name}.sols.pdf" + # solution_stat=1; + #fi echo "" + + if [[ $handout_stat == 0 ]]; then + ( + echo -n "{" + echo -n "\"title\": \"${job_name}\"", + echo -n "\"type\": \"$(realpath --relative-to="${target_dir}" "${b_target_dir}")\"", + echo -n "\"description\": \"${job_name}\"", + echo -n "\"handout\": \"https://static.betalupi.com/ormc/$(realpath --relative-to="${target_dir}" "${b_target_dir}")/${job_name}.pdf\"," + if [[ $solution_stat == 0 ]]; then + echo -n "\"solutions\": \"https://static.betalupi.com/ormc/$(realpath --relative-to="${target_dir}" "${b_target_dir}")/${job_name}.sols.pdf\"" + fi + echo -n "}," + ) >> "$target_dir/index.json" + fi cd "${run_dir}" } - +mkdir -p "${target_dir}" +echo -n "[" > "$target_dir/index.json" @@ -127,7 +142,11 @@ for d in "${run_dir}/Intermediate"/*/ ; do "main.tex" done +echo -n "{}]" >> "$target_dir/index.json" + # cd so paths in zip are relative cd "${target_dir}" -zip -FSr "${target_zip}" . \ No newline at end of file + +zip -FSr "${target_zip}" . +zip -d "${target_zip}" "index.json" # We don't need this in the zip \ No newline at end of file