From fe9ab940d224171bf9b314c69c5e96e4a9d5283f Mon Sep 17 00:00:00 2001 From: Tim Austin Date: Mon, 20 Apr 2020 11:17:32 -0600 Subject: [PATCH] Add absolute image path feature (#3) If using this action for github pages, relative links break. This adds a feature which allows absolute paths to be enabled when links are inserted into the markdown for compiled images. You can now set the environment variable `ABSOLUTE_IMAGE_LINK` to flag the option: - if unset, links remain relative - if set, links are not absolute from using the output directory as a directory found in the repository root folder --- entrypoint.sh | 11 +++++++++-- insert-markdown.awk | 2 +- package.json | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5d45e47..b74c4d5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -103,11 +103,18 @@ function c_md_mermaid { c_mermaid "${block_file}-${block_count}" "${2}/${dasherized}-${block_count}.png" # Compute relative path from the markdown to the tmp_dir - relative_path=$(realpath --relative-to="${input_dir}" "${2}/${dasherized}-${block_count}.png") + image_relative_path=$(realpath --relative-to="${input_dir}" "${2}/${dasherized}-${block_count}.png") + image_absolute_path="/${2}/${dasherized}-${block_count}.png" + + if [[ -z "${ABSOLUTE_IMAGE_LINKS}" ]]; then + image_path="${image_relative_path}" + else + image_path="${image_absolute_path}" + fi # Insert the link to the markdown awk -v n="${block_count}" \ - -v rel_path="${relative_path}" \ + -v path="${image_path}" \ -v hide_codeblocks="${HIDE_CODEBLOCKS}" \ -f "${insert_markdown_awk}" \ "${1}" > "${1}-temp" diff --git a/insert-markdown.awk b/insert-markdown.awk index 9e278f5..4cb320f 100644 --- a/insert-markdown.awk +++ b/insert-markdown.awk @@ -6,7 +6,7 @@ BEGIN { i=0; start_comment=""; end_comment=""; - link="![~mermaid diagram " n "~](" rel_path ")"; + link="![~mermaid diagram " n "~](" path ")"; } # Rules to erase old generated code diff --git a/package.json b/package.json index fa1cc8e..dd506a6 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ }, "homepage": "https://github.com/neenjaw/mermaid-workflow-test#readme", "dependencies": { - "mermaid.cli": "^0.5.1" + "mermaid.cli": "^0.5.1", + "minimist": ">=0.2.1" } }