Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
Update entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Zhao authored and neenjaw committed Mar 31, 2021
1 parent e5ddec8 commit 14a5e70
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# For *.md files:
# 1) finds all of the mermaid markup in the file
# 2) creates intermediate files in the output directory *.md.<n>.mermaid where n represents the nth block found
# 3) compile the mermaid to the directory *.md.<n>.mermaid.png or .svg
# 3) compile the mermaid to the directory *.md.<n>.mermaid.png
# 4) place a reference to the compiled image in the markdown

set -euo pipefail
Expand All @@ -24,6 +24,8 @@ function main {
outpath="${1}"
mkdir -p "${outpath}"
printf "Got output path: %s\n" "${outpath}"
output_file_type="${OUTPUT_FILE_TYPE:-png}"
printf "Filetype: %s\n" "${output_file_type}"

shift $(( OPTIND - 1 ))

Expand All @@ -35,22 +37,16 @@ function main {
in_file_basename=$(basename "${in_file}")
in_file_type="${in_file_basename##*.}"

if [[ -z "${RENDER_SVG}" ]]; then
out_file_type="png"
else
out_file_type="svg"
fi

if [[ "${in_file_type}" == "mermaid" || "${in_file_type}" == "mmd" ]]; then

output_path="${in_file_dirname}"
output_file="$(dasherize_name ${in_file_basename}).${out_file_type}"
output_file="$(dasherize_name ${in_file_basename}).png"
c_mermaid "${in_file}" "${output_path}/${output_file}"

elif is_path_markdown "${in_file_basename}" "${MD_SUFFIXES-.md}"; then

output_path="${outpath}"
c_md_mermaid "${in_file}" "${output_path}" "${out_file_type}"
c_md_mermaid "${in_file}" "${output_path}"

else

Expand Down Expand Up @@ -91,7 +87,6 @@ function c_md_mermaid {
printf "Parsing mermaid codeblocks from %s\n" "${1}"

output_path="${2}"
output_file_type="${3}"

input_dir=$(dirname "${1}")
dasherized=$(dasherize_name "${1}")
Expand Down Expand Up @@ -124,11 +119,11 @@ function c_md_mermaid {
rm "${all_file}x"

# Compile mermaid block"
c_mermaid "${block_file}-${block_count}" "${output_path}/${dasherized}-${block_count}.${output_file_type}"
c_mermaid "${block_file}-${block_count}" "${output_path}/${dasherized}-${block_count}.png"

# Compute relative path from the markdown to the tmp_dir
image_relative_path=$(realpath --relative-to="${input_dir}" "${output_path}/${dasherized}-${block_count}.${output_file_type}")
image_absolute_path="/${output_path}/${dasherized}-${block_count}.${output_file_type}"
image_relative_path=$(realpath --relative-to="${input_dir}" "${output_path}/${dasherized}-${block_count}.png")
image_absolute_path="/${output_path}/${dasherized}-${block_count}.png"

if [[ -z "${ABSOLUTE_IMAGE_LINKS}" ]]; then
image_path="${image_relative_path}"
Expand Down

0 comments on commit 14a5e70

Please sign in to comment.