You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am looking for something like Jekyll, but directly embedded inside the Rails app.
The idea is to have a folder blog with all the blog posts. Each post would also have a front matter.
Is there any way to iterate on the blog posts?
Ideally you would read each file like it was a row in a database, so that you have a author, category, date, etc. from the front matter for each post, then you can display the index of posts or a category or a specific post.
Can you do that with this gem? Do you already have a similar approach for that (blog, docs, etc.) or I need to build from scratch?
The text was updated successfully, but these errors were encountered:
I think you could get that working, but you need a way to make rails render markdown first. Here's one approach.
I had something like this implemented and it worked perfectly. I can dump markdown files (with erb) in my pages folder without issues. Here are my steps:
Add a file to your app/config/initializers, mine is called markdown_template_handler.rb,
Write a ruby file that calls the redcarpet gem on markdown files using the register_template_handler function. Here is a copy of mine, but please note that I have it wrap generated markdown in the tailwindcss prose class for styling.
Also DANGER, I am the only author, so I have erb available on all markdown files. You may want create a second file format like mderb so that you can limit when markdown can have erb:
# app/config/initializers/markdown_template_handler.rb
require 'redcarpet'
class CustomMarkdownRenderer < Redcarpet::Render::HTML
def postprocess(full_document)
"<div class=\"prose prose-xl prose-img:rounded-xl prose-headings:underline prose-a:text-blue-600 \">#{full_document}</div>"
end
end
class MarkdownTemplateHandler
def erb
@erb ||= ActionView::Template.registered_template_handler(:erb)
end
def call(template, source)
compiled_source = erb.call(template, source)
"Redcarpet::Markdown.new(CustomMarkdownRenderer.new).render(begin;#{compiled_source};end.to_s).html_safe"
end
end
ActionView::Template.register_template_handler(:md, MarkdownTemplateHandler.new)
I am looking for something like Jekyll, but directly embedded inside the Rails app.
The idea is to have a folder
blog
with all the blog posts. Each post would also have a front matter.Is there any way to iterate on the blog posts?
Ideally you would read each file like it was a row in a database, so that you have a author, category, date, etc. from the front matter for each post, then you can display the index of posts or a category or a specific post.
Can you do that with this gem? Do you already have a similar approach for that (blog, docs, etc.) or I need to build from scratch?
The text was updated successfully, but these errors were encountered: