Url encode w/ include_relative

Here is my question;

.dot graphviz graph in a separate file like so;

digraph {

I have to get the contents of this file, in url encoded format, and then append it to this link; https://quickchart.io/graphviz?graph= and have it inside my markdown post like so;

![my_graph](https://quickchart.io/graphviz?graph=<url encoded .dot file contents>

How would I go about doing this?

I can get the contents of the .dot file with {%- include_relative /graph/my_graph.dot -%} but I can’t use the url_encode filter with it. And I don’t mind having the file under my _posts directory, but if there is a solution where I can store it in any directory under my site root, I would be happier…

Here is what I did, I first had to capture the include in a variable and then encode it.

{% capture my_graph%}
{%- include_relative /graph/digraphEg.dot -%}
{% endcapture %}
{{ my_graph | uri_escape }}
![complex_chart](https://quickchart.io/graphviz?graph={{ my_graph }})

it would be nice if I can figure out how to place digraphEg.dot somewhere but it could also live in the markdown file at this point.

1 Like

Idea for refactor


{% capture my_graph%}
{%- include_relative {{ include.path -%}
{% endcapture %}
https://quickchart.io/graphviz?graph={{ my_graph | uri_escape }}


graph_path: /graph/digraphEg.dot

![complex_chart]({% include graph.html path=graph_path %})
1 Like