aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--_config.yml1
-rw-r--r--_plugins/graphviz-block.rb36
-rw-r--r--default.nix1
4 files changed, 40 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 476620d..94fc6b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,4 +4,5 @@
# Jekyll
/.bundle/
/_site/
-/.jekyll-cache/ \ No newline at end of file
+/.jekyll-cache/
+/images/graphviz/ \ No newline at end of file
diff --git a/_config.yml b/_config.yml
index b8467f5..3eceb93 100644
--- a/_config.yml
+++ b/_config.yml
@@ -32,6 +32,7 @@ exclude:
- drafts/
- description
- result
+ - images/graphviz/
collections:
articles:
diff --git a/_plugins/graphviz-block.rb b/_plugins/graphviz-block.rb
new file mode 100644
index 0000000..4ddd2ee
--- /dev/null
+++ b/_plugins/graphviz-block.rb
@@ -0,0 +1,36 @@
+require 'tempfile'
+require 'digest'
+
+OUTPUT_DIR = '/images/graphviz'
+
+module Jekyll
+ class GraphvizBlock < Liquid::Block
+ def initialize(tag_name, options, tokens)
+ super
+ opts_list = options.split('|').map { |s| s.strip }
+ @name = opts_list[0]
+ @alt = opts_list[1]
+ end
+
+ def render(context)
+ source = super
+ site = context.registers[:site]
+ FileUtils.mkdir_p(File.join(site.source, OUTPUT_DIR))
+
+ filename = "#{@name}-#{Digest::SHA256.hexdigest(source + @alt)}.svg"
+ site_path = File.join(OUTPUT_DIR, filename)
+ os_path = File.join(site.source, site_path)
+
+ f = Tempfile.new('graphviz-input')
+ f.write(source)
+ f.close
+ `dot -Tsvg #{f.path} > #{os_path}`
+ f.unlink
+
+ site.static_files << Jekyll::StaticFile.new(site, site.source, OUTPUT_DIR, filename)
+ "<img src=\"#{site_path}\" alt=\"#{@alt}\" />"
+ end
+ end
+end
+
+Liquid::Template.register_tag('graphviz', Jekyll::GraphvizBlock)
diff --git a/default.nix b/default.nix
index f52c6a6..10d7ef0 100644
--- a/default.nix
+++ b/default.nix
@@ -13,6 +13,7 @@ let
projectBuildInputs = with pkgs; [
jekyllEnv
+ graphviz
nixfmt
git
shellcheck