diff --git a/README.md b/README.md index dcfbf169..415bbe54 100644 --- a/README.md +++ b/README.md @@ -289,6 +289,22 @@ wiki page, simply preface the link with a single quote (like in LISP): This is useful for writing about the link syntax in your wiki pages. +## TABLE OF CONTENTS + +Gollum has a special tag to insert a table of contents (new in v2.1) + + '[[_TOC_]] + +This tag is case sensitive, use all upper case. The TOC tag can be inserted +into the `_Header`, `_Footer` or `_Sidebar` files too. + +There is also a wiki option `:universal_toc` which will display a +table of contents at the top of all your wiki pages if it is enabled. +The `:universal_toc` is not enabled by default. To set the option, +add the option to the `:wiki_options` hash before starting the +frontend app: + + Precious::App.set(:wiki_options, {:universal_toc => true}) ## SYNTAX HIGHLIGHTING @@ -471,6 +487,7 @@ like Rack::Auth, OmniAuth, etc. gollum_path = File.expand_path(File.dirname(__FILE__)) # CHANGE THIS TO POINT TO YOUR OWN WIKI REPO Precious::App.set(:gollum_path, gollum_path) Precious::App.set(:default_markup, :markdown) # set your favorite markup language + Precious::App.set(:wiki_options, {:universal_toc => false}) run Precious::App ## Windows Filename Validation diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 56041ffc..ebd4d999 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -8,6 +8,17 @@ require 'gollum/frontend/views/editable' require File.expand_path '../uri_encode_component', __FILE__ +# Run the frontend, based on Sinatra +# +# There are a number of wiki options that can be set for the frontend +# +# Example +# require 'gollum/frontend/app' +# Precious::App.set(:wiki_options, { +# :universal_toc => false, +# } +# +# See the wiki.rb file for more details on wiki options module Precious class App < Sinatra::Base register Mustache::Sinatra @@ -122,10 +133,11 @@ module Precious end post '/preview' do - wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) - @name = "Preview" - @page = wiki.preview_page(@name, params[:content], params[:format]) - @content = @page.formatted_data + wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) + @name = "Preview" + @page = wiki.preview_page(@name, params[:content], params[:format]) + @content = @page.formatted_data + @toc_content = wiki.universal_toc ? @page.toc_data : nil @editable = false mustache :page end @@ -220,8 +232,10 @@ module Precious if page = wiki.page(name) @page = page @name = name - @content = page.formatted_data @editable = true + @content = page.formatted_data + @toc_content = wiki.universal_toc ? @page.toc_data : nil + mustache :page elsif file = wiki.file(name) content_type file.mime_type diff --git a/lib/gollum/frontend/public/gollum/css/gollum.css b/lib/gollum/frontend/public/gollum/css/gollum.css index 64394275..687b6ffd 100755 --- a/lib/gollum/frontend/public/gollum/css/gollum.css +++ b/lib/gollum/frontend/public/gollum/css/gollum.css @@ -75,6 +75,7 @@ a:hover, a:visited { #wiki-body { display: block; float: left; + clear: left; margin-right: 3%; margin-bottom: 40px; width: 100%; @@ -84,6 +85,24 @@ a:hover, a:visited { width: 68%; } +/* @section toc */ +#wiki-toc-main { + background-color: #F7F7F7; + border: 1px solid #DDD; + font-size: 13px; + padding: 0px 5px; + float:left; + margin-bottom: 20px; + min-width: 33%; + + border-radius: 0.5em; + -moz-border-radius: 0.5em; + -webkit-border-radius: 0.5em; +} +#wiki-toc-main > div { + border: none; +} + /* @section rightbar */ #wiki-rightbar { background-color: #f7f7f7; @@ -145,6 +164,7 @@ a:hover, a:visited { #wiki-header #header-content { margin-bottom: 1.5em; } + #wiki-footer #footer-content { margin-top: 1.5em; } diff --git a/lib/gollum/frontend/public/gollum/css/template.css b/lib/gollum/frontend/public/gollum/css/template.css index 159872db..c9ea382b 100644 --- a/lib/gollum/frontend/public/gollum/css/template.css +++ b/lib/gollum/frontend/public/gollum/css/template.css @@ -30,6 +30,11 @@ a.absent { color: #c00; } +.markdown-body a[id].wiki-toc-anchor { + color: inherit; + text-decoration: none; +} + .markdown-body { font-size: 14px; line-height: 1.6; @@ -72,7 +77,7 @@ a.absent { .markdown-body h4:hover a.anchor, .markdown-body h5:hover a.anchor, .markdown-body h6:hover a.anchor { - background: url('/images/para.png') no-repeat 10px center; + background: url('/images/pin-20.png') no-repeat left center; text-decoration: none; } .markdown-body h1 tt, @@ -362,6 +367,43 @@ a.absent { margin: 0; padding: 0; } +.toc { + background-color: #F7F7F7; + border: 1px solid #ddd; + padding: 5px 10px; + margin: 0; + border-radius: 3px; +} +.toc-title { + color: #888; + font-size: 14px; + line-height: 1.6; + padding: 2px; + border-bottom: 1px solid #ddd; + margin-bottom: 3px; +} +.toc ul { + padding-left: 10px; + margin: 0; +} +.toc>ul { + margin-left: 10px; + font-size: 17px; +} +.toc ul ul { + font-size: 15px; +} +.toc ul ul ul { + font-size: 14px; +} +.toc ul li{ + margin: 0; +} +#header-content .toc, +#footer-content .toc, +#sidebar-content .toc { + border: none; +} .highlight { background: #fff; } diff --git a/lib/gollum/frontend/public/gollum/images/pin-16.png b/lib/gollum/frontend/public/gollum/images/pin-16.png new file mode 100644 index 00000000..fc5a5f50 Binary files /dev/null and b/lib/gollum/frontend/public/gollum/images/pin-16.png differ diff --git a/lib/gollum/frontend/public/gollum/images/pin-20.png b/lib/gollum/frontend/public/gollum/images/pin-20.png new file mode 100644 index 00000000..45e7f97d Binary files /dev/null and b/lib/gollum/frontend/public/gollum/images/pin-20.png differ diff --git a/lib/gollum/frontend/public/gollum/images/pin-24.png b/lib/gollum/frontend/public/gollum/images/pin-24.png new file mode 100644 index 00000000..fdca0e53 Binary files /dev/null and b/lib/gollum/frontend/public/gollum/images/pin-24.png differ diff --git a/lib/gollum/frontend/public/gollum/images/pin-32.png b/lib/gollum/frontend/public/gollum/images/pin-32.png new file mode 100644 index 00000000..8350bab3 Binary files /dev/null and b/lib/gollum/frontend/public/gollum/images/pin-32.png differ diff --git a/lib/gollum/frontend/templates/page.mustache b/lib/gollum/frontend/templates/page.mustache index 6a2b708b..09758175 100644 --- a/lib/gollum/frontend/templates/page.mustache +++ b/lib/gollum/frontend/templates/page.mustache @@ -20,7 +20,19 @@