Skip to content

Commit a74b38c

Browse files
committed
script/update-docs: add support for .adoc files
Since 2.49.0 the documentation files are named with the .adoc extension. Adapt the script to support that. Signed-off-by: Toon Claes <[email protected]>
1 parent 00fc134 commit a74b38c

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

script/update-docs.rb

+18-14
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,20 @@ def drop_uninteresting_tags(tags)
254254
ret
255255
end
256256

257-
def expand_content(content, path, get_f_content, generated)
258-
content.gsub(/include::(?:{build_dir}\/)?(\S+)\.txt\[\]/) do |_line|
257+
def expand_content(content, path, get_f_content, generated, ext)
258+
content.gsub(/include::(?:{build_dir}\/)?(\S+)\.#{ext}\[\]/) do |_line|
259259
if File.dirname(path) == "."
260-
new_fname = "#{$1}.txt"
260+
new_fname = "#{$1}.#{ext}"
261261
else
262-
new_fname = (Pathname.new(path).dirname + Pathname.new("#{$1}.txt")).cleanpath.to_s
262+
new_fname = (Pathname.new(path).dirname + Pathname.new("#{$1}.#{ext}")).cleanpath.to_s
263263
end
264264
if generated[new_fname]
265265
new_content = generated[new_fname]
266266
else
267267
new_content = get_f_content.call(new_fname)
268268
if new_content
269269
new_content = expand_content(new_content.force_encoding("UTF-8"),
270-
new_fname, get_f_content, generated)
270+
new_fname, get_f_content, generated, ext)
271271
else
272272
puts "#{new_fname} could not be resolved for expansion"
273273
end
@@ -319,6 +319,7 @@ def index_doc(filter_tags, doc_list, get_content)
319319
version_data["committed"] = ts
320320
version_data["date"] = ts.strftime("%m/%d/%y")
321321

322+
ext = Version.version_to_num(version) < 2_490_000 ? 'txt' : 'adoc'
322323
tag_files = doc_list.call(tree_sha)
323324
doc_files = tag_files.select do |ent|
324325
ent.first =~
@@ -336,8 +337,8 @@ def index_doc(filter_tags, doc_list, get_content)
336337
pull.* |
337338
scalar |
338339
technical\/.*
339-
)\.txt)$/x or
340-
docs_extra["git_project_specific"].include?(ent.first.sub(/^Documentation\/(.*?)(\.txt|\.adoc)?$/, '\1'))
340+
)\.#{ext})$/x or
341+
docs_extra["git_project_specific"].include?(ent.first.sub(/^Documentation\/(.*?)(\.#{ext})?$/, '\1'))
341342
end
342343

343344
puts "Found #{doc_files.size} entries"
@@ -398,10 +399,11 @@ def index_doc(filter_tags, doc_list, get_content)
398399

399400
doc_files.each do |entry|
400401
path, sha = entry
402+
txt_path = path.sub(/\.adoc$/, '.txt')
401403
ids = Set.new([])
402-
docname = File.basename(path, ".txt")
404+
docname = File.basename(txt_path, ".txt")
403405
# TEMPORARY: skip the scalar technical doc until it has a non-overlapping name
404-
next if path == "Documentation/technical/scalar.txt"
406+
next if txt_path == "Documentation/technical/scalar.txt"
405407
next if doc_limit && path !~ /#{doc_limit}/
406408

407409
doc_path = "#{SITE_ROOT}external/docs/content/docs/#{docname}"
@@ -413,19 +415,19 @@ def index_doc(filter_tags, doc_list, get_content)
413415
} unless data["pages"][docname]
414416
page_data = data["pages"][docname]
415417

416-
content = expand_content((get_content.call sha).force_encoding("UTF-8"), path, get_content_f, generated)
418+
content = expand_content((get_content.call sha).force_encoding("UTF-8"), path, get_content_f, generated, ext)
417419
# Handle `link:../howto/maintain-git.txt`, which should point to
418420
# a `.html` target instead
419-
content.gsub!(/link:\.\.\/howto\/maintain-git\.txt/, 'link:../howto/maintain-git.html')
421+
content.gsub!(/link:\.\.\/howto\/maintain-git\.#{ext}/, 'link:../howto/maintain-git.html')
420422
# Handle `gitlink:` mistakes (the last of which was fixed in
421423
# dbf47215e32b (rebase docs: fix "gitlink" typo, 2019-02-27))
422424
content.gsub!(/gitlink:/, "linkgit:")
423425
# Handle erroneous `link:api-trace2.txt`, see 4945f046c7f5 (api docs:
424426
# link to html version of api-trace2, 2022-09-16)
425-
content.gsub!(/link:api-trace2.txt/, 'link:api-trace2.html')
427+
content.gsub!(/link:api-trace2.#{ext}/, 'link:api-trace2.html')
426428
# Handle `linkgit:git-config.txt` mistake, fixed in ad52148a7d0
427429
# (Documentation: fix broken linkgit to git-config, 2016-03-21)
428-
content.gsub!(/linkgit:git-config.txt/, 'linkgit:git-config')
430+
content.gsub!(/linkgit:git-config.#{ext}/, 'linkgit:git-config')
429431
content.gsub!(/link:(?:technical\/)?(\S*?)\.html(\#\S*?)?\[(.*?)\]/m, "link:/docs/\\1\\2[\\3]")
430432

431433
asciidoc = make_asciidoc(content)
@@ -457,7 +459,9 @@ def index_doc(filter_tags, doc_list, get_content)
457459
# HTML anchor on hdlist1 (i.e. command options)
458460
html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |_m|
459461
text = $1.tr("^A-Za-z0-9-", "")
460-
anchor = "#{path}-#{text}"
462+
# use txt_path for backward compatibility of already-existing
463+
# deep links shared across the interwebs.
464+
anchor = "#{txt_path}-#{text}"
461465
# handle anchor collisions by appending -1
462466
anchor += "-1" while ids.include?(anchor)
463467
ids.add(anchor)

0 commit comments

Comments
 (0)