Skip to content

Commit 2b6bd2a

Browse files
committed
docs: add fall-back redirects for unrendered pages
There are quite a couple of pages we do not render, e.g. all of the `howto/` ones. The existing Rails App can get away with trying to redirect all unknown pages in `docs/` to the git/git repository via a generic wildcard pattern. In the static website, we do not have that luxury. But we can at least add corresponding redirects for missing pages that are linked to. While at it, work around a couple incorrect constructs such as `linkgit:../<...>` and `linkgit:technical/<...>`. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 22b45b0 commit 2b6bd2a

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

script/update-docs.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ def index_doc(filter_tags, doc_list, get_content)
310310
new_content
311311
end
312312

313+
check_paths = Set.new([])
314+
313315
doc_files.each do |entry|
314316
path, sha = entry
315317
ids = Set.new([])
@@ -355,6 +357,7 @@ def index_doc(filter_tags, doc_list, get_content)
355357
"<a href='https://curl.se/docs/manpage.html'>curl</a>"
356358
else
357359
relurl = "docs/#{x[1].gsub(/&#x2d;/, '-')}"
360+
check_paths.add(relurl)
358361
"<a href='{{< relurl \"#{relurl}\" >}}'>#{x[1]}[#{x[2]}]</a>"
359362
end
360363
end
@@ -368,7 +371,14 @@ def index_doc(filter_tags, doc_list, get_content)
368371
"<dt class=\"hdlist1\" id=\"#{anchor}\"> <a class=\"anchor\" href=\"##{anchor}\"></a>#{$1} </dt>"
369372
end
370373
# Make links relative
371-
html.gsub!(/(<a href=['"])\/([^'"]*)/, '\1{{< relurl "\2" >}}')
374+
html.gsub!(/(<a href=['"])\/([^'"]*)/) do |relurl|
375+
before = $1
376+
after = $2
377+
after.sub!(/^docs\/\.\.\//, 'docs/')
378+
after = 'pack-format' if after == 'technical/pack-format'
379+
check_paths.add(after.sub(/#.*/, ''))
380+
"#{before}{{< relurl \"#{after}\" >}}"
381+
end
372382

373383
doc_versions = version_map.keys.sort{|a, b| Version.version_to_num(a) <=> Version.version_to_num(b)}
374384
doc_version_index = doc_versions.index(version)
@@ -456,6 +466,32 @@ def index_doc(filter_tags, doc_list, get_content)
456466
end
457467
end
458468
end
469+
470+
# In some cases, documents are skipped from git-scm.com, e.g. the
471+
# `howto/` files. As a consequence, some links may point to locations
472+
# that are not populated. Let's redirect to the source files in the
473+
# git/git repository.
474+
check_paths.each do |path|
475+
doc_path = "#{SITE_ROOT}external/docs/content/#{path}.html"
476+
if !File.exists?(doc_path)
477+
type = 'blob'
478+
target = path.sub(/^docs\//, '')
479+
if target == 'api-index'
480+
type = 'tree'
481+
target = 'technical'
482+
elsif target == 'howto-index'
483+
type = 'tree'
484+
target = 'howto'
485+
else
486+
target += '.txt'
487+
end
488+
front_matter = { "redirect_to" => "https://github.com/git/git/#{type}/HEAD/Documentation/#{target}" } # ltrim `docs/`
489+
FileUtils.mkdir_p(File.dirname(doc_path))
490+
File.open(doc_path, "w") do |out|
491+
out.write(wrap_front_matter(front_matter))
492+
end
493+
end
494+
end
459495
end
460496
data["latest-version"] = version if !data["latest-version"] || Version.version_to_num(data["latest-version"]) < Version.version_to_num(version)
461497
end

0 commit comments

Comments
 (0)