@@ -81,6 +81,20 @@ def expand_l10n(path, content, get_f_content, categories, ext)
81
81
content
82
82
end
83
83
84
+ def extract_headings ( html )
85
+ doc = Nokogiri ::HTML ::DocumentFragment . parse ( html )
86
+ headings = [ ]
87
+
88
+ doc . css ( 'h2' ) . each do |heading |
89
+ headings << {
90
+ 'text' => heading . text . strip ,
91
+ 'id' => heading [ 'id' ]
92
+ }
93
+ end
94
+
95
+ headings
96
+ end
97
+
84
98
def index_l10n_doc ( filter_tags , doc_list , get_content )
85
99
rebuild = ENV . fetch ( "REBUILD_DOC" , nil )
86
100
rerun = ENV [ "RERUN" ] || rebuild || false
@@ -220,6 +234,11 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
220
234
"aliases" => [ "/docs/#{ path } /#{ lang } /index.html" ]
221
235
}
222
236
237
+ headings = extract_headings ( html )
238
+ if headings . length > 0
239
+ front_matter [ 'headings' ] = headings
240
+ end
241
+
223
242
FileUtils . mkdir_p ( doc_path )
224
243
File . open ( "#{ doc_path } /#{ lang } .html" , "w" ) do |out |
225
244
out . write ( wrap_front_matter ( front_matter ) )
@@ -525,6 +544,11 @@ def index_doc(filter_tags, doc_list, get_content)
525
544
"version" => doc_versions [ changed_in ] ,
526
545
}
527
546
547
+ headings = extract_headings ( html )
548
+ if headings . length > 0
549
+ front_matter [ 'headings' ] = headings
550
+ end
551
+
528
552
if changed_in != doc_version_index && File . exist? ( "#{ doc_path } /#{ version } .html" )
529
553
# remove obsolete file
530
554
File . delete ( "#{ doc_path } /#{ version } .html" )
@@ -736,3 +760,4 @@ def local_index_doc(index_fun)
736
760
else
737
761
abort ( "Need two arguments: (<path-to-repo> | remote) (en | l10n)!" )
738
762
end
763
+
0 commit comments