Skip to content

Commit 1aea6f6

Browse files
committed
- Add optional 'Page Source' link to all pages
1 parent 5b79823 commit 1aea6f6

18 files changed

Lines changed: 53 additions & 0 deletions

File tree

app/views/document.slim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@
88
- if type != :file and config.auto_nav
99
- if nav.links.any?
1010
== slim :_index_nav, locals: { nav: nav }
11+
12+
- if %i[file readme].include?(type) && config.source_link
13+
- uri = config.source_link % { path: doc.href }
14+
hr
15+
div
16+
a href="#{uri}" = config.source_link_label

lib/madness/document.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def content
1818
@content ||= %i[empty missing].include?(type) ? "<h1>#{title}</h1>" : markdown.to_html
1919
end
2020

21+
def relative_file
22+
file[%r{^#{docroot}/(.*)}, 1]
23+
end
24+
25+
def href
26+
relative_file.to_href
27+
end
28+
2129
private
2230

2331
# Identify file, dir and type.

lib/madness/server.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Server < ServerBase
4949
status 404 if doc.type == :missing
5050

5151
slim :document, locals: {
52+
doc: doc,
5253
content: content,
5354
type: doc.type,
5455
title: doc.title,

lib/madness/settings.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def defaults
6464
highlighter: true,
6565
copy_code: true,
6666
shortlinks: false,
67+
source_link: nil,
68+
source_link_label: 'Page Source',
6769
toc: nil,
6870
theme: nil,
6971
open: false,

lib/madness/templates/madness.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ toc: ~
4646
# theme: _theme
4747
theme: ~
4848

49+
# enable a link to the page's source at the bottom of each page by setting
50+
# a URL pattern here. Use '%{path}' anywhere in the string to get the
51+
# URI-encoded path of the page.
52+
# source_link: example.com/%{path}
53+
source_link: ~
54+
55+
# if source_link is enabled, you can change the default link label
56+
# source_link_label: Edit Page
57+
source_link_label: Page Source
58+
4959
# open the server URL in the browser
5060
open: false
5161

spec/approvals/cli/config/show

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
highlighter: true
1010
copy_code: true
1111
shortlinks: ~
12+
source_link: ~
13+
source_link_label: Page Source
1214
toc: ~
1315
theme: ~
1416
open: ~

spec/approvals/cli/config/show-non-default

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
highlighter: true
1010
copy_code: true
1111
shortlinks: ~
12+
source_link: ~
13+
source_link_label: Page Source
1214
toc: Table of Contents
1315
theme: my_theme
1416
open: ~
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source_link: example.com/%{path}
2+
source_link_label: Edit Page
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
me
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is a docroot index fixture

0 commit comments

Comments
 (0)