From cb5ce64b75198805abcb0380d71c036345917f62 Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Thu, 26 Oct 2023 21:25:55 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8C=90=20update=20internationalizatio?= =?UTF-8?q?n=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i18n/index.ts | 4 ++-- i18n/locales/{zh-TW => zh}/common.ts | 0 i18n/locales/{zh-TW => zh}/index.ts | 4 ++-- i18n/locales/{zh-TW => zh}/metadata.ts | 0 i18n/locales/{zh-TW => zh}/notFound.ts | 0 src/middleware.ts | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename i18n/locales/{zh-TW => zh}/common.ts (100%) rename i18n/locales/{zh-TW => zh}/index.ts (79%) rename i18n/locales/{zh-TW => zh}/metadata.ts (100%) rename i18n/locales/{zh-TW => zh}/notFound.ts (100%) diff --git a/i18n/index.ts b/i18n/index.ts index 97150331..cd40d1d5 100644 --- a/i18n/index.ts +++ b/i18n/index.ts @@ -1,9 +1,9 @@ -export const defaultLocale = 'zh-TW'; +export const defaultLocale = 'zh'; export const locales = [defaultLocale, 'en'] as const; export type Locale = (typeof locales)[number]; const dictionaries = { - 'zh-TW': () => import('./locales/zh-TW').then((module) => module.default), + zh: () => import('./locales/zh').then((module) => module.default), en: () => import('./locales/en').then((module) => module.default), }; diff --git a/i18n/locales/zh-TW/common.ts b/i18n/locales/zh/common.ts similarity index 100% rename from i18n/locales/zh-TW/common.ts rename to i18n/locales/zh/common.ts diff --git a/i18n/locales/zh-TW/index.ts b/i18n/locales/zh/index.ts similarity index 79% rename from i18n/locales/zh-TW/index.ts rename to i18n/locales/zh/index.ts index df66dd3e..d4f77504 100644 --- a/i18n/locales/zh-TW/index.ts +++ b/i18n/locales/zh/index.ts @@ -2,10 +2,10 @@ import common from './common'; import metadata from './metadata'; import notFound from './notFound'; -const zhTW = { +const zh = { common, metadata, notFound, }; -export default zhTW; +export default zh; diff --git a/i18n/locales/zh-TW/metadata.ts b/i18n/locales/zh/metadata.ts similarity index 100% rename from i18n/locales/zh-TW/metadata.ts rename to i18n/locales/zh/metadata.ts diff --git a/i18n/locales/zh-TW/notFound.ts b/i18n/locales/zh/notFound.ts similarity index 100% rename from i18n/locales/zh-TW/notFound.ts rename to i18n/locales/zh/notFound.ts diff --git a/src/middleware.ts b/src/middleware.ts index e231820f..81a8d644 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -15,7 +15,7 @@ export function middleware(request: NextRequest) { const locale = getLocale(acceptLanguage, defaultLocale); const redirectURL = new URL(`/${locale}${pathname}`, request.url); - if (locale !== 'zh-TW') { + if (locale !== defaultLocale) { return NextResponse.redirect(redirectURL); } From b674b1725852494788d3853af947e3d5502ceeb5 Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Thu, 26 Oct 2023 21:27:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=92=84=20update=20style=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{assets => app}/css/globals.css | 0 src/{assets => app}/css/prism-plus.css | 0 src/{assets => app}/css/prism-vsc-dark-plus.css | 0 src/app/layout.tsx | 2 +- tailwind.config.js | 9 +++++++-- 5 files changed, 8 insertions(+), 3 deletions(-) rename src/{assets => app}/css/globals.css (100%) rename src/{assets => app}/css/prism-plus.css (100%) rename src/{assets => app}/css/prism-vsc-dark-plus.css (100%) diff --git a/src/assets/css/globals.css b/src/app/css/globals.css similarity index 100% rename from src/assets/css/globals.css rename to src/app/css/globals.css diff --git a/src/assets/css/prism-plus.css b/src/app/css/prism-plus.css similarity index 100% rename from src/assets/css/prism-plus.css rename to src/app/css/prism-plus.css diff --git a/src/assets/css/prism-vsc-dark-plus.css b/src/app/css/prism-vsc-dark-plus.css similarity index 100% rename from src/assets/css/prism-vsc-dark-plus.css rename to src/app/css/prism-vsc-dark-plus.css diff --git a/src/app/layout.tsx b/src/app/layout.tsx index f4a7ad1a..e71e2da1 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -3,10 +3,10 @@ import type { Metadata } from 'next'; import { locales } from '~/i18n'; import { createMetadata, createFeedOptions } from '~/data/metadata'; import generateRSS from '@/utils/generateRSS'; -import '@/assets/css/globals.css'; import Html from './Html'; import Providers from './Providers'; +import './css/globals.css'; export const dynamic = 'force-static'; diff --git a/tailwind.config.js b/tailwind.config.js index 9d21d20e..4cd607a2 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -7,13 +7,13 @@ const tailwindcssConfig = { theme: { extend: { colors: { - primary: { ...colors.cyan, DEFAULT: colors.cyan[500] } + primary: { ...colors.lime, DEFAULT: colors.lime[500] }, }, typography: { DEFAULT: { css: { a: { - textDecoration: 'none' + textDecoration: 'none', }, code: { margin: '0 4px', @@ -22,6 +22,11 @@ const tailwindcssConfig = { background: '#1e1e1e', color: '#ff8888', }, + li: { + a: { + margin: 0, + }, + }, 'code::before': { content: '' }, 'code::after': { content: '' }, }, From 7dc494b4241912cbecaf0eb34525350a7defb791 Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Thu, 26 Oct 2023 21:27:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20components?= =?UTF-8?q?=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Card/Card.tsx | 5 ++--- src/components/Header/Menu.tsx | 4 ++-- src/components/Link/Link.tsx | 14 +++----------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/components/Card/Card.tsx b/src/components/Card/Card.tsx index a2962fcb..77a2e8db 100644 --- a/src/components/Card/Card.tsx +++ b/src/components/Card/Card.tsx @@ -1,11 +1,10 @@ -import Image from 'next/image'; - import { BsCalendar4Week } from 'react-icons/bs'; import { MdOutlineWidgets } from 'react-icons/md'; import { AiOutlineTags } from 'react-icons/ai'; import { formatDate } from '@/utils/date'; import Link from '../Link'; +import Image from '../Image'; type CardProps = DataFrontmatter; @@ -25,7 +24,7 @@ function Card({
{image && ( {`${title} { + const isActiveLink = (href: DynamicRoutesWithoutLocalePath) => { const locale = getLocale(pathname) || ''; const localePrefix = new RegExp(`^/${locale}/?`); const adjustedPathname = pathname.replace(localePrefix, '/'); diff --git a/src/components/Link/Link.tsx b/src/components/Link/Link.tsx index a43b6fda..3ceeca26 100644 --- a/src/components/Link/Link.tsx +++ b/src/components/Link/Link.tsx @@ -26,19 +26,11 @@ function Link({ }: LinkProps) { const pathname = usePathname(); - const isObjectHref = typeof href === 'object'; + const isObjectHref = typeof href === 'object' || href.startsWith('#'); const isAnchorLink = !isObjectHref && href.startsWith('#'); const isInternalLink = !isObjectHref && href.startsWith('/'); - if (isObjectHref) { - return ( - - {children} - - ); - } - - if (isAnchorLink) { + if (isObjectHref || isAnchorLink) { return ( {children} @@ -66,7 +58,7 @@ function Link({ href={href} target="_blank" rel="noopener noreferrer" - className={cn('inline-flex align-top', className)} + className={cn('inline-flex', className)} {...otherProps} > {children} From 33c531e60c2079c573038e9e153159ae28cdec73 Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Thu, 26 Oct 2023 21:40:37 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9C=85=20fix=20i18n=20test=20failures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Link/link.test.tsx | 4 ++-- src/hooks/__tests__/useI18n.test.ts | 6 +++--- src/utils/__tests__/getLocale.test.ts | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/Link/link.test.tsx b/src/components/Link/link.test.tsx index 9696d375..adbf1a48 100644 --- a/src/components/Link/link.test.tsx +++ b/src/components/Link/link.test.tsx @@ -33,8 +33,8 @@ describe('Link component', () => { it.each([ ['/internal', '/internal'], ['/en/internal', '/en/internal'], - ['/zh-TW/internal', '/zh-TW/internal'], - ['/fr-CH/internal', '/internal'], + ['/zh/internal', '/zh/internal'], + ['/fr/internal', '/internal'], ])( 'should render correct link element with pathname %s', (pathname, expected) => { diff --git a/src/hooks/__tests__/useI18n.test.ts b/src/hooks/__tests__/useI18n.test.ts index 6bb43170..c4da28a5 100644 --- a/src/hooks/__tests__/useI18n.test.ts +++ b/src/hooks/__tests__/useI18n.test.ts @@ -13,10 +13,10 @@ describe('useI18n hook', () => { }); it.each([ - ['/test/path', 'zh-TW'], + ['/test/path', 'zh'], ['/en/test/path', 'en'], - ['/zh-TW/test/path', 'zh-TW'], - ['/fr-CH/test/path', 'zh-TW'], + ['/zh/test/path', 'zh'], + ['/fr/test/path', 'zh'], ])( 'should return the correct language code and dictionary', (pathname, expected) => { diff --git a/src/utils/__tests__/getLocale.test.ts b/src/utils/__tests__/getLocale.test.ts index ddfcda35..5539d41c 100644 --- a/src/utils/__tests__/getLocale.test.ts +++ b/src/utils/__tests__/getLocale.test.ts @@ -8,9 +8,9 @@ describe('get locale function', () => { }); it.each([ - ['zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7', 'zh-TW'], + ['zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7', 'zh'], ['en-US,en;q=0.9,zh-TW;q=0.8,ja;q=0.7', 'en'], - ['fr-CH,fr;q=0.9,de-CH;q=0.8,de;q=0.7', 'zh-TW'], + ['fr-CH,fr;q=0.9,de-CH;q=0.8,de;q=0.7', 'zh'], ])( 'should extract the preferred language code from the Accept-Language header', (acceptLanguage, expected) => { @@ -19,10 +19,10 @@ describe('get locale function', () => { ); it.each([ - ['/test/path', 'zh-TW'], + ['/test/path', 'zh'], ['/en/test/path', 'en'], - ['/zh-TW/test/path', 'zh-TW'], - ['/fr-CH/test/path', 'zh-TW'], + ['/zh/test/path', 'zh'], + ['/fr/test/path', 'zh'], ])( 'should extract the language code from the path string', (pathname, expected) => {