diff --git a/apps/astro/src/components/lib/Markdown.tsx b/apps/astro/src/components/lib/Markdown.tsx index 25e420b..80e8ee0 100644 --- a/apps/astro/src/components/lib/Markdown.tsx +++ b/apps/astro/src/components/lib/Markdown.tsx @@ -28,16 +28,18 @@ export const Markdown = ({ ( + h1: ({ ref: __, node: _, ...props }) => ( ), - h2: ({ node: _, ...props }) => , - h3: ({ node: _, ...props }) => ( + h2: ({ ref: __, node: _, ...props }) => , + h3: ({ ref: __, node: _, ...props }) => ( ), - h4: ({ node: _, ...props }) => , - h5: ({ node: _, ...props }) => , - h6: ({ node: _, ...props }) => , + h4: ({ ref: __, node: _, ...props }) => , + h5: ({ ref: __, node: _, ...props }) => ( + + ), + h6: ({ ref: __, node: _, ...props }) => , p: ({ ref: _ref, node: _, ...props }) => , strong: ({ ref: _, node: __, ...props }) => ( diff --git a/apps/astro/src/i18n/utils.ts b/apps/astro/src/i18n/utils.ts index 1379289..f4a4418 100644 --- a/apps/astro/src/i18n/utils.ts +++ b/apps/astro/src/i18n/utils.ts @@ -14,10 +14,12 @@ export function useTranslations(key: `${string & Collection}.${string & Key}`): (typeof ui)[Lang][Collection][Key] { + >(key: `${string & Collection}.${string & Key}`): (typeof ui)[Lang][Collection][Key] | Key { const [collection, translationKey] = key.split('.') as [Collection, Key]; - return ( - ui[lang][collection][translationKey] || ui[defaultLang as Lang][collection][translationKey] - ); + const res = + ui[lang][collection]?.[translationKey] ?? + ui[defaultLang as Lang][collection]?.[translationKey] ?? + translationKey; + return res; }; } diff --git a/apps/astro/src/pages/[locale]/about/index.astro b/apps/astro/src/pages/[locale]/about/index.astro index eedb326..ca60ae0 100644 --- a/apps/astro/src/pages/[locale]/about/index.astro +++ b/apps/astro/src/pages/[locale]/about/index.astro @@ -9,6 +9,7 @@ import { toKebabCase } from 'utils/kebab-case'; import { Markdown } from '~/components/lib/Markdown'; import { TagBadge } from '~/components/tags/TagBadge'; import { Heading } from '~/components/ui/heading'; +import { Link } from '~/components/ui/link'; import { Text } from '~/components/ui/text'; import { graphQLSdk } from '~/graphql'; import { useTranslations, validateLocale } from '~/i18n/utils'; @@ -66,9 +67,9 @@ Astro.response.headers.set('CDN-Cache-Control', 'public, max-age=3600, must-reva .map( (s) => s.attributes && ( - + - + ) )} @@ -111,9 +112,9 @@ Astro.response.headers.set('CDN-Cache-Control', 'public, max-age=3600, must-reva {sortTags(tags?.data).map( (s) => s.attributes && ( - + - + ) )} diff --git a/apps/astro/src/pages/[locale]/hobbies/[id]/index.astro b/apps/astro/src/pages/[locale]/hobbies/[id]/index.astro new file mode 100644 index 0000000..09b5f70 --- /dev/null +++ b/apps/astro/src/pages/[locale]/hobbies/[id]/index.astro @@ -0,0 +1,66 @@ +--- +//TODO: +import { FaArrowLeft } from 'react-icons/fa'; +import { Container, Divider, Stack, Wrap } from 'styled-system/jsx'; +import { Markdown } from '~/components/lib/Markdown'; +import { Heading } from '~/components/ui/heading'; +import { Link } from '~/components/ui/link'; +import { Text } from '~/components/ui/text'; +import { useTranslations } from '~/i18n/utils'; +import MainLayout from '~/layouts/MainLayout.astro'; +import { outlineClient } from '~/utils/outline-api'; +import { getOutlineSettings } from '~/utils/outline-settings'; + +export const prerender = false; + +const { locale, id } = Astro.params; + +const t = useTranslations(locale as 'en'); + +const settings = await getOutlineSettings(); + +if (!settings?.['hobbies-collection']) { + return Astro.redirect('/404'); +} + +const data = ( + await outlineClient.POST('/documents.info', { + body: { collectionId: settings['hobbies-collection'], id: id } + }) +).data?.data; + +if (!data) { + return Astro.redirect('/404'); +} + +const { title, text } = data; +Astro.response.headers.set('CDN-Cache-Control', 'public, max-age=86400, must-revalidate'); +--- + + + + + + + + {t('hobbies.back-to-hobbies')} + + + + + {title} + + + + + {text && } + + + diff --git a/apps/astro/src/pages/[locale]/hobbies/index.astro b/apps/astro/src/pages/[locale]/hobbies/index.astro index b021dce..87c58e8 100644 --- a/apps/astro/src/pages/[locale]/hobbies/index.astro +++ b/apps/astro/src/pages/[locale]/hobbies/index.astro @@ -5,6 +5,7 @@ import MainLayout from '~/layouts/MainLayout.astro'; import { Center, Container, Grid, GridItem, Stack } from 'styled-system/jsx'; import { Heading } from '~/components/ui/heading'; +import { Link } from '~/components/ui/link'; import { Text } from '~/components/ui/text'; import { useTranslations } from '~/i18n/utils'; import { outlineClient } from '~/utils/outline-api'; @@ -27,7 +28,7 @@ const hobbiesList = ( await outlineClient.POST('/documents.list', { body: { collectionId: settings['hobbies-collection'] } }) -).data; +).data?.data?.filter((d) => !d.parentDocumentId); if (!hobbiesList) { return Astro.redirect(404); @@ -40,17 +41,20 @@ if (!hobbiesList) { {t('common.hobbies')} { - hobbiesList.data?.map((hobby) => { - const { title } = hobby; + hobbiesList.map((hobby) => { + console.log(hobby); + const { title, id } = hobby; return ( -
- - - {title} - - -
+ +
+ + + {title} + + +
+
); }) diff --git a/apps/astro/src/pages/[locale]/projects/[slug]/index.astro b/apps/astro/src/pages/[locale]/projects/[slug]/index.astro index a601423..23fb7b2 100644 --- a/apps/astro/src/pages/[locale]/projects/[slug]/index.astro +++ b/apps/astro/src/pages/[locale]/projects/[slug]/index.astro @@ -99,7 +99,9 @@ Astro.response.headers.set('CDN-Cache-Control', 'public, max-age=86400, must-rev {tags.data .filter((t) => !!t) .map((t) => ( - + + + ))} diff --git a/apps/astro/src/pages/[locale]/tags/[id]/index.astro b/apps/astro/src/pages/[locale]/tags/[id]/index.astro deleted file mode 100644 index d6615ae..0000000 --- a/apps/astro/src/pages/[locale]/tags/[id]/index.astro +++ /dev/null @@ -1,5 +0,0 @@ ---- -export const prerender = false; - -//TODO: ---- diff --git a/apps/astro/src/pages/[locale]/tags/[slug]/index.astro b/apps/astro/src/pages/[locale]/tags/[slug]/index.astro new file mode 100644 index 0000000..ad8adf1 --- /dev/null +++ b/apps/astro/src/pages/[locale]/tags/[slug]/index.astro @@ -0,0 +1,176 @@ +--- +import { formatDistance } from 'date-fns'; +import { enUS, ja } from 'date-fns/locale'; +import { FaArrowLeft, FaGithub, FaGlobe } from 'react-icons/fa'; +import { Box, Container, Divider, Grid, GridItem, Stack, styled, Wrap } from 'styled-system/jsx'; +import { formatMonthYear, parseDate } from 'utils/date'; +import { getMediaUrl } from 'utils/media'; +import { Markdown } from '~/components/lib/Markdown'; +import { TagBadge } from '~/components/tags/TagBadge'; +import { Heading } from '~/components/ui/heading'; +import { IconButton } from '~/components/ui/icon-button'; +import { Link } from '~/components/ui/link'; +import { Text } from '~/components/ui/text'; +import { graphQLSdk } from '~/graphql'; +import { Enum_Componentutilslink_Type } from '~/graphql/generated/client'; +import { useTranslations, validateLocale } from '~/i18n/utils'; +import MainLayout from '~/layouts/MainLayout.astro'; +import { sortTags } from '~/utils/tags'; + +export const prerender = false; + +const { locale, slug } = Astro.params; + +const data = await graphQLSdk.getTagBySlug({ + slug +}); + +if (!validateLocale(locale)) { + return Astro.redirect(404); +} + +const { projects, experiences, title, type } = data?.tags?.data[0].attributes ?? {}; +const t = useTranslations(locale); + +Astro.response.headers.set('CDN-Cache-Control', 'public, max-age=86400, must-revalidate'); +--- + + + + + + + + {t('project.back-to-projects')} + + + + + {title} + + {type} + | + {type} + + + + + { + experiences && + experiences.data?.map((d) => { + if (!d.attributes) return null; + const { title, content, position, tags } = d.attributes; + const start = d.attributes.start as string; + const end = d.attributes.end as string; + return ( + + + {title} + + + {position} | + + {formatMonthYear(parseDate(start), locale)} -{' '} + {end ? formatMonthYear(parseDate(end), locale) : t('common.present')} ( + {formatDistance(parseDate(start), end ? parseDate(end) : new Date(), { + locale: locale === 'ja' ? ja : enUS + })} + ) + + + {tags && ( + + {t('common.tags')} + {sortTags(tags?.data).map( + (s) => + s.attributes && ( + + + + ) + )} + + )} + {content && } + + ); + }) + } + + + { + projects?.data?.map((p) => { + const { title, description, slug, banner, media, date, category, links } = + p.attributes ?? {}; + const image = banner?.data?.attributes ?? media?.data?.[0]?.attributes; + const link = links?.find((l) => l?.type === Enum_Componentutilslink_Type.Web); + const ghLink = links?.find((l) => l?.type === Enum_Componentutilslink_Type.Github); + + return ( + + + + + {image && ( + + + + )} + + {title} + + + {category?.data?.attributes?.name} | + {formatMonthYear(parseDate(date), locale)} + + {description} + + + + {link?.url && ( + + + + + + )} + {ghLink?.url && ( + + + + + + )} + + + + ); + }) + } + + + + diff --git a/libs/i18n/en/hobbies.json b/libs/i18n/en/hobbies.json new file mode 100644 index 0000000..4906215 --- /dev/null +++ b/libs/i18n/en/hobbies.json @@ -0,0 +1,3 @@ +{ + "back-to-hobbies": "Back to hobbies" +} diff --git a/libs/i18n/en/index.ts b/libs/i18n/en/index.ts index a87ad0a..d8d891d 100644 --- a/libs/i18n/en/index.ts +++ b/libs/i18n/en/index.ts @@ -2,6 +2,7 @@ import aboutMe from './about-me.json'; import blog from './blog.json'; import common from './common.json'; import contact from './contact.json'; +import hobbies from './hobbies.json'; import home from './home.json'; import nameCard from './name-card.json'; import note from './note.json'; @@ -9,11 +10,12 @@ import project from './project.json'; export default { 'about-me': aboutMe, - blog: blog, - common: common, - contact: contact, - home: home, + blog, + common, + contact, + home, 'name-card': nameCard, - note: note, - project: project -} as const; + note, + project, + hobbies +}; diff --git a/libs/i18n/ja/hobbies.json b/libs/i18n/ja/hobbies.json new file mode 100644 index 0000000..3918bbb --- /dev/null +++ b/libs/i18n/ja/hobbies.json @@ -0,0 +1,3 @@ +{ + "back-to-hobbies": "趣味一覧へ" +} diff --git a/libs/i18n/ja/index.ts b/libs/i18n/ja/index.ts index a87ad0a..d8d891d 100644 --- a/libs/i18n/ja/index.ts +++ b/libs/i18n/ja/index.ts @@ -2,6 +2,7 @@ import aboutMe from './about-me.json'; import blog from './blog.json'; import common from './common.json'; import contact from './contact.json'; +import hobbies from './hobbies.json'; import home from './home.json'; import nameCard from './name-card.json'; import note from './note.json'; @@ -9,11 +10,12 @@ import project from './project.json'; export default { 'about-me': aboutMe, - blog: blog, - common: common, - contact: contact, - home: home, + blog, + common, + contact, + home, 'name-card': nameCard, - note: note, - project: project -} as const; + note, + project, + hobbies +};