Skip to content

Commit 68dd401

Browse files
committed
Ignore Frontmatter
1 parent 4ed07ff commit 68dd401

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

config/initializers/actionview.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Uncomment if you're not on Rails 7,1, see https://www.shakacode.com/blog/rails-7-1-introduces-config-autoload_lib
2+
# require 'strip_frontmatter_template_handler'
3+
4+
ActiveSupport.on_load(:action_view) do
5+
# Replace the registered template handlers for formats we want to support
6+
# Frontmatter
7+
[
8+
:erb,
9+
:slim
10+
].each do |extension|
11+
handler = ActionView::Template.registered_template_handler(extension)
12+
13+
ActionView::Template.register_template_handler(
14+
extension,
15+
StripFrontmatterTemplateHandler.new(handler)
16+
)
17+
end
18+
end
19+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class StripFrontmatterTemplateHandler
2+
attr_reader :handler
3+
4+
def initialize(handler)
5+
@handler = handler
6+
end
7+
8+
def call(template, source)
9+
# Extract the non-frontmatter part of the template
10+
source = RubyMatter.parse(source).content
11+
12+
# Pass the extracted source to the original handler
13+
handler.call(template, source)
14+
end
15+
end
16+

0 commit comments

Comments
 (0)