diff --git a/script/update-docs.rb b/script/update-docs.rb index 8d401b7703..5fa1b0f9b9 100644 --- a/script/update-docs.rb +++ b/script/update-docs.rb @@ -385,10 +385,11 @@ def index_l10n_doc(filter_tags, doc_list, get_content) end end - # Clean up orphaned translated outputs whose upstream source has gone away. - # Skipped entirely when no source was iterated (e.g. when the early `next if - # !rerun && l10n["committed"] >= ts` short-circuits the whole tag loop) so - # that an "everything is up to date" run never deletes anything. + # Clean up orphan translated outputs and the matching `data.json` entries + # whose upstream source has gone away. Skipped entirely when no source was + # iterated (e.g. when the early `next if !rerun && l10n["committed"] >= ts` + # short-circuits the whole tag loop) so that an "everything is up to date" + # run never deletes anything. unless seen_translations.empty? Dir.glob("#{SITE_ROOT}external/docs/content/docs/*/*.html").each do |output_path| m = output_path.match(%r{/external/docs/content/docs/([^/]+)/([^/]+)\.html\z}) @@ -407,6 +408,22 @@ def index_l10n_doc(filter_tags, doc_list, get_content) puts "Removing orphan translation #{output_path}" File.delete(output_path) end + + # `layouts/partials/ref/languages.html` iterates + # `data.pages..languages` on every English manual page to build + # the per-page language picker, so a stale entry here generates a dead + # link from every variant of every English page (including each + # versioned `/docs//.html` slice). Prune symmetrically + # with the file-deletion loop above. + data["pages"].each do |docname, page_data| + next unless page_data.is_a?(Hash) + langs = page_data["languages"] + next unless langs.is_a?(Hash) + langs.keys.reject { |lang| seen_translations.include?([docname, lang]) }.each do |lang| + puts "Removing orphan language entry data.pages.#{docname}.languages.#{lang}" + langs.delete(lang) + end + end end File.open(DATA_FILE, "w") do |out|