Last active
March 25, 2016 15:51
-
-
Save mattroyer/2589255 to your computer and use it in GitHub Desktop.
Create a Sinatra page of blog posts that are in separate markdown files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an array of all markdown files from a specific directory | |
# And convert them to Html using the RDiscount gem | |
# Display them in the index of the page using Haml | |
# | |
# I sorted them this way because they are in the format: | |
# post_1.md | |
# post_2.md | |
# ... | |
# post_10.md | |
# post_11.md | |
# | |
# Without the sort done this way, it will put them into the array | |
# and on your page as: | |
# | |
# post_1.md | |
# post_10.md | |
# post_11.md | |
# post_2.md | |
# ... | |
get '/' do | |
@posts = "" | |
Dir["/Blog/Markdown/*.md"].sort_by {|f| f.split("_")[1].to_i}.each do |post| | |
@posts << RDiscount.new( File.open(post).read ).to_html | |
end | |
haml :index | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment