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

[docs-infra] Fix GitHub source link redirection #43534

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ export function ComponentLinkHeader(props: ComponentLinkHeaderProps) {
size="small"
variant="outlined"
rel="nofollow"
href={`${process.env.SOURCE_CODE_REPO}/blob/v${process.env.LIB_VERSION}/${headers.githubSource}`}
href={`${process.env.SOURCE_CODE_REPO}/tree/v${process.env.LIB_VERSION}/${headers.githubSource}`}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
href={`${process.env.SOURCE_CODE_REPO}/tree/v${process.env.LIB_VERSION}/${headers.githubSource}`}
href={`${process.env.SOURCE_CODE_REPO}/${/\.[a-z]{2,3}$/.test(headers.githubSource) ? 'blob' : 'tree'}/v${process.env.LIB_VERSION}/${headers.githubSource}`}

Maybe I'm overengineering But with a regexp that check if the file ends with a dot plus 2 or 3 characters, you get a fix that work for all cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would imagine that on the API page we always link files and on the demo page folders, so it might be fine?
If we start to see regressions, yeah, I would add an exception here, it must be a folder.

Copy link
Member

Choose a reason for hiding this comment

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

This component is not on the API page. It's the header of the demo. Technically, we could put files or folders in the markdown header

icon={<GitHubIcon />}
data-ga-event-category="ComponentLinkHeader"
data-ga-event-action="click"
data-ga-event-label="Source"
data-ga-event-split="0.1"
label="Source"
target="_blank"
/>
</li>
) : null}
Expand Down
Loading