Skip to content

Commit d1d6a35

Browse files
authored
Merge pull request #1976 from dscho/l10n-adoc
`script/update-docs.rb`(l10n): add support for .adoc files
2 parents 4240b0c + 0b97bcd commit d1d6a35

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

script/update-docs.rb

+13-8
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ def wrap_front_matter(front_matter)
6262
"#{front_matter.to_yaml.sub("---\n", "---\n#{content_note}\n")}---\n"
6363
end
6464

65-
def expand_l10n(path, content, get_f_content, categories)
66-
content.gsub!(/include::({build_dir}\/)?(\S+)\.txt/) do |line|
65+
def expand_l10n(path, content, get_f_content, categories, ext)
66+
content.gsub!(/include::({build_dir}\/)?(\S+)\.#{ext}/) do |line|
6767
line.gsub!("include::", "")
6868
if categories[line]
6969
new_content = categories[line]
7070
else
7171
new_content, new_path = get_f_content.call(path, line)
7272
end
7373
if new_content
74-
expand_l10n(new_path, new_content, get_f_content, categories)
74+
expand_l10n(new_path, new_content, get_f_content, categories, ext)
7575
else
7676
"\n\n[WARNING]\n====\nMissing `#{new_path}`\n\nSee original version for this content.\n====\n\n"
7777
end
@@ -89,22 +89,24 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
8989

9090
filter_tags.call(rebuild, false).sort_by { |tag| Version.version_to_num(tag.first[1..]) }.each do |tag|
9191
name, commit_sha, tree_sha, ts = tag
92-
puts "#{name}: #{ts}, #{commit_sha[0, 8]}, #{tree_sha[0, 8]}"
92+
puts "#{name}: #{ts}, #{commit_sha[0, 8]}, #{tree_sha[0, 8]}", ts
9393

9494
next if !rerun && l10n["committed"] and l10n["committed"] >= ts
9595

9696
l10n["commit_sha"] = commit_sha
9797
l10n["tree_sha"] = tree_sha
9898
l10n["committed"] = ts
9999

100+
ext = ts < Time.parse('2025-03-03 18:00:56 +0100') ? 'txt' : 'adoc'
101+
100102
tag_files = doc_list.call(tree_sha)
101103
doc_files = tag_files.select do |ent|
102104
ent.first =~
103105
/^([-_\w]+)\/(
104106
(
105107
git.* |
106108
scalar
107-
)\.txt)/x
109+
)\.#{ext})/x
108110
end
109111

110112
puts "Found #{doc_files.size} entries"
@@ -126,7 +128,8 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
126128
full_path, sha = entry
127129
ids = Set.new([])
128130
lang = File.dirname(full_path)
129-
path = File.basename(full_path, ".txt")
131+
path = File.basename(full_path, ".#{ext}")
132+
txt_path = path.sub(/\.adoc$/, '.txt')
130133

131134
doc_path = "#{SITE_ROOT}external/docs/content/docs/#{path}"
132135

@@ -141,7 +144,7 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
141144

142145
content = get_content.call sha
143146
categories = {}
144-
expand_l10n(full_path, content, get_content_f, categories)
147+
expand_l10n(full_path, content, get_content_f, categories, ext)
145148
content.gsub!(/link:(?:technical\/)?(\S*?)\.html(\#\S*?)?\[(.*?)\]/m) do |match|
146149
check_paths.add("docs/#{$1}/#{lang}")
147150
"link:/docs/#{$1}/#{lang}#{$2}[#{$3}]"
@@ -172,7 +175,9 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
172175
# HTML anchor on hdlist1 (i.e. command options)
173176
html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |_m|
174177
text = $1.tr("^A-Za-z0-9-", "")
175-
anchor = "#{path}-#{text}"
178+
# use txt_path for backward compatibility of already-existing
179+
# deep links shared across the interwebs.
180+
anchor = "#{txt_path}-#{text}"
176181
# handle anchor collisions by appending -1
177182
anchor += "-1" while ids.include?(anchor)
178183
ids.add(anchor)

0 commit comments

Comments
 (0)