From bc44220db3b289d774abb7c0f30065aa03a5c4d8 Mon Sep 17 00:00:00 2001 From: Lorin Werthen Date: Fri, 26 Feb 2021 15:24:40 +0100 Subject: [PATCH] add katex support --- Gemfile | 8 ++++++-- Gemfile.lock | 6 ++++++ Rules | 3 ++- layouts/blogpost.erb | 3 +++ lib/data_sources/katex.rb | 17 +++++++++++++++++ nanoc.yaml | 3 +++ 6 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 lib/data_sources/katex.rb diff --git a/Gemfile b/Gemfile index b25d8dd..7f75f98 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,12 @@ gem 'nanoc' gem 'icalendar' # ical files gem 'kramdown' + +# Kramdown math mode gems +gem 'kramdown-math-katex' +# Also needed for autoprefixing +gem 'mini_racer' + gem 'sassc' gem 'typogruby' @@ -24,8 +30,6 @@ group :development do end group :production do - # Faster css autoprefixing - gem 'mini_racer' # Autoprefixing for class gem 'autoprefixer-rails' gem 'htmlcompressor' diff --git a/Gemfile.lock b/Gemfile.lock index 3d27be4..223e161 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -53,8 +53,13 @@ GEM ice_cube (0.16.3) json (2.5.1) json_schema (0.20.9) + katex (0.6.1) + execjs (~> 2.7) kramdown (2.3.0) rexml + kramdown-math-katex (1.0.1) + katex (~> 0.4) + kramdown (~> 2.0) libv8 (8.4.255.0) listen (3.4.0) rb-fsevent (~> 0.10, >= 0.10.3) @@ -161,6 +166,7 @@ DEPENDENCIES htmlcompressor icalendar kramdown + kramdown-math-katex mini_racer nanoc pandoc-ruby diff --git a/Rules b/Rules index 48cf4e9..39d1ec3 100644 --- a/Rules +++ b/Rules @@ -4,6 +4,7 @@ require 'json' require 'icalendar' + # Important!!! # First ignore the node_modules, we do not need any of it on the site directly. ignore '/node_modules/**/*' @@ -103,7 +104,7 @@ end compile '/blog/*/*.md' do filter :erb layout '/blogpost.md' - filter :kramdown + filter :kramdown, {math_engine: :katex} filter :typogruby layout '/blogpost.erb' diff --git a/layouts/blogpost.erb b/layouts/blogpost.erb index 50043cb..0c4253c 100644 --- a/layouts/blogpost.erb +++ b/layouts/blogpost.erb @@ -14,6 +14,9 @@ + + + <% end %>
diff --git a/lib/data_sources/katex.rb b/lib/data_sources/katex.rb new file mode 100644 index 0000000..31677b7 --- /dev/null +++ b/lib/data_sources/katex.rb @@ -0,0 +1,17 @@ +require 'katex' + +class KatexDataSource < ::Nanoc::DataSource + identifier :katex + + def items + katex_css_path = File.join(Katex.gem_path, 'vendor', 'katex', 'stylesheets', 'katex.css') + + [ + new_item( + File.open(katex_css_path).read, + {}, + "/katex.css" + ) + ] + end +end diff --git a/nanoc.yaml b/nanoc.yaml index 003c512..38fe064 100644 --- a/nanoc.yaml +++ b/nanoc.yaml @@ -90,6 +90,9 @@ data_sources: items_root: /about/verslagen/ content_dir: drive/verslagen/ layouts_dir: null + - + type: katex + items_root: /assets/stylesheets # Configuration for the “check” command, which run unit tests on the site. checks: