@@ -81,6 +81,20 @@ def expand_l10n(path, content, get_f_content, categories, ext)
8181 content
8282end
8383
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+
8498def index_l10n_doc ( filter_tags , doc_list , get_content )
8599 rebuild = ENV . fetch ( "REBUILD_DOC" , nil )
86100 rerun = ENV [ "RERUN" ] || rebuild || false
@@ -220,6 +234,11 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
220234 "aliases" => [ "/docs/#{ path } /#{ lang } /index.html" ]
221235 }
222236
237+ headings = extract_headings ( html )
238+ if headings . length > 0
239+ front_matter [ 'headings' ] = headings
240+ end
241+
223242 FileUtils . mkdir_p ( doc_path )
224243 File . open ( "#{ doc_path } /#{ lang } .html" , "w" ) do |out |
225244 out . write ( wrap_front_matter ( front_matter ) )
@@ -525,6 +544,11 @@ def index_doc(filter_tags, doc_list, get_content)
525544 "version" => doc_versions [ changed_in ] ,
526545 }
527546
547+ headings = extract_headings ( html )
548+ if headings . length > 0
549+ front_matter [ 'headings' ] = headings
550+ end
551+
528552 if changed_in != doc_version_index && File . exist? ( "#{ doc_path } /#{ version } .html" )
529553 # remove obsolete file
530554 File . delete ( "#{ doc_path } /#{ version } .html" )
@@ -736,3 +760,4 @@ def local_index_doc(index_fun)
736760else
737761 abort ( "Need two arguments: (<path-to-repo> | remote) (en | l10n)!" )
738762end
763+
0 commit comments