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(v2): classify link hrefs with protocol identifier as internal #3063

Merged
merged 1 commit into from
Jul 15, 2020

Conversation

ghost
Copy link

@ghost ghost commented Jul 15, 2020

Motivation

Currently, only specific protocol links (http://, https://, tel: and mailto:) in the navbar and footer are treated as external - other protocols such as ssh://, sftp:// etc are treated as internal and get prepended with baseUrl which breaks the links.

It would be nice to be able to have other protocols in links as well. My suggested solution is to let the isInternalUrl test check for any protocol identifier rather than specific ones.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Using the following navbar configuration in docusaurus.config.js

    navbar: {
      hideOnScroll: true,
      title: 'Docusaurus',
      logo: {
        alt: 'Docusaurus Logo',
        src: 'img/docusaurus.svg',
        srcDark: 'img/docusaurus_keytar.svg',
      },
      links: [
        {
          href: 'https://example.com',
          label: 'https://example.com',
          position: 'left',
        },
        {
          href: 'tel:18005551042',
          label: 'tel:18005551042',
          position: 'left',
        },
        {
          href: 'mailto:user@example.com',
          label: 'mailto:user@example.com',
          position: 'left',
        },
        {
          href: 'ssh://host.example.com',
          label: 'ssh://host.example.com',
          position: 'left',
        },
        {
          to: 'versions',
          label: `v${versions[0]}`,
          position: 'right',
        },
        {
          href: 'https://github.com/facebook/docusaurus',
          position: 'right',
          className: 'header-github-link',
          'aria-label': 'GitHub repository',
        },
      ],
    }

Current behavior

The concerned navbar items are output as:

<li class="menu__list-item"><a href="https://example.com/" target="_blank" rel="noopener noreferrer" class="menu__link">https://example.com</a></li>
<li class="menu__list-item"><a href="tel:18005551042" target="_blank" rel="noopener noreferrer" class="menu__link">tel:18005551042</a></li>
<li class="menu__list-item"><a href="mailto:user@example.com" target="_blank" rel="noopener noreferrer" class="menu__link">mailto:user@example.com</a></li>
<li class="menu__list-item"><a target="_blank" rel="noopener noreferrer" href="http://localhost:3000/ssh://host.example.com" class="menu__link">ssh://host.example.com</a></li>

with http://localhost:3000/ prepended to the href property on the last link.

before

Behavior after the change

Navbar items are output as:

<li class="menu__list-item"><a href="https://example.com/" target="_blank" rel="noopener noreferrer" class="menu__link">https://example.com</a></li>
<li class="menu__list-item"><a href="tel:18005551042" target="_blank" rel="noopener noreferrer" class="menu__link">tel:18005551042</a></li>
<li class="menu__list-item"><a href="mailto:user@example.com" target="_blank" rel="noopener noreferrer" class="menu__link">mailto:user@example.com</a></li>
<li class="menu__list-item"><a href="ssh://host.example.com/" target="_blank" rel="noopener noreferrer" class="menu__link">ssh://host.example.com</a></li>

and all links are working as expected.

after

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@ghost ghost requested a review from yangshun as a code owner July 15, 2020 13:12
@facebook-github-bot
Copy link
Contributor

Hi @svtfrida!

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.

In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit 0934ca5

https://deploy-preview-3063--docusaurus-2.netlify.app

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jul 15, 2020
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@slorber
Copy link
Collaborator

slorber commented Jul 15, 2020

agree, + it does not break existing tests so it looks like a safe change to me, thanks!

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Jul 15, 2020
@slorber slorber merged commit 5d08ef8 into facebook:master Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants