├── Gemfile ├── template ├── images │ ├── page.png │ ├── folder.png │ └── page_edit.png ├── template.erb └── css │ └── style.css ├── content ├── Misc │ └── Credits.md ├── Todos.md ├── Structure.md └── index.md ├── config.yaml ├── LICENSE ├── markdown-tree.rb └── README.md /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'sinatra' 3 | gem 'redcarpet' 4 | -------------------------------------------------------------------------------- /template/images/page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mil/markdown-tree/HEAD/template/images/page.png -------------------------------------------------------------------------------- /template/images/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mil/markdown-tree/HEAD/template/images/folder.png -------------------------------------------------------------------------------- /template/images/page_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mil/markdown-tree/HEAD/template/images/page_edit.png -------------------------------------------------------------------------------- /content/Misc/Credits.md: -------------------------------------------------------------------------------- 1 | Credits 2 | ======= 3 | - Inspiration taken from static site generator mksite [mksite](http://zziplib.sourceforge.net/mksite/) 4 | - Icons are [famfam's silk set](http://www.famfamfam.com/lab/icons/silk/) 5 | -------------------------------------------------------------------------------- /content/Todos.md: -------------------------------------------------------------------------------- 1 | Todos 2 | ===== 3 | - Clean up the default template's css 4 | - Create example site using same example structure in repo 5 | - Add more error handling for reading file 6 | - Add support for .mkd, .markdown, and more extensions 7 | -------------------------------------------------------------------------------- /content/Structure.md: -------------------------------------------------------------------------------- 1 | Folder Structure / Customization 2 | ================================ 3 | - **markdown-tree.rb** : The ruby script to run which serves your site 4 | - **config.yaml** : 3 option config used by markdown-tree.rb 5 | - **template/** : Contains the default template 6 | * **template.erb** : ERB template pages are built from 7 | - **content/** : Contains the hierarchy of markdown files for your site 8 | -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | #Site Title, passed to the template when rendering 2 | site-title: Markdown Tree Example Site 3 | 4 | #Template folder, relative to root directory of markdown-tree 5 | template-folder: template 6 | 7 | #Hierarchy folder, should contain tree of folders and markdown files 8 | hierarchy-folder: content 9 | 10 | #Markdown extension you use for your files (md, mkd, markdown, etc.) 11 | markdown-extension: md 12 | -------------------------------------------------------------------------------- /content/index.md: -------------------------------------------------------------------------------- 1 | Markdown Tree 2 | ============= 3 | 4 | What is it? 5 | ----------- 6 | Take a folder with a hierarchy of markdown files and use this script to serve that folder as a live styled site with a built in navigation. 7 | 8 | Basically this is a Sinatra script to serve a hierarchy / tree directory of markdown files as a live dynamic site. Use intended for small sites built in markdown. 9 | 10 | 11 | Why 12 | --- 13 | There are many similar scripts done in a static fashion but I couldn't find a minimal system for serving markdown hierarchy based sites that was dynamic. 14 | 15 | For that reason I created Markdown Tree. Having a dynamically generated site allows me to not have to worry about regenerating my site every time I make a minor change. 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Miles Sandlar 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /template/template.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <%= siteTitle %> 6 | 7 | 8 | 9 |
10 |
11 | 12 | 13 | 14 |
15 | <%= siteTitle %> 16 | 17 | <% fullPath = '' %> 18 | 19 | <% for pathPart in path %> 20 | <% fullPath = fullPath + '/' + pathPart %> 21 | »  <%= pathPart%> 22 | <% end %> 23 | 24 |
25 | 26 | 27 | 28 | 52 | 53 | 54 |
<%= content %>
55 | 56 |
57 | 58 | 61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /markdown-tree.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | require 'sinatra' 3 | require 'redcarpet' 4 | require 'yaml' 5 | 6 | #Config 7 | $config = YAML.load_file('config.yaml') 8 | 9 | #Set up Sinatra Config 10 | set :views => "#{settings.root}/#{$config['template-folder']}/", 11 | :public_folder => "#{settings.root}/#{$config['template-folder']}/", 12 | :static => true 13 | 14 | #All Pages 15 | get '/*' do 16 | path = params[:splat].join.split("/") 17 | 18 | #File or folder 19 | folder = "#{Dir.getwd}/#{$config['hierarchy-folder']}/#{params[:splat].join}" 20 | if File.directory?(folder) then 21 | file = "index" 22 | else 23 | folder.gsub!(/\/[^\/]+$/,"") 24 | file = path.pop 25 | end 26 | 27 | #Get children of current folder 28 | children = getChildren(folder) 29 | 30 | #Render Markdown 31 | begin 32 | content = File.read("#{folder}/#{file}.#{$config['markdown-extension']}") 33 | rescue 34 | content = "" 35 | end 36 | 37 | erb :template, :locals => { 38 | :siteTitle => $config['site-title'], 39 | 40 | :currentFile => file, 41 | :path => path, 42 | :children => children, 43 | 44 | :content => markdown(content) 45 | } 46 | end 47 | 48 | #Children Array 49 | def getChildren(folderPath) 50 | children = { 51 | :directories => [], 52 | :pages => [] 53 | } 54 | 55 | #Loop through each child 56 | Dir.foreach(folderPath) do |child| 57 | # Skip if index or . or .. 58 | next if child.match(/^(index.#{$config['markdown-extension']}|\.+)$/) 59 | 60 | #Children folder or file 61 | if File.directory?("#{folderPath}/#{child}") then 62 | children[:directories].push(child) 63 | else 64 | #Throw away extension and push 65 | children[:pages].push(child.gsub!(/\.[^.]+$/, '')) 66 | end 67 | end 68 | 69 | return children 70 | end 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Markdown Tree 2 | ============= 3 | 4 | What is it? 5 | ----------- 6 | Take a folder with a hierarchy of markdown files and use this script to serve that folder as a live styled site with a built in navigation. 7 | 8 | Basically this is a Sinatra script to serve a hierarchy / tree directory of markdown files as a live dynamic site. Use intended for small sites built in markdown. 9 | 10 | 11 | Why 12 | --- 13 | There are many similar scripts done in a static fashion but I couldn't find a minimal system for serving markdown hierarchy based sites that was dynamic. 14 | 15 | For that reason I created Markdown Tree. Having a dynamically generated site allows me to not have to worry about regenerating my site every time I make a minor change. 16 | 17 | Installation and Usage 18 | ----- 19 | - Clone the repo: ```git clone git://github.com/mil/markdown-tree.git``` 20 | - Go into the directory: ```cd markdown-tree``` 21 | - Install the Sinatra and Redcarpet gems: ```gem install redcarpet sinatra``` 22 | - Run the script: ```ruby markdown-tree.rb``` 23 | * Visit http://localhost:4567 to browse your site! 24 | 25 | Folder Structure / Customization 26 | -------------------------------- 27 | - **markdown-tree.rb** : The ruby script to run which serves your site 28 | - **config.yaml** : 4 option config used by markdown-tree.rb 29 | - **template/** : Contains the default template 30 | * **template.erb** : ERB template pages are built from 31 | - **content/** : Contains the hierarchy of markdown files for your Sites 32 | 33 | Example Sites 34 | ------------- 35 | - [Default Example Site](http://markdown-tree.bladdo.net/) 36 | - [My Personal Notes System](http://notes.bladdo.net) (for notes I take in class at Virginia Tech) 37 | 38 | Todos 39 | -------------------------------- 40 | - Clean up the default template's CSS 41 | - Add more error handling for reading file 42 | 43 | Credits 44 | ------- 45 | - Inspiration taken from static site generator mksite [mksite](http://zziplib.sourceforge.net/mksite/) 46 | - Icons are [famfam's silk set](http://www.famfamfam.com/lab/icons/silk/) 47 | -------------------------------------------------------------------------------- /template/css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Arial, sans-serif; 3 | color: #000; 4 | background: #fff; 5 | line-height: 20px; 6 | } 7 | 8 | 9 | h1 { 10 | color: #641818; 11 | border-bottom: 1px solid #d0d0d0; 12 | font-size: 25px; 13 | line-height: 38px; 14 | } 15 | 16 | h2 { 17 | color: #641818; 18 | border-bottom: 1px dashed #d0d0d0; 19 | font-size: 23px; 20 | line-height: 30px; 21 | } 22 | 23 | 24 | h3 { 25 | color: #353f6e; 26 | font-size: 20px; 27 | } 28 | 29 | 30 | h4 { 31 | color: #641818; 32 | font-size: 18px; 33 | } 34 | 35 | 36 | h5 { 37 | color: #641818; 38 | font-size: 16px; 39 | } 40 | 41 | h6 { 42 | color: #641818; 43 | font-size: 15px; 44 | } 45 | 46 | ul { 47 | border: 1px dotted gray; 48 | margin: 5px; 49 | 50 | } 51 | li { 52 | padding: 5px; 53 | } 54 | 55 | ul li ul { 56 | background: #eeeeee; 57 | } 58 | 59 | ul li ul li { 60 | background: white; 61 | } 62 | 63 | ul li ul li ul { 64 | background: #eeeeee; 65 | } 66 | 67 | 68 | 69 | a { 70 | color: #bb2828; 71 | text-decoration: none; 72 | } 73 | 74 | a:hover { 75 | color: #ff0000; 76 | } 77 | 78 | #content { 79 | border: 1px solid #dfdfdf; 80 | padding: 10px; 81 | } 82 | 83 | #footer { 84 | 85 | margin-top: 5px; 86 | border: 1px solid #dfdfdf; 87 | font-size: 12px; 88 | padding: 10px 5px; 89 | text-align: right; 90 | 91 | background-color: #f4f4f4; 92 | 93 | clear: both; 94 | overflow: hidden; 95 | } 96 | 97 | 98 | 99 | 100 | #path { 101 | border: 1px solid #dfdfdf; 102 | padding: 5px 10px; 103 | background: #eaeaea; 104 | } 105 | 106 | #path a { 107 | padding-left: 20px; 108 | padding-right: 5px; 109 | font-size: 13px; 110 | 111 | background-image: url('/images/folder.png'); 112 | background-repeat: no-repeat; 113 | background-position: left center; 114 | 115 | 116 | 117 | } 118 | 119 | #path a:last-child { 120 | color: black; 121 | font-size: 14px; 122 | } 123 | 124 | 125 | #menu { 126 | border: 1px solid #dfdfdf; 127 | border-top: none; 128 | padding: 5px 10px; 129 | margin-bottom: 5px; 130 | background: #f4f4f4; 131 | } 132 | 133 | #menu ul { 134 | margin: 0; 135 | border: none; 136 | } 137 | 138 | #menu li { 139 | 140 | background-image: url('/images/page.png'); 141 | background-repeat: no-repeat; 142 | background-position: left center; 143 | 144 | 145 | display: inline-block; 146 | list-style: none; 147 | font-size: 13px; 148 | padding-left: 20px; 149 | padding-right: 10px; 150 | line-height: 10px; 151 | border-right: 1px dotted #d4d4d4; 152 | } 153 | 154 | #menu li.page { 155 | background-image: url('/images/page.png'); 156 | } 157 | 158 | #menu li.folder { 159 | background-image: url('/images/folder.png'); 160 | } 161 | 162 | #menu li.current { 163 | background-image: url('/images/page_edit.png'); 164 | } 165 | #menu li.current a { 166 | color: black; 167 | } 168 | --------------------------------------------------------------------------------