Tip
The docs as explained here are used in multiple projects, but documented only once for better maintenance. When applying this to other projects, remember that some things such as the name, repository, or paths are a bit different.
Docs: Find Permalink Implementation
Warning
This is a technical documentation about how the documentation system works. It helps the core team understand how to maintain and enhance the documentation system.
It's not meant for most contributors, as it's too technical.
Goals
- We want to be able to link to docs easily from external places
- These links should not break when the docs change
- ...so we need the ability to update the target if the docs ever do change
- The link should be obvious where it goes, if ever something more dramatic is changed
- Most links will link to code, such as namespaces etc.
- The links should be obvious where they should go, in case things still change - so no cryptic /xy920f
The Parts that Make it Work
- DocFx uses the concept of
XREF
links, which are either API references, or documentation pages having auid
. - Inside DocFx this is used extensively, and to make sure the docs don't change, are also maintained.
- On each compile of the docs, a
xrefmap.yml
is created in the dist, which maps alluid
to the actual URL. - We can also introduce custom redirects for older XREFS which changed, in the
xrefmap.yml
in the source.
Now all we need is
- A JavaScript which loads the final/latest
xrefmap.yml
and can resolve theuid
to the URL - A page which runs this JS, takes the
xref=
parameter from the URL and redirects to the target URL - Some minor options to cancel the redirect etc. for better debugging.
Implementation
- The
xrefmap.yml
is loaded by thexref.ts
script in theshared-global
template - The
xref.ts
script is loaded on all pages, so it's always available - ...but it checks if it's on the special
find.html
page, and only runs there - The
xref.ts
script will parse the URL, look forxref=
and then redirect to the target URL - If the target URL is not found, it will show a message and not redirect
- If the target URL is found, it will redirect after 1 second
In addition, there is a bit more magic on the fid.html
page (which comes from the find.md
markdown file):
- The
find.html
page has some named HTML elements where the JS will place the values for better understanding and debugging. - It also has instructions so the user could - for 1 second - see what's happening and could cancel the redirect.
- It also has a hidden element which will be shown if the user cancels the redirect.
History of the Find Permalink System
- ca. 2022 introduced it as
/xref.html
and the shortlink go.2sxc.org/xref17 (as we initially thought we want the 2sxc version in there) - 2024-12-12 reduced the time to redirect to 1 second
- 2025-02-15 changed to use
find.html
, enhanced instructions and updated the redirects - 2025-02-15 changed the main redirect to be
https://go.2sxc.org/find
instead ofxref
and without the version number - 2025-02-15 updated the documentation for clarity and accuracy
- 2025-02-15 added more detail on the handling of
uid
inxref.ts