Find every file in a directory and render them all using rdiscount

98 views Asked by At

I've got a directory called "posts" which is filled with .md files. Right now rdiscount renders only one file (one.md), then puts the product into a variable (@content). Because this is done issuing...

@content = markdown(:one)

...I'm really confused as to how to make ruby 1) find every file in the directory and 2) render everything using rdiscount. Any ideas?

2

There are 2 answers

0
ian On BEST ANSWER

To extend @Simone Carletti's answer, in order to answer part 2 of your question:

@content = ""
Dir.glob("path/to/folder/*.md") do |file|
  @content << markdown(file)
end
0
Simone Carletti On

You can use Dir.glob to find and iterate all the Markdown files in the directory.

Dir.glob("path/to/folder/*.md") do |file|
  # do what you want with file
end