From bb3102b6e860ecf6ead6e69c9745327dbceec2fd Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sun, 17 Sep 2023 05:02:23 +0900 Subject: [PATCH 1/4] refactor: type utility for internal links --- apps/portfolio/src/components/InternalLink.astro | 3 ++- apps/portfolio/src/core/types.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 apps/portfolio/src/core/types.ts diff --git a/apps/portfolio/src/components/InternalLink.astro b/apps/portfolio/src/components/InternalLink.astro index 59b6778..0676a14 100644 --- a/apps/portfolio/src/components/InternalLink.astro +++ b/apps/portfolio/src/components/InternalLink.astro @@ -1,8 +1,9 @@ --- import type { HTMLAttributes } from 'astro/types'; +import type { WorkLink, WorksLink } from '../core/types.js'; interface Props extends HTMLAttributes<'a'> { - href: '/' | '/works' | `/works/${string}`; + href: '/' | WorksLink | `${WorkLink}`; } --- diff --git a/apps/portfolio/src/core/types.ts b/apps/portfolio/src/core/types.ts new file mode 100644 index 0000000..43d1e6f --- /dev/null +++ b/apps/portfolio/src/core/types.ts @@ -0,0 +1,2 @@ +export type WorksLink = '/works'; +export type WorkLink = `${WorksLink}/${Slug}`; From 87e202f559ff5bb5c61d6d9cbcee6a8ca95a29ce Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sun, 17 Sep 2023 05:20:58 +0900 Subject: [PATCH 2/4] refactor: `Links` utility object for links --- apps/portfolio/src/components/Header.astro | 3 ++- apps/portfolio/src/components/InternalLink.astro | 2 +- apps/portfolio/src/core/types.ts | 13 +++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/portfolio/src/components/Header.astro b/apps/portfolio/src/components/Header.astro index 2e2407f..22bfa97 100644 --- a/apps/portfolio/src/components/Header.astro +++ b/apps/portfolio/src/components/Header.astro @@ -1,4 +1,5 @@ --- +import Links from '../core/types.js'; import { listIconPath } from '../icon-path.js'; import Button from './Button.astro'; import InternalLink from './InternalLink.astro'; @@ -49,7 +50,7 @@ const NAV_ID = 'nav-menu';
  • 작업물 diff --git a/apps/portfolio/src/components/InternalLink.astro b/apps/portfolio/src/components/InternalLink.astro index 0676a14..23e9522 100644 --- a/apps/portfolio/src/components/InternalLink.astro +++ b/apps/portfolio/src/components/InternalLink.astro @@ -3,7 +3,7 @@ import type { HTMLAttributes } from 'astro/types'; import type { WorkLink, WorksLink } from '../core/types.js'; interface Props extends HTMLAttributes<'a'> { - href: '/' | WorksLink | `${WorkLink}`; + href: '/' | WorksLink | WorkLink; } --- diff --git a/apps/portfolio/src/core/types.ts b/apps/portfolio/src/core/types.ts index 43d1e6f..8501cda 100644 --- a/apps/portfolio/src/core/types.ts +++ b/apps/portfolio/src/core/types.ts @@ -1,2 +1,11 @@ -export type WorksLink = '/works'; -export type WorkLink = `${WorksLink}/${Slug}`; +const Links = { + works: '/works', + work(slug: string) { + return `${this.works}/${slug}` as const; + }, +} as const; + +export default Links; + +export type WorksLink = (typeof Links)['works']; +export type WorkLink = ReturnType<(typeof Links)['work']>; From 269a04c605c97f8594a9ffcf6ed3c5c469dfcd2c Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sun, 17 Sep 2023 05:23:28 +0900 Subject: [PATCH 3/4] refactor: change file name --- apps/portfolio/src/components/Header.astro | 2 +- apps/portfolio/src/components/InternalLink.astro | 2 +- apps/portfolio/src/core/{types.ts => links.ts} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename apps/portfolio/src/core/{types.ts => links.ts} (100%) diff --git a/apps/portfolio/src/components/Header.astro b/apps/portfolio/src/components/Header.astro index 22bfa97..2f23425 100644 --- a/apps/portfolio/src/components/Header.astro +++ b/apps/portfolio/src/components/Header.astro @@ -1,5 +1,5 @@ --- -import Links from '../core/types.js'; +import Links from '../core/links.js'; import { listIconPath } from '../icon-path.js'; import Button from './Button.astro'; import InternalLink from './InternalLink.astro'; diff --git a/apps/portfolio/src/components/InternalLink.astro b/apps/portfolio/src/components/InternalLink.astro index 23e9522..51f90b7 100644 --- a/apps/portfolio/src/components/InternalLink.astro +++ b/apps/portfolio/src/components/InternalLink.astro @@ -1,6 +1,6 @@ --- import type { HTMLAttributes } from 'astro/types'; -import type { WorkLink, WorksLink } from '../core/types.js'; +import type { WorkLink, WorksLink } from '../core/links.js'; interface Props extends HTMLAttributes<'a'> { href: '/' | WorksLink | WorkLink; diff --git a/apps/portfolio/src/core/types.ts b/apps/portfolio/src/core/links.ts similarity index 100% rename from apps/portfolio/src/core/types.ts rename to apps/portfolio/src/core/links.ts From 7a3fd87938296e5d5d81df8ba76ec1a87e6cb9c1 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Sun, 17 Sep 2023 05:27:13 +0900 Subject: [PATCH 4/4] refactor: add root for Links object --- apps/portfolio/src/components/Header.astro | 2 +- apps/portfolio/src/components/InternalLink.astro | 4 ++-- apps/portfolio/src/core/links.ts | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/portfolio/src/components/Header.astro b/apps/portfolio/src/components/Header.astro index 2f23425..9a0a499 100644 --- a/apps/portfolio/src/components/Header.astro +++ b/apps/portfolio/src/components/Header.astro @@ -42,7 +42,7 @@ const NAV_ID = 'nav-menu';
    • 홈 diff --git a/apps/portfolio/src/components/InternalLink.astro b/apps/portfolio/src/components/InternalLink.astro index 51f90b7..a30f7ba 100644 --- a/apps/portfolio/src/components/InternalLink.astro +++ b/apps/portfolio/src/components/InternalLink.astro @@ -1,9 +1,9 @@ --- import type { HTMLAttributes } from 'astro/types'; -import type { WorkLink, WorksLink } from '../core/links.js'; +import type { RootLink, WorkLink, WorksLink } from '../core/links.js'; interface Props extends HTMLAttributes<'a'> { - href: '/' | WorksLink | WorkLink; + href: RootLink | WorksLink | WorkLink; } --- diff --git a/apps/portfolio/src/core/links.ts b/apps/portfolio/src/core/links.ts index 8501cda..06fc5a6 100644 --- a/apps/portfolio/src/core/links.ts +++ b/apps/portfolio/src/core/links.ts @@ -1,4 +1,6 @@ const Links = { + root: '/', + works: '/works', work(slug: string) { return `${this.works}/${slug}` as const; @@ -7,5 +9,7 @@ const Links = { export default Links; +export type RootLink = (typeof Links)['root']; + export type WorksLink = (typeof Links)['works']; export type WorkLink = ReturnType<(typeof Links)['work']>;