This repository was archived by the owner on Jan 21, 2022. It is now read-only.
File tree 3 files changed +43
-27
lines changed
3 files changed +43
-27
lines changed Original file line number Diff line number Diff line change 48
48
# end
49
49
50
50
require 'navigation'
51
+ require 'quicklinks'
51
52
52
53
set :markdown_engine , :redcarpet
53
54
set :markdown , :layout_engine => :erb ,
91
92
# For navigation breadcrumbs
92
93
activate :navigation
93
94
95
+ # For generated intra-page links
96
+ activate :quicklinks
97
+
94
98
helpers do
95
99
class Middleman ::Sitemap ::Page
96
100
def banner_url
Original file line number Diff line number Diff line change 1
1
# mostly from https://github.com/multiscan/middleman-navigation but modified slightly
2
2
module Navigation
3
-
4
- require 'redcarpet'
5
-
6
3
class << self
7
4
def registered ( app )
8
5
app . helpers HelperMethods
@@ -62,30 +59,6 @@ def children_nav(options={})
62
59
return content_tag :ul , menu_content , options
63
60
end
64
61
65
- def quick_links ( )
66
- links = [ ]
67
- page_src = File . read ( current_page . source_file )
68
- sections = page_src . scan /\n \# {2,3}[^#]+\# {2,3}\n /
69
-
70
- markdown = ''
71
-
72
- sections . each do |s |
73
-
74
- next if s . match ( /id='(.+)'/ ) . nil? or s . match ( /<\/ a>([^#.]+)\# {2,3}/ ) . nil?
75
-
76
- anchor_name = s . match ( /id='(.+)'/ ) [ 1 ]
77
- title = s . match ( /<\/ a>([^#.]+)\# {2,3}/ ) [ 1 ] . strip!
78
- indent = ( s . count ( '#' ) / 2 ) - 2
79
-
80
- markdown << ' ' * indent
81
- markdown << "* [#{ title } ](##{ anchor_name } )\n "
82
-
83
- end
84
-
85
- md = Redcarpet ::Markdown . new ( Redcarpet ::Render ::HTML )
86
- md . render ( markdown )
87
- end
88
-
89
62
# create an <ul> list with links to all the parent pages down to the root
90
63
def trail_nav ( ) # removed sep
91
64
p = current_page
Original file line number Diff line number Diff line change
1
+ module QuickLinks
2
+ require 'redcarpet'
3
+
4
+ class << self
5
+ def registered ( app )
6
+ app . helpers HelperMethods
7
+ end
8
+
9
+ alias :included :registered
10
+ end
11
+
12
+ module HelperMethods
13
+ def quick_links ( )
14
+ links = [ ]
15
+ page_src = File . read ( current_page . source_file )
16
+ sections = page_src . scan /\n \# {2,3}[^#]+\# {2,3}\n /
17
+
18
+ markdown = ''
19
+
20
+ sections . each do |s |
21
+
22
+ next if s . match ( /id=['"](.+)['"]/ ) . nil? or s . match ( /<\/ a>([^#.]+)\# {2,3}/ ) . nil?
23
+
24
+ anchor_name = s . match ( /id=['"](.+)['"]/ ) [ 1 ]
25
+ title = s . match ( /<\/ a>([^#.]+)\# {2,3}/ ) [ 1 ] . strip!
26
+ indent = ( s . count ( '#' ) / 2 ) - 2
27
+
28
+ markdown << ' ' * indent
29
+ markdown << "* [#{ title } ](##{ anchor_name } )\n "
30
+
31
+ end
32
+
33
+ md = Redcarpet ::Markdown . new ( Redcarpet ::Render ::HTML )
34
+ md . render ( markdown )
35
+ end
36
+ end
37
+ end
38
+
39
+ ::Middleman ::Extensions . register ( :quicklinks , QuickLinks )
You can’t perform that action at this time.
0 commit comments