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

[SEO 16.] Add nofollow to docusaurus external links #227

Merged
merged 11 commits into from
Jan 17, 2025
Merged

Conversation

ArturT
Copy link
Member

@ArturT ArturT commented Jan 16, 2025

  • Add nofollow to docusaurus external links but not to the main website knapsackpro.com

Use swizzling to replace original Docusaurus components:
https://docusaurus.io/docs/swizzling/

  • wrap MDXComponents/A component to add nofollow (it's safe)
  • eject EditThisPage component to override it (it's unsafe if there is a breaking change then we would have to update it). We added rel nofollow.

@ArturT ArturT requested a review from 3v0k4 January 16, 2025 22:11

export default function EditThisPage({editUrl}: Props): JSX.Element {
return (
<Link to={editUrl} className={ThemeClassNames.common.editThisPage} rel="nofollow noopener noreferrer">
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion

I see that the current link on our docs has also target=_blank. Will it stay the same? Does Link take care of that internally?

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 see that the current link on our docs has also target=_blank. Will it stay the same?

Yes.

Does Link take care of that internally?

Yes.

Comment on lines +15 to +21
<>
<A
{...props}
rel={isExternal ? 'nofollow noopener noreferrer' : undefined}
target={isExternal ? '_blank' : undefined}
/>
</>
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion

You don't need the wrapping element:

Suggested change
<>
<A
{...props}
rel={isExternal ? 'nofollow noopener noreferrer' : undefined}
target={isExternal ? '_blank' : undefined}
/>
</>
<A
{...props}
rel={isExternal ? 'nofollow noopener noreferrer' : undefined}
target={isExternal ? '_blank' : undefined}
/>

Copy link
Member Author

Choose a reason for hiding this comment

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

It was generated this way by:

➜  docusaurus git:(main) npm run swizzle

> [email protected] swizzle
> docusaurus swizzle


    ------------------------------------------------------------------------------------------------------------------------------------------------

                                                             Update available 3.6.3 → 3.7.0

                                   To upgrade Docusaurus packages with the latest version, run the following command:
        `npm i @docusaurus/core@latest @docusaurus/plugin-client-redirects@latest @docusaurus/preset-classic@latest @docusaurus/tsconfig@latest
                                                        @docusaurus/module-type-aliases@latest`

    ------------------------------------------------------------------------------------------------------------------------------------------------

✔ Select a theme to swizzle: › @docusaurus/theme-classic
✔ Which language do you want to use? › TypeScript
✔
Select or type the component to swizzle.
* = not safe for all swizzle actions
 › MDXComponents/A (Safe)

✔ Which swizzle action do you want to do? › Wrap (Safe)
[SUCCESS]

The original code generated:

import React from 'react';
import A from '@theme-original/MDXComponents/A';
import type AType from '@theme/MDXComponents/A';
import type {WrapperProps} from '@docusaurus/types';

type Props = WrapperProps<typeof AType>;

export default function AWrapper(props: Props): JSX.Element {
  return (
    <>
      <A {...props} />
    </>
  );
}

I'd keep it as is just to be on the safe side.

@ArturT ArturT merged commit 8214b84 into main Jan 17, 2025
1 check passed
@ArturT ArturT deleted the nofollow-docusaurus branch January 17, 2025 14:48
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.

2 participants