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

Automatically slugify site_name #58

Merged
merged 9 commits into from
Oct 27, 2021
Merged

Automatically slugify site_name #58

merged 9 commits into from
Oct 27, 2021

Conversation

diegomarangoni
Copy link
Contributor

Currently, this plugin fails if an embedded mkdocs site_name field does not match the regex ^[a-zA-Z0-9_\-/]+$.

This PR change this behavior to automatically generate a slug based on site_name, this will allow to maintain user-friendly names and still be able to embed.

@diegomarangoni diegomarangoni requested a review from a team as a code owner October 12, 2021 08:50
@diegomarangoni
Copy link
Contributor Author

can I have a review here? maybe @bih?

@camilaibs
Copy link
Contributor

Starting to review

@@ -121,7 +121,7 @@ teardown() {
@test "builds a mkdocs site with site_name containing slash" {
cd ${fixturesDir}/ok-nested-site-name-contains-slash
assertSuccessMkdocs build
assertFileExists site/plugins/example-Folder/index.html
assertFileExists site/plugins-example-folder/index.html
Copy link
Contributor

@camilaibs camilaibs Oct 19, 2021

Choose a reason for hiding this comment

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

Looks like a "/" should not be replaced by "-" in the path because apparently, it causes a not found error that has been solved in the past here:

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 will change a bit, I will slugify only if doesn't match the regex

Copy link
Contributor

@camilaibs camilaibs Oct 19, 2021

Choose a reason for hiding this comment

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

if I use disallowed characters (like "@"), it compiles, but some pages are not found:

sample-docs/v3/mkdocs.yml
image

image

error

Copy link
Contributor Author

@diegomarangoni diegomarangoni Oct 19, 2021

Choose a reason for hiding this comment

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

slugified site_name will naturally have different paths than the ones matching the regex
in this specific case, it will require to change the link reference to ./versions-v3/reference.md

Copy link
Contributor

Choose a reason for hiding this comment

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

So this will introduce significant changes, if we continue, it would be good to have instructions for this new path pattern. I'd like to hear from other reviewers just to make sure it's okay to proceed with this new standard.
What do you think @emmaindal, @iamEAP, @ottosichert and @OrkoHunter?

Copy link

@garyniemen garyniemen Oct 20, 2021

Choose a reason for hiding this comment

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

Can somebody map out from a product perspective what the implications of this suggested change are?

Copy link
Contributor

@camilaibs camilaibs Oct 20, 2021

Choose a reason for hiding this comment

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

Correct me @diegomarangoni, if am I wrong, please 🙏🏻

What will change is that we will replace all invalid characters with "-" in the site_name when generating documentation without throwing an error with instructions to not use those characters there.

The consequences are:

  1. Users will lose favorite links that point to the current path style
  2. And should also update links in their markdown files to use the new path pattern instead (the breaking change)

Example:

This is a new link path using "versions-v3" instead of "versions/v3:
slugify

If you try to access the page using the previous URL will see a not found page:

page not found

And if you don't update the link in your markdown, they will be broken links pointing to the old URL (not found pages):

wrong link

To fix this, users will need to update the paths in their doc files:

index

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, that's correct, but there is one important difference:

if you don't change your site_name and continue to use the pattern matching regex (^[a-zA-Z0-9_\-/]+$), nothing changes

these consequences you mentioned only apply to cases where you decided to change your site_name to something that does not match the regex

@camilaibs
Copy link
Contributor

Hello, @diegomarangoni thanks for contributing 🎉
Added only one comment to the test file!
Can you take a look at the failed checks, please?

@diegomarangoni
Copy link
Contributor Author

hey @camilaibs, thanks for the review

I did some changes, it should works now

@garyniemen
Copy link

@diegomarangoni - I have been thinking about this a bit. We are a bit reluctant to introduce an automatic change to a user's site_name (assuming they have used a character that doesn't pass the regex). I think the favoured solution would be to inform the user that their site_name includes an invalid character - and then give a good error message that guides them in the right direction. And I think we have that in place, right @camilaibs ?
Please let me know though @diegomarangoni if I have misunderstood the problem that you are trying to solve and your attempt to solve it.

@camilaibs
Copy link
Contributor

@diegomarangoni - I have been thinking about this a bit. We are a bit reluctant to introduce an automatic change to a user's site_name (assuming they have used a character that doesn't pass the regex). I think the favoured solution would be to inform the user that their site_name includes an invalid character - and then give a good error message that guides them in the right direction. And I think we have that in place, right @camilaibs ? Please let me know though @diegomarangoni if I have misunderstood the problem that you are trying to solve and your attempt to solve it.

Hey @garyniemen, the message we have today is:

"Site name can only contain letters, numbers, underscores, hyphens and forward-slashes. The regular expression we test against is ^[a-zA-Z0-9_\-/]+$."

@diegomarangoni
Copy link
Contributor Author

hey @garyniemen, let me better explain the use case this PR is intended to solve.

Currently, this plugin requires that every included documentation must be designed to be embedded, meaning the site_name instead of being used as page title, will be used as the navigation path.

Considering a scenario where the documentation is designed to have its own dedicated page, with site_name being a human-friendly title, embedding this doc would not be possible.

So this will require changing the documentation title to something less user-friendly and also assumes that the user has control over this project, which might not be the case.

Let me know if you have any question

@@ -139,6 +139,11 @@ teardown() {
[[ "$output" == *"This contains a sentence which only exists in the ok-mkdocs-git-revision-date-localized-plugin/project-a fixture."* ]]
}

@test "builds a mkdocs even if !include path has site_name containing spaces" {
cd ${fixturesDir}/error-include-path-site-name-contains-space
Copy link
Member

Choose a reason for hiding this comment

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

Just one last update and I think this is good to merge. Could you update the name of this fixture to indicate that no error is expected? Maybe even just no-error-include-path-site-name-contains-space

@garyniemen
Copy link

garyniemen commented Oct 26, 2021

Hi again @diegomarangoni - sorry for the delay in replying. I am still a bit confused. Is this use case specifically for a Monorepo? Assuming so, and within that context, can you describe what the 2 use cases are that you are trying to simultaneously address. Will the change that you are making fix one of these use cases - but still keep the other working fine? And - what is the relation between these 2 use cases and the previous discussion around Regex?

@diegomarangoni
Copy link
Contributor Author

hey @garyniemen, the use case I describe is for multiple repositories, let me bring an example that might help:

I have 3 repositories:

  • myapp-backend: it has his own mkdocs file, his own mkdocs serve page, and the site_name being MyApp Backend service
  • myapp-frontend: like the previous one, but I don't have control over this repository and site_name being MyApp Frontend application
  • myapp-docs: new repository created in order to centralize backend and frontend docs in a single place

So the problem here is that I can't easily use this plugin without having to change both frontend and backend site_name first and at the cost of having less friendly titles on their mkdocs serve page

Here is how the page looks like:
Screenshot 2021-10-27 at 09 45 51
.

iamEAP and others added 3 commits October 27, 2021 14:57
Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
@iamEAP
Copy link
Member

iamEAP commented Oct 27, 2021

Thanks for the contribution @diegomarangoni! Shipping this now as a patch release. Will look toward the .yaml support PR as a minor version update after this.

@iamEAP iamEAP merged commit c06c481 into backstage:master Oct 27, 2021
@camilaibs camilaibs linked an issue Dec 15, 2021 that may be closed by this pull request
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.

Allow for spaces in site_name of sub-docs
4 participants