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: fixed localized links and next links redirection #5474

Merged
merged 6 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 0 additions & 19 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@
"plugin:storybook/recommended"
],
"overrides": [
{
"files": ["**/*.{mjs,js,ts,tsx}"],
"rules": {
"import/order": [
"warn",
{
"groups": [
"builtin",
"external",
"internal",
"sibling",
"parent",
"index",
"type"
]
}
]
}
},
{
"files": ["**/*.ts?(x)"],
"plugins": ["@typescript-eslint"],
Expand Down
3 changes: 1 addition & 2 deletions components/Downloads/DownloadReleasesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FormattedMessage } from 'react-intl';
import Link from 'next/link';
import { getNodejsChangelog } from '../../util/getNodeJsChangelog';
import { getNodeApiLink } from '../../util/getNodeApiLink';
import { useNodeReleases } from '../../hooks/useNodeReleases';
Expand All @@ -18,7 +17,7 @@ const DownloadReleasesTable: FC = () => {
<td>V8</td>
<td>npm</td>
<td>
NODE_MODULE_VERSION<Link href="#ref-1">[1]</Link>
NODE_MODULE_VERSION<a href="#ref-1">[1]</a>
<span id="backref-1"></span>
</td>
<td></td>
Expand Down
6 changes: 4 additions & 2 deletions components/Downloads/DownloadToggle/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
background: var(--black0);
border: none;
border-radius: 32px;
box-shadow: inset 1px -1px 1px rgba(0, 0, 0, 0.08),
box-shadow:
inset 1px -1px 1px rgba(0, 0, 0, 0.08),
inset 0px 1px 2px rgba(0, 0, 0, 0.08);
box-sizing: border-box;
color: var(--black7);
Expand All @@ -44,7 +45,8 @@
width: 133px;

&.current {
box-shadow: inset 1px -1px 1px rgba(0, 0, 0, 0.08),
box-shadow:
inset 1px -1px 1px rgba(0, 0, 0, 0.08),
inset 0px 1px 2px rgba(0, 0, 0, 0.08);
margin-left: -30px;
}
Expand Down
5 changes: 2 additions & 3 deletions components/Home/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Link from 'next/link';
import { useSiteConfig } from '../../hooks/useSiteConfig';
import { dateIsBetween } from '../../util/dateIsBetween';

Expand All @@ -17,14 +16,14 @@ const Banner = () => {
if (showBanner && indexBanner.text) {
return (
<p className="home-version home-version-banner">
<Link href={indexBanner.link}>{indexBanner.text}</Link>
<a href={indexBanner.link}>{indexBanner.text}</a>
</p>
);
}

if (showBanner && indexBanner.html) {
return (
<Link
<a
href={indexBanner.link}
dangerouslySetInnerHTML={{ __html: indexBanner.html }}
/>
Expand Down
13 changes: 7 additions & 6 deletions components/Home/HomeDownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const HomeDownloadButton: FC<NodeRelease> = ({
const nodeDownloadLink = downloadUrlByOS(versionWithPrefix, os, bitness);
const nodeApiLink = `https://nodejs.org/dist/latest-v${major}.x/docs/api/`;
const nodeAllDownloadsLink = `/download${isLts ? '/' : '/current'}`;
const nodeDownloadTitle =
`${labels?.download} ${version}` +
` ${labels?.[isLts ? 'lts' : 'current']}`;

const nodeDownloadTitle = `${labels?.download} ${version} ${labels?.[
isLts ? 'lts' : 'current'
]}`;

return (
<div className="home-downloadblock">
Expand All @@ -44,12 +45,12 @@ const HomeDownloadButton: FC<NodeRelease> = ({
</LocalizedLink>
</li>
<li>
<LocalizedLink href={getNodejsChangelog(versionWithPrefix)}>
<a href={getNodejsChangelog(versionWithPrefix)}>
{labels?.changelog}
</LocalizedLink>
</a>
</li>
<li>
<LocalizedLink href={nodeApiLink}>{labels?.api}</LocalizedLink>
<a href={nodeApiLink}>{labels?.api}</a>
</li>
</ul>
</div>
Expand Down
19 changes: 8 additions & 11 deletions components/LocalizedLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useMemo } from 'react';
import Link from 'next/link';
import { useLocale } from '../hooks/useLocale';
import { linkWithLocale } from '../util/linkWithLocale';
Expand All @@ -11,18 +10,16 @@ const LocalizedLink: FC<ComponentProps<typeof Link>> = ({
}) => {
const { currentLocale } = useLocale();

const localizedUrl = linkWithLocale(currentLocale.code);

const finalHref = useMemo(
() =>
/^https?:\/\//.test(href.toString())
? href.toString()
: localizedUrl(href),
[href, localizedUrl]
);
if (/^https?:\/\//.test(href.toString())) {
return (
<a {...extra} href={href.toString()}>
{children}
</a>
);
}

return (
<Link {...extra} href={finalHref}>
<Link {...extra} href={linkWithLocale(currentLocale.code)(href)}>
{children}
</Link>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`Sections/NewHeader Default smoke-test 1`] = `
<div class="NewHeader_container__tyM2Y">
<div class="NewHeader_startWrapper__teZG4">
<a aria-label="Homepage"
href="/"
href="/en"
>
<div class="NewHeader_logo__mB_8v">
<div>
Expand Down
9 changes: 5 additions & 4 deletions components/Sections/NewHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { FormattedMessage } from 'react-intl';
import Image from 'next/image';
import Link from 'next/link';
import { FaGithub } from 'react-icons/fa';
import styles from './index.module.scss';
import LocalizedLink from '../../LocalizedLink';
import ActiveLocalizedLink from '../../Common/ActiveLocalizedLink';
import DarkModeToggle from '../../Common/DarkModeToggle';
import LanguageSelector from '../../Common/LanguageSelector';
import type { FC } from 'react';

import styles from './index.module.scss';

const Header: FC = () => (
<nav aria-label="Primary" className={styles.header}>
<div className={styles.container}>
<div className={styles.startWrapper}>
<Link href="/" aria-label="Homepage">
<LocalizedLink href="/" aria-label="Homepage">
<div className={styles.logo}>
<div>
<Image
Expand All @@ -33,7 +34,7 @@ const Header: FC = () => (
/>
</div>
</div>
</Link>
</LocalizedLink>
</div>

<ul className={styles.tabs}>
Expand Down
3 changes: 2 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LocaleProvider } from '../providers/localeProvider';
import { BlogDataProvider } from '../providers/blogDataProvider';
import { NodeReleasesProvider } from '../providers/nodeReleasesProvider';
import { sourceSans } from '../util/nextFonts';
import * as nextConstants from '../next.constants.mjs';
import type { AppProps } from 'next/app';

import '../styles/old/index.scss';
Expand All @@ -20,7 +21,7 @@ const App = ({ Component, pageProps }: AppProps) => (
</SiteProvider>
</LocaleProvider>

<Analytics />
{nextConstants.ENABLE_STATIC_EXPORT || <Analytics />}
ovflowd marked this conversation as resolved.
Show resolved Hide resolved

<style jsx global>
{`
Expand Down