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

Commit

Permalink
Add absolute image path feature (#3)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
neenjaw authored Apr 20, 2020
1 parent a4f6006 commit fe9ab94
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
11 changes: 9 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion insert-markdown.awk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN {
i=0;
start_comment="<!-- generated by mermaid compile action - START -->";
end_comment="<!-- generated by mermaid compile action - END -->";
link="![~mermaid diagram " n "~](" rel_path ")";
link="![~mermaid diagram " n "~](" path ")";
}

# Rules to erase old generated code
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit fe9ab94

Please sign in to comment.