-
Notifications
You must be signed in to change notification settings - Fork 353
DOC-6909 Add link render hook to replace relref (investigation) #3732
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
Closed
andy-stark-redis
wants to merge
20
commits into
main
from
DOC-6909-investigate-alternatives-to-hugo-shortcodes
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
61b6ee1
DOC-6909 Add link render hook to replace relref, with coexistence fin…
andy-stark-redis 03de590
DOC-6909 Resolve page-bundle resource links in the render hook
andy-stark-redis 96cd672
DOC-6909 Normalise leading ./ in render-hook link resolution
andy-stark-redis 22f3cf6
DOC-6909 Use .PageInner and split fragment links in the render hook
andy-stark-redis 7d340dc
DOC-6909 Document tooling that assumes relref (review follow-up)
andy-stark-redis c4e3953
DOC-6909 Record diverse-section stress-test results in the assessment
andy-stark-redis 93abb35
DOC-6909 Harden render-hook anchor handling (safeURL + first-# split)
andy-stark-redis f8bfc62
DOC-6909 Record versioned-tree stress-test result in the assessment
andy-stark-redis e5665e0
DOC-6909 Fix broken links surfaced by the render-hook investigation
andy-stark-redis 49b53ca
DOC-6909 Fix the remaining pre-existing broken links surfaced by the …
andy-stark-redis ce39f5b
DOC-6909 Remove aggregations-syntax note linking a non-existent dataset
andy-stark-redis c7dd76f
DOC-6909 Migrate develop/clients/redis-py links from relref to plain …
andy-stark-redis f29556e
DOC-6909 Add blockquote-alert render hook (portable callouts)
andy-stark-redis 3139628
DOC-6909 Migrate redis-py callouts from note shortcodes to blockquote…
andy-stark-redis 2422cff
DOC-6909 Make redis-py links source-relative (portable end state)
andy-stark-redis c1ba272
DOC-6909 Revert RedisVL doc edits (externally synced, would be overwr…
andy-stark-redis 07328c9
DOC-6909 Restore RedisVL link fixes (keep in this PR)
andy-stark-redis 3315a24
DOC-6909 Use repo-root-relative /content/ links for redis-py
andy-stark-redis f351060
DOC-6909 Rewrite /content/ links in the AI Markdown and JSON output
andy-stark-redis 34f9577
DOC-6909 Version plain /content/ links when archiving a version
andy-stark-redis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Test script for version_archiver's link versioning. | ||
|
|
||
| When a version is archived, intra-product links must point at the frozen copy, | ||
| not at latest. The archiver originally rewrote only `relref`, so a section | ||
| migrated to plain Markdown links (DOC-6909) was silently left pointing at | ||
| latest -- wrong content in an archived version, with no error or warning. | ||
|
|
||
| These tests cover both notations, the guards they share, and the forms that must | ||
| NOT be touched. | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
| import tempfile | ||
|
|
||
| # Add the build directory to the path | ||
| sys.path.insert(0, os.path.dirname(__file__)) | ||
|
|
||
| from version_archiver import VersionArchiver | ||
|
|
||
|
|
||
| def archive(product, version, page_relpath, content): | ||
| """Run the real version_relrefs() over one page in an isolated tree. | ||
|
|
||
| page_relpath is relative to the versioned directory, so nesting can be | ||
| realistic -- it matters for source-relative links, which resolve against the | ||
| page's own location. | ||
| """ | ||
| cwd = os.getcwd() | ||
| with tempfile.TemporaryDirectory() as tmp: | ||
| arch_cwd = tmp | ||
| os.chdir(arch_cwd) | ||
| try: | ||
| archiver = VersionArchiver(product, version) | ||
| page = os.path.join(archiver.new_directory, page_relpath) | ||
| os.makedirs(os.path.dirname(page), exist_ok=True) | ||
| with open(page, "w") as f: | ||
| f.write(content) | ||
| archiver.version_relrefs() | ||
| with open(page) as f: | ||
| return f.read() | ||
| finally: | ||
| os.chdir(cwd) | ||
|
|
||
|
|
||
| DEEP = os.path.join("databases", "configure", "page.md") | ||
|
|
||
|
|
||
| def test_relref_is_versioned(): | ||
| """The original behaviour: an intra-product relref gains the version.""" | ||
| out = archive("rs", "9.9", DEEP, | ||
| '[a]({{< relref "/operate/rs/databases/memory/eviction" >}})') | ||
| assert "/operate/rs/9.9/databases/memory/eviction" in out, out | ||
| print("✓ relref link is versioned") | ||
|
|
||
|
|
||
| def test_plain_content_link_is_versioned(): | ||
| """DOC-6909's repo-root-relative form must be versioned the same way.""" | ||
| out = archive("rs", "9.9", DEEP, | ||
| '[b](/content/operate/rs/databases/memory/eviction.md)') | ||
| assert "](/content/operate/rs/9.9/databases/memory/eviction.md)" in out, out | ||
| print("✓ plain /content/ link is versioned") | ||
|
|
||
|
|
||
| def test_plain_content_link_keeps_anchor(): | ||
| """An anchor must survive versioning.""" | ||
| out = archive("rs", "9.9", DEEP, | ||
| '[c](/content/operate/rs/databases/memory/eviction.md#policies)') | ||
| assert "/operate/rs/9.9/databases/memory/eviction.md#policies" in out, out | ||
| print("✓ anchor preserved when versioning a plain link") | ||
|
|
||
|
|
||
| def test_source_relative_link_is_left_alone(): | ||
| """Source-relative links need no rewriting and must not be touched. | ||
|
|
||
| The whole subtree is copied, so a link between two pages inside it already | ||
| resolves within the versioned directory. | ||
| """ | ||
| link = '[d](../memory/eviction.md)' | ||
| out = archive("rs", "9.9", DEEP, link) | ||
| assert out == link, out | ||
| # and confirm the claim: it resolves inside the frozen tree | ||
| page_dir = os.path.join("content", "operate", "rs", "9.9", | ||
| os.path.dirname(DEEP)) | ||
| resolved = os.path.normpath(os.path.join(page_dir, "../memory/eviction.md")) | ||
| assert resolved.startswith(os.path.join("content", "operate", "rs", "9.9")), resolved | ||
| print("✓ source-relative link untouched, and resolves inside the version") | ||
|
|
||
|
|
||
| def test_release_notes_are_exempt(): | ||
| """Release notes are deliberately not versioned, in either notation.""" | ||
| both = ('[e]({{< relref "/operate/rs/release-notes/rs-7-8" >}})\n' | ||
| '[f](/content/operate/rs/release-notes/rs-7-8.md)') | ||
| out = archive("rs", "9.9", DEEP, both) | ||
| assert out == both, out | ||
| print("✓ release-notes links exempt in both notations") | ||
|
|
||
|
|
||
| def test_already_versioned_is_idempotent(): | ||
| """Re-running must not double-version an already-versioned link.""" | ||
| both = ('[g]({{< relref "/operate/rs/9.9/databases/memory/eviction" >}})\n' | ||
| '[h](/content/operate/rs/9.9/databases/memory/eviction.md)') | ||
| out = archive("rs", "9.9", DEEP, both) | ||
| assert out == both, out | ||
| assert "9.9/9.9" not in out, out | ||
| print("✓ already-versioned links are left alone (idempotent)") | ||
|
|
||
|
|
||
| def test_other_product_and_external_urls_untouched(): | ||
| """Only the product being archived is rewritten, and external URLs are safe. | ||
|
|
||
| The GitHub blob URL is the important one: it contains the substring | ||
| '/content/operate/rs/', so the pattern must anchor on a link destination | ||
| ('](/content/...') rather than matching anywhere in the line. | ||
| """ | ||
| content = ('[i](/content/operate/kubernetes/deploy/quickstart.md)\n' | ||
| '[j](https://github.com/redis/docs/blob/main/content/operate/rs/x.md)\n' | ||
| '[k]({{< relref "/develop/data-types/hashes" >}})') | ||
| out = archive("rs", "9.9", DEEP, content) | ||
| assert out == content, out | ||
| print("✓ other products, external URLs and other sections untouched") | ||
|
|
||
|
|
||
| def test_other_products_use_their_own_prefix(): | ||
| """The pattern is parameterised, so non-'operate' products work too.""" | ||
| out = archive("redis-data-integration", "1.20", DEEP, | ||
| '[l](/content/integrate/redis-data-integration/reference/config.md)') | ||
| assert "/integrate/redis-data-integration/1.20/reference/config.md" in out, out | ||
| print("✓ redis-data-integration (integrate prefix) is versioned") | ||
|
|
||
|
|
||
| def main(): | ||
| tests = [ | ||
| test_relref_is_versioned, | ||
| test_plain_content_link_is_versioned, | ||
| test_plain_content_link_keeps_anchor, | ||
| test_source_relative_link_is_left_alone, | ||
| test_release_notes_are_exempt, | ||
| test_already_versioned_is_idempotent, | ||
| test_other_product_and_external_urls_untouched, | ||
| test_other_products_use_their_own_prefix, | ||
| ] | ||
| try: | ||
| for t in tests: | ||
| t() | ||
| print("\n✅ All tests passed!") | ||
| return 0 | ||
| except AssertionError as e: | ||
| print(f"\n❌ Test failed: {e}") | ||
| return 1 | ||
| except Exception as e: | ||
| print(f"\n❌ Unexpected error: {e}") | ||
| import traceback | ||
| traceback.print_exc() | ||
| return 1 | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.