archive
This commit is contained in:
72
gollum/config.rb
Executable file
72
gollum/config.rb
Executable file
@@ -0,0 +1,72 @@
|
||||
=begin
|
||||
This file can be used to (e.g.):
|
||||
- alter certain inner parts of Gollum,
|
||||
- extend it with your stuff.
|
||||
|
||||
It is especially useful for customizing supported formats/markups. For more information and examples:
|
||||
- https://github.com/gollum/gollum#config-file
|
||||
|
||||
=end
|
||||
|
||||
module Gollum
|
||||
class Macro
|
||||
class ImmediatePages < Gollum::Macro
|
||||
def render(toc_root_path = nil, max_depth = 1, min_depth = 0)
|
||||
if toc_root_path == nil
|
||||
if @page.path == "Home.md"
|
||||
toc_root_path = ""
|
||||
else
|
||||
toc_root_path = @page.path.sub(/\.[a-z]+$/,'/')
|
||||
end
|
||||
end
|
||||
if toc_root_path.start_with?("/")
|
||||
toc_root_path[0] = ''
|
||||
end
|
||||
if toc_root_path != "" and not toc_root_path.end_with?("/")
|
||||
toc_root_path << '/'
|
||||
end
|
||||
if @wiki.pages.size > 0
|
||||
list_items = @wiki.pages.map do |page|
|
||||
if @page.url_path != page.url_path and page.url_path.start_with?(toc_root_path)
|
||||
path_display = page.url_path_display.sub(toc_root_path.gsub("-", " "), "").sub(/^\//,'')
|
||||
depth = path_display.count("/")
|
||||
if depth.to_i < max_depth.to_i and depth.to_i >= min_depth.to_i
|
||||
" <li><a href=\"/#{page.url_path}\">#{path_display}</a></li>"
|
||||
end
|
||||
end
|
||||
end
|
||||
result = "<ul>#{list_items.join}</ul>"
|
||||
end
|
||||
title = toc_root_path
|
||||
"<div class=\"toc\"><div class=\"toc-title\">#{title}</div>#{result}</div>"
|
||||
end
|
||||
end
|
||||
class PathSegments < Gollum::Macro
|
||||
def render(append = "")
|
||||
segments = @page.path.split('/')
|
||||
segments = segments.first(segments.size - 1)
|
||||
if append != ""
|
||||
segments << append
|
||||
end
|
||||
full = ""
|
||||
list_items = segments.map do |segment|
|
||||
full = "#{full}/#{segment}"
|
||||
" / <a href=\"#{full}\">#{segment}</a>"
|
||||
end
|
||||
list_items.insert(0, " / <a href=\"/Home\">Home</a>")
|
||||
list_items << " / <a id='last_segment' onload='load_segment();' href='#'></a>"
|
||||
"<div>#{list_items.join}</div>"
|
||||
end
|
||||
end
|
||||
class DropDown < Gollum::Macro
|
||||
def render(summary, detail)
|
||||
"<details><summary>#{summary}</summary><div class=\"toc\">#{detail}</div></details"
|
||||
end
|
||||
end
|
||||
class ImgDropDown < Gollum::Macro
|
||||
def render(img_link, title = "Image")
|
||||
"<details><summary>#{title}</summary><div class=\"img-drop-down\"><img src=\"#{img_link}\"/></div></details"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user