@@ -68,18 +68,19 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
6868 rebuild = ENV . fetch ( "REBUILD_DOC" , nil )
6969 rerun = ENV [ "RERUN" ] || rebuild || false
7070
71+ data = read_data
72+ data [ "l10n" ] = { } unless data [ "l10n" ]
73+ l10n = data [ "l10n" ]
74+
7175 filter_tags . call ( rebuild , false ) . sort_by { |tag | Version . version_to_num ( tag . first [ 1 ..] ) } . each do |tag |
7276 name , commit_sha , tree_sha , ts = tag
7377 puts "#{ name } : #{ ts } , #{ commit_sha [ 0 , 8 ] } , #{ tree_sha [ 0 , 8 ] } "
7478
75- stag = Version . where ( name : name . gsub ( "v" , "l10n" ) ) . first_or_create
76-
77- next if ( stag . commit_sha == commit_sha ) && !rerun
79+ next if !rerun && l10n [ "committed" ] and l10n [ "committed" ] >= ts
7880
79- stag . commit_sha = commit_sha
80- stag . tree_sha = tree_sha
81- stag . committed = ts
82- stag . save
81+ l10n [ "commit_sha" ] = commit_sha
82+ l10n [ "tree_sha" ] = tree_sha
83+ l10n [ "committed" ] = ts
8384
8485 tag_files = doc_list . call ( tree_sha )
8586 doc_files = tag_files . select do |ent |
@@ -110,43 +111,74 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
110111 lang = File . dirname ( full_path )
111112 path = File . basename ( full_path , ".txt" )
112113
113- file = DocFile . where ( name : path ) . first_or_create
114+ doc_path = " #{ SITE_ROOT } external/docs/content/docs/ #{ path } "
114115
115116 puts " build: #{ path } for #{ lang } "
116117
118+ data [ "pages" ] [ path ] = {
119+ "version-map" => { }
120+ } unless data [ "pages" ] [ path ]
121+ page_data = data [ "pages" ] [ path ]
122+ page_data [ "languages" ] = { } unless page_data [ "languages" ]
123+ lang_data = page_data [ "languages" ]
124+
117125 content = get_content . call sha
118126 categories = { }
119127 expand_l10n ( full_path , content , get_content_f , categories )
120128 content . gsub! ( /link:(?:technical\/ )?(\S *?)\. html(\# \S *?)?\[ (.*?)\] /m , "link:/docs/\\ 1/#{ lang } \\ 2[\\ 3]" )
121129 asciidoc = make_asciidoc ( content )
122130 asciidoc_sha = Digest ::SHA1 . hexdigest ( asciidoc . source )
123- doc = Doc . where ( blob_sha : asciidoc_sha ) . first_or_create
124- if rerun || !doc . plain || !doc . html
125- html = asciidoc . render
126- html . gsub! ( /linkgit:(\S +?)\[ (\d +)\] / ) do |line |
127- x = /^linkgit:(\S +?)\[ (\d +)\] / . match ( line )
128- "<a href='/docs/#{ x [ 1 ] . gsub ( /-/ , '-' ) } /#{ lang } '>#{ x [ 1 ] } [#{ x [ 2 ] } ]</a>"
131+ if !File . exists? ( "#{ SITE_ROOT } external/docs/asciidoc/#{ asciidoc_sha } " )
132+ FileUtils . mkdir_p ( "#{ SITE_ROOT } external/docs/asciidoc" )
133+ File . open ( "#{ SITE_ROOT } external/docs/asciidoc/#{ asciidoc_sha } " , "w" ) do |out |
134+ out . write ( content )
129135 end
130- # HTML anchor on hdlist1 (i.e. command options)
131- html . gsub! ( /<dt class="hdlist1">(.*?)<\/ dt>/ ) do |_m |
132- text = $1. tr ( "^A-Za-z0-9-" , "" )
133- anchor = "#{ path } -#{ text } "
134- # handle anchor collisions by appending -1
135- anchor += "-1" while ids . include? ( anchor )
136- ids . add ( anchor )
136+ end
137137
138- "<dt class=\" hdlist1\" id=\" #{ anchor } \" > <a class=\" anchor\" href=\" ##{ anchor } \" ></a>#{ $1} </dt>"
139- end
140- doc . plain = asciidoc . source
141- doc . html = html
142- doc . save
138+ next if !rerun && lang_data [ lang ] == asciidoc_sha
139+
140+ html = asciidoc . render
141+ html . gsub! ( /linkgit:(\S +?)\[ (\d +)\] / ) do |line |
142+ x = /^linkgit:(\S +?)\[ (\d +)\] / . match ( line )
143+ relurl = "docs/#{ x [ 1 ] . gsub ( /-/ , '-' ) } /#{ lang } "
144+ "<a href='{{< relurl \" #{ relurl } \" >}}'>#{ x [ 1 ] } [#{ x [ 2 ] } ]</a>"
145+ end
146+ # HTML anchor on hdlist1 (i.e. command options)
147+ html . gsub! ( /<dt class="hdlist1">(.*?)<\/ dt>/ ) do |_m |
148+ text = $1. tr ( "^A-Za-z0-9-" , "" )
149+ anchor = "#{ path } -#{ text } "
150+ # handle anchor collisions by appending -1
151+ anchor += "-1" while ids . include? ( anchor )
152+ ids . add ( anchor )
153+
154+ "<dt class=\" hdlist1\" id=\" #{ anchor } \" > <a class=\" anchor\" href=\" ##{ anchor } \" ></a>#{ $1} </dt>"
143155 end
144- dv = DocVersion . where ( version_id : stag . id , doc_file_id : file . id , language : lang ) . first_or_create
145- dv . doc_id = doc . id
146- dv . language = lang
147- dv . save
156+ # Make links relative
157+ html . gsub! ( /(<a href=['"])\/ ([^'"]*)/ , '\1{{< relurl "\2" >}}' )
158+
159+ # Write <docname>/<lang>.html
160+ front_matter = {
161+ "category" => "manual" ,
162+ "section" => "documentation" ,
163+ "subsection" => "manual" ,
164+ "title" => "Git - #{ path } Documentation" ,
165+ "docname" => path ,
166+ "lang" => lang ,
167+ "aliases" => [ "/docs/#{ path } /#{ lang } /index.html" ]
168+ }
169+
170+ FileUtils . mkdir_p ( doc_path )
171+ File . open ( "#{ doc_path } /#{ lang } .html" , "w" ) do |out |
172+ out . write ( wrap_front_matter ( front_matter ) )
173+ out . write ( html )
174+ end
175+
176+ lang_data [ lang ] = asciidoc_sha
148177 end
149178 end
179+ File . open ( DATA_FILE , "w" ) do |out |
180+ YAML . dump ( data , out )
181+ end
150182end
151183
152184def drop_uninteresting_tags ( tags )
0 commit comments