Url encode w/ include_relative

Here is my question;

.dot graphviz graph in a separate file like so;

digraph {
  main->parse->execute;
  main->init;
  main->cleanup;
  execute->make_string;
  execute->printf;
  init->make_string;
  main->printf;
  execute->compare;
}

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

_include/graph.html

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

index.md

---
graph_path: /graph/digraphEg.dot
---

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