Skip to content

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Mar 31, 2020

The base href caused browsers to produce incorrect URLs for anchor links on various pages, for example, pointing to:

https://docs-test.docker.com/engine/reference/#foreground

Instead of

https://docs-test.docker.com/engine/reference/run/#foreground

While there might be links generated incorrectly (links including .md), we should fix those when generating the HTML instead of trying to fix them up using JavaScript.

Unfortunately, Jekyll doesn't process links to markdown files in includes, so for includes in this repository, these were changed to "absolute" "html" links (not linking to Markdown). After that, the only place we need the JavaScript link fix is within the reference docs.

I rewrite the script to be more efficient, documented each step (sorry, quite verbose on the comments), and limited its scope to only run on the reference docs, and on those, only on links within the "content".

fixes #2655
fixes #10647

relates to #247
relates to #8070
relates to #6772
relates to #5711
relates to #5388
relates to #3952
relates to #2655

@thaJeztah
Copy link
Member Author

opening as draft, as we first need the links fixed; #10548

@thaJeztah thaJeztah marked this pull request as ready for review April 1, 2020 11:11
@thaJeztah thaJeztah changed the title [WIP] Template: remove "base href" and javascript link-fixing Template: remove "base href" and javascript link-fixing Apr 3, 2020
@thaJeztah thaJeztah changed the title Template: remove "base href" and javascript link-fixing [WIP] Template: remove "base href" and javascript link-fixing Apr 8, 2020
@thaJeztah
Copy link
Member Author

Temporarily moving back to "WIP", as I still see issues occurring of incorrect links being generated; let me investigate if there's a configuration that I can change

We cannot use relative links in includes, because:

- The jekyll-relative-links, is not called on includes, so
  markdown-links are rendered as-is.
- These files are included in various locations on the website;
  because of that, it's not possible to compose a relative link
  to other Markdown files, so we're falling back to using absolute
  URLs, relative to the root of the website.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- remove some redundant whitespace
- use "remove_first" instead of "replace", because the strings to
  replace should only occur once.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Removing this "check" because it made the template difficult to
read, and duilding the docs won't fail if these values are missing.

If a page is empty, it's probably fast to find why anyway.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
When generating HTML pages, Jekyll will generate a directory named after the name
of the Markdown file, and generate an index.html file inside that directory. For
example, for a markdown file named /foo/bar/mypage.md, Jekyll generates a HTML
file named  /foo/bar/mypage/index.html.

This means that all links relative to mypage.md, and expect those links to be
relative to the /foo/bar/ directory, will actually end up being relative to
/foo/bar/mypage/.

Unfortunately, Jekyll / Liquid does not have a variable that holds the parent
directory of the _markdown_ file, so we have to generate it by taking `page.path`
(which holds the absolute path of the markdownfile), and remove the filename from
that path.

After generating that path, we prepend that path to URLs linking to related
commands (parent commands and child commands), as all reference files are in the
same path.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah changed the title [WIP] Template: remove "base href" and javascript link-fixing Template: remove "base href" and fix javascript link-fixing Apr 23, 2020
@thaJeztah
Copy link
Member Author

@usha-mandya @StefanScherer @silvin-lubecki I separated this from #10615 again; this should be ready for review, and fixes #10647

@netlify
Copy link

netlify bot commented Apr 23, 2020

Deploy preview for docsdocker ready!

Built with commit 342660f

https://deploy-preview-10549--docsdocker.netlify.app

- remove some stray empty lines
- put liquid code that was before the opening HTML inside a HTML
  comment, to prevent IDE's from marking it as invalid HTML
- fix some indentation
- fix some minor linting issues

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The base href caused browsers to produce incorrect URLs for
anchor links on various pages, for example, pointing to:

    https://docs-test.docker.com/engine/reference/#foreground

Instead of

    https://docs-test.docker.com/engine/reference/run/#foreground

Also cleaning up and fixing the JavaScript workaround for links
in include-files;

- only fix up links in the main content, not in other parts
  of the page
- don't fix up anchor links, absolute links, or links that don't
  contain `.md`: for those we can assume they were generated
  correctly, and if not, those are links that should be fixed in
  the markdown source, not fixed afterwards.
- document the function for future readers.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The JavaScript "link fix" looks to be only needed for pages
where Markdown is included, and which contain relative links.

Now that we modified all local includes to use absolute links,
the only location where links are not properly generated, is
in the reference documentation.

If broken links are found elsewhere in the website, those links
are legitimately broken, and should be fixed in the markdown
source, not fixed-up afterwards.

This patch moves the javascript to the cli.md include, so that
the script is only run on the reference pages instead of on every
page.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Now that we no longer have a baseURL, we can simplify the generated
links to just contain the anchor. This also provents issues if the
visited page already has an anchor set.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Copy link
Member

@StefanScherer StefanScherer left a comment

Choose a reason for hiding this comment

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

SGTM

I tested a bit in the /docker-for-windows/troubleshoot page and I couldn't find a problem.

Copy link
Member

@usha-mandya usha-mandya left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @thaJeztah

@usha-mandya usha-mandya merged commit 0fffff2 into docker:master Apr 23, 2020
@thaJeztah thaJeztah deleted the remove_base_href branch April 23, 2020 11:01
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.

Some Docker Desktop for Windows Troubleshooting links are self-referential Dead link on page

3 participants