Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite documentation URL mapping to use the TOC #58

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ekohl
Copy link
Contributor

@ekohl ekohl commented Jul 26, 2024

Upstream builds various guides and each guide is built as a single large page. That page has many chapters. Technically every guide is also built into 3 flavors (foreman-deb, foreman-el, katello).

Downstream builds various guides, which mostly come from upstream. Most guides are a simple translation where they're downcased, but some are rewritten to something else.

A bigger difference is that each guide is built into multiple pages. This means we need to find the right page containing the chapter. The Table of Content contains a complete mapping with this information, so it can be looked up dynamically.

If this still can't be found, we use the html-single where everything is built into a single page. We then just hope it exists. Otherwise the browser will just show the whole page. This is an unexpected case, so a warning is logged.

The result is that a lot less maintenance is needed, because in most cases it will "just work". A downside is that it becomes hard to verify links are correct. It becomes needed to crawl through all of the source code for any documentation links, similar to how we crawl through it for translations.

Includes #59 and #60.

@ekohl ekohl changed the title Rewrite documentation URL mapping to use the TOC & access.redhat.com -> docs.redhat.com Rewrite documentation URL mapping to use the TOC Jul 26, 2024
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI jobs needs to be updated to reflect this

@ekohl ekohl force-pushed the use-documentation-toc-at-runtime branch from 4b5b68a to d64fff5 Compare July 26, 2024 13:18
@ekohl ekohl requested review from evgeni and ShimShtein July 26, 2024 13:18
@ekohl ekohl force-pushed the use-documentation-toc-at-runtime branch 2 times, most recently from 104d3ab to dbd265f Compare July 26, 2024 13:30
Copy link
Contributor Author

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShimShtein this builds on your TOC work. The aim is to reduce maintenance burden: it makes PRs like #45 not needed, meaning there's a greater change it'll "just work".

# An upstream chapter mapping, in case downstream another chapter should be
# used. The top level key is the upstream guide name where the value is a
# mapping of upstream chapter to downstream mapping
DOCS_GUIDE_CHAPTER_MAPPING = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's questionable if we really want this, but I kept it in since we had this.

DOCS_GUIDE_CHAPTER_MAPPING.each do |guide, chapters|
chapters.keys.each do |chapter|
url = ForemanThemeSatellite::Documentation.docs_url(guide, chapter)
failed["/#{guide}/#{chapter}"] = url if url.include?('/html-single/')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this reports correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will fail if the chapter is not recognized. But what about non-recognized guide? Is it possible to have one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The html-single code path is the unrecognized guide. I admit it's very indirect. Note that it can only be reached if it's not found in DOCS_GUIDE_PAGES (which is the TOC).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me rephrase: If I have a link without a chapter: just for the guide. It will not get into the if chapter block in the docs_url method, and will return <root>/non-existing-guide. Which is an error too, if I read the code correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There we assume guide.downcase returns the correct result, but you're right that we actually have a list of guides and can check. And I'll go through the list of current guides and add mappings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekohl ekohl force-pushed the use-documentation-toc-at-runtime branch 3 times, most recently from 17f09d8 to a257851 Compare July 26, 2024 13:54
@ekohl ekohl force-pushed the use-documentation-toc-at-runtime branch 2 times, most recently from 37095a9 to 52a5c42 Compare July 26, 2024 14:55
Copy link
Contributor

@ShimShtein ShimShtein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of using the TOC, although it's used here only for validation.

Maybe we should extend the idea to have an upstream-to-downstream mapping file, that would be maintained automatically, so we will be sure the chapter actually exists.

The idea is to have downstream_toc.json <-> upstream_toc.json connection. The algorithm for automatic transformation would be the same as you have pointed out here plus the manual overrides. Then once one of the TOC files gets updated, we can make sure we still have valid connection.

The idea is to ensure each upstream TOC entry has an equivalent downstream: either by automatic guessing (like the algo you have suggested in this PR) or by manual override (with a dictionary). This is much easier that try to hunt down all references to documentation in the code.
WDYT?

desc 'Validate documentation links against given TOC file'
task :validate_docs do
toc_file = ENV['TOC']
unless toc_file
toc_file = File.expand_path('../../test/fixtures/toc.json', __dir__)
toc_file = File.expand_path('../foreman_theme_satellite/documentation-toc.json', __dir__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require a change to the downstream CI

lib/foreman_theme_satellite/branded_words.rb Outdated Show resolved Hide resolved
DOCS_GUIDE_CHAPTER_MAPPING.each do |guide, chapters|
chapters.keys.each do |chapter|
url = ForemanThemeSatellite::Documentation.docs_url(guide, chapter)
failed["/#{guide}/#{chapter}"] = url if url.include?('/html-single/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will fail if the chapter is not recognized. But what about non-recognized guide? Is it possible to have one?

lib/foreman_theme_satellite/documentation.rb Outdated Show resolved Hide resolved
@ekohl ekohl force-pushed the use-documentation-toc-at-runtime branch 3 times, most recently from 5408d68 to 6461f1b Compare July 31, 2024 09:28
Copy link
Contributor

@ShimShtein ShimShtein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still waiting for you opinion about the joined TOC idea.

DOCS_GUIDE_CHAPTER_MAPPING.each do |guide, chapters|
chapters.keys.each do |chapter|
url = ForemanThemeSatellite::Documentation.docs_url(guide, chapter)
failed["/#{guide}/#{chapter}"] = url if url.include?('/html-single/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me rephrase: If I have a link without a chapter: just for the guide. It will not get into the if chapter block in the docs_url method, and will return <root>/non-existing-guide. Which is an error too, if I read the code correctly.

def test_docs_redirect_unknown_chapter
get "/links/docs/Managing_Hosts"

assert_redirected_to "https://docs.redhat.com/documentation/en-us/red_hat_satellite/#{ForemanThemeSatellite.documentation_version}/html/managing_hosts/"
end

def test_many
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we want to keep this, but it was a simple way for me to test if the old DOCS_GUIDES_LINKS were properly converted

Upstream builds various guides and each guide is built as a single large
page. That page has many chapters. Technically every guide is also built
into 3 flavors (foreman-deb, foreman-el, katello).

Downstream builds various guides, which mostly come from upstream. Most
guides are a simple translation where they're downcased, but some are
rewritten to something else.

A bigger difference is that each guide is built into multiple pages.
This means we need to find the right page containing the chapter. The
Table of Content contains a complete mapping with this information, so
it can be looked up dynamically.

If this still can't be found, we use the html-single where everything is
built into a single page. We then just hope it exists. Otherwise the
browser will just show the whole page. This is an unexpected case, so a
warning is logged.

The result is that a lot less maintenance is needed, because in most
cases it will "just work". A downside is that it becomes hard to verify
links are correct. It becomes needed to crawl through all of the source
code for any documentation links, similar to how we crawl through it for
translations.
@ekohl ekohl force-pushed the use-documentation-toc-at-runtime branch from 0406fef to 4dfad0b Compare August 12, 2024 16:03
@ekohl ekohl mentioned this pull request Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants