Skip to content

Commit

Permalink
Added Markdown Extension Option to config.yaml
Browse files Browse the repository at this point in the history
Removed todo in README for multiple extensions
Minor other fixes
  • Loading branch information
Miles Sandlar committed Apr 28, 2012
1 parent f23cdfa commit 9ba31a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
7 changes: 2 additions & 5 deletions README.md
Expand Up @@ -25,7 +25,7 @@ Installation and Usage
Folder Structure / Customization
--------------------------------
- **markdown-tree.rb** : The ruby script to run which serves your site
- **config.yaml** : 3 option config used by markdown-tree.rb
- **config.yaml** : 4 option config used by markdown-tree.rb
- **template/** : Contains the default template
* **template.erb** : ERB template pages are built from
- **content/** : Contains the hierarchy of markdown files for your Sites
Expand All @@ -37,11 +37,8 @@ Example Sites

Todos
--------------------------------
- Clean up the default template's css
- Create example site using same example structure in repo
- Clean up the default template's CSS
- Add more error handling for reading file
- Add support for .mkd, .markdown, and more extensions


Credits
-------
Expand Down
3 changes: 3 additions & 0 deletions config.yaml
Expand Up @@ -6,3 +6,6 @@ template-folder: template

#Hierarchy folder, should contain tree of folders and markdown files
hierarchy-folder: content

#Markdown extension you use for your files (md, mkd, markdown, etc.)
markdown-extension: md
20 changes: 10 additions & 10 deletions markdown-tree.rb
Expand Up @@ -4,19 +4,19 @@
require 'yaml'

#Config
config = YAML.load_file('config.yaml')
$config = YAML.load_file('config.yaml')

#Set up Sinatra Config
set :views => "#{settings.root}/#{config['template-folder']}/",
:public_folder => "#{settings.root}/#{config['template-folder']}/",
:static => true
set :views => "#{settings.root}/#{$config['template-folder']}/",
:public_folder => "#{settings.root}/#{$config['template-folder']}/",
:static => true

#All Pages
get '/*' do
path = params[:splat].join.split("/")

#File or folder
folder = "#{Dir.getwd}/#{config['hierarchy-folder']}/#{params[:splat].join}"
folder = "#{Dir.getwd}/#{$config['hierarchy-folder']}/#{params[:splat].join}"
if File.directory?(folder) then
file = "index"
else
Expand All @@ -29,33 +29,33 @@

#Render Markdown
begin
content = File.read("#{folder}/#{file}.md")
content = File.read("#{folder}/#{file}.#{$config['markdown-extension']}")
rescue
content = ""
end

erb :template, :locals => {
:siteTitle => config['site-title'],
:siteTitle => $config['site-title'],

:currentFile => file,
:path => path,
:children => children,

:content => markdown(content),
:content => markdown(content)
}
end

#Children Array
def getChildren(folderPath)
children = {
:directories =>[],
:directories => [],
:pages => []
}

#Loop through each child
Dir.foreach(folderPath) do |child|
# Skip if index or . or ..
next if child.match(/^(index.md|\.+)$/)
next if child.match(/^(index.#{$config['markdown-extension']}|\.+)$/)

#Children folder or file
if File.directory?("#{folderPath}/#{child}") then
Expand Down

0 comments on commit 9ba31a9

Please sign in to comment.