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

Fix relative URLs when serving the specification with a custom baseURL #1984

Merged
merged 11 commits into from
Nov 14, 2024

Conversation

zecakeh
Copy link
Contributor

@zecakeh zecakeh commented Oct 24, 2024

Requires matrix-org/docsy#4.

Using canonifyURLs and a baseURL that is not / at the same time makes .RelPermalink and relref return relative URLs where the first path segment is duplicated, e.g. /v1.11/v1.11/rest/of/the/path.

canonifyURLs is deprecated so let's get rid of it and allow Hugo to compute the relative URLs itself, because it keeps track of the resources and knows where they will be served.

This can be reviewed commit by commit.

Since the PR CI uses / as a baseURL, I guess the only way to test that this works before it is deployed is to generate the spec locally with a custom baseURL like /v1.11 and make sure that there are no URLs where it is duplicated.

Closes #1957.
Fixes the causes behind #1964, but the artifacts that were already generated for v1.11 and v1.12 still need to be fixed somehow.

Pull Request Checklist

Preview: https://pr1984--matrix-spec-previews.netlify.app

@zecakeh zecakeh requested a review from a team as a code owner October 24, 2024 10:34
@zecakeh zecakeh marked this pull request as draft October 24, 2024 13:27
@zecakeh
Copy link
Contributor Author

zecakeh commented Oct 24, 2024

Leaving as a draft for now, it turns out that it creates broken links in places (see CI).

All the broken links are declared as only a fragment. For some of them, it's good that they are broken, because the need at least the spec path, otherwise it means that they are also broken in the generated OpenAPI definitions. But other fragments should just work, like the ones inside info boxes.

@zecakeh
Copy link
Contributor Author

zecakeh commented Oct 24, 2024

Alright the issues have been fixed, but I am leaving this as a draft for now until the docsy PR is merged.

So the good news is that now some links that would have been broken in the OpenAPI definitions are also broken in the rendered spec, and we detect them in CI thanks to htmltest.

Signed-off-by: Kévin Commaille <[email protected]>
Helps Hugo to generate the correct links for files in /static.

Signed-off-by: Kévin Commaille <[email protected]>
It is deprecated and messes with relative links when used with some baseURLs.

Signed-off-by: Kévin Commaille <[email protected]>
Now that relative links are fixed, having it enabled is not a problem anymore.

Signed-off-by: Kévin Commaille <[email protected]>
Signed-off-by: Kévin Commaille <[email protected]>
Otherwise the `relref` in the changelogs does not work.
Version 0.124.1 is the last version of Hugo to work with the current
version of the docsy theme.

Signed-off-by: Kévin Commaille <[email protected]>
This causes issues for links as the method doesn't have
the right context to resolve them.
The content is already markdownified because of the `%` syntax of the shortcode
that calls it, and it has the right context.

Signed-off-by: Kévin Commaille <[email protected]>
Links that contain only a fragment are not resolved by Hugo so the final relative URL is wrong.
They also cause problems for the OpenAPI definitions because these links are
not edited in the dump-openapi script so they end up broken.

Signed-off-by: Kévin Commaille <[email protected]>
@zecakeh zecakeh marked this pull request as ready for review November 1, 2024 10:54
anoadragon453
anoadragon453 previously approved these changes Nov 6, 2024
Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

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

This LGTM otherwise, thank you for your work!

Fixes the causes behind #1964, but the artifacts that were already generated for v1.11 and v1.12 still need to be fixed somehow.

Would manual find/replace surgery be tractable, or do we need to figure out how to regenerate? We can also discuss this further on a new issue to avoid bumping a merged PR.

@@ -2,4 +2,4 @@ module github.com/matrix-org/matrix-spec

go 1.12

require github.com/matrix-org/docsy v0.0.0-20231227121313-d55dbaf3aaaf // indirect
require github.com/matrix-org/docsy v0.0.0-20241030165433-a14705b7e3ca // indirect
Copy link
Member

Choose a reason for hiding this comment

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

I suppose this should be updated to matrix-org/docsy@ec7b98e now?

Copy link
Contributor Author

@zecakeh zecakeh Nov 6, 2024

Choose a reason for hiding this comment

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

I was planning to upgrade docsy in a separate PR because it brings visual changes that might need to be discussed.

config.toml Outdated Show resolved Hide resolved
config.toml Outdated Show resolved Hide resolved
.github/workflows/main.yml Show resolved Hide resolved
@anoadragon453 anoadragon453 dismissed their stale review November 6, 2024 13:40

meant to hit the "comment" button, but approval is close!

@zecakeh
Copy link
Contributor Author

zecakeh commented Nov 6, 2024

Would manual find/replace surgery be tractable, or do we need to figure out how to regenerate? We can also discuss this further on a new issue to avoid bumping a merged PR.

There must be something like 30 invalid links in those artifacts so it is doable manually. Running htmltest detects all the issues.

But it should also be simple to regenerate, we just need to use Hugo 0.117.0, like the CI that generates the "non-historical" spec-artifact. We can discuss this in the original issue, I already left a few comments there: #1964.

Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

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

Blocking on the threads above.

Allows to only serve the file that we actually use.

Signed-off-by: Kévin Commaille <[email protected]>
Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

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

This now LGTM. Thanks for your patience!

@anoadragon453 anoadragon453 merged commit bf8dee7 into matrix-org:main Nov 14, 2024
12 checks passed
@zecakeh zecakeh deleted the no-canonifyurls branch November 14, 2024 11:13
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.

Stop using canonifyURLs
2 participants