From 848543accfd9a6759b8efb6fd6b15ffb1b2acd11 Mon Sep 17 00:00:00 2001 From: kaivanwong Date: Mon, 13 May 2024 10:35:54 +0800 Subject: [PATCH] feat: add 404 page --- src/content/blog/{note => notes}/post-1.md | 0 src/content/blog/{note => notes}/post-2.md | 0 src/content/blog/{note => notes}/post-3.md | 0 src/content/blog/{note => notes}/post-4.md | 0 src/content/blog/talks/post-1.md | 7 ++++++ src/layouts/BaseLayout.astro | 2 +- src/pages/404.mdx | 9 ++++++++ src/pages/[...slug].astro | 8 +++---- src/pages/blog/[...path].astro | 25 ++++++++-------------- src/pages/index.astro | 9 ++++---- src/pages/posts/[...slug].astro | 13 +++-------- src/pages/projects/index.astro | 6 +----- src/site-config.ts | 18 +++++++++++----- src/styles/global.css | 6 +++++- 14 files changed, 55 insertions(+), 48 deletions(-) rename src/content/blog/{note => notes}/post-1.md (100%) rename src/content/blog/{note => notes}/post-2.md (100%) rename src/content/blog/{note => notes}/post-3.md (100%) rename src/content/blog/{note => notes}/post-4.md (100%) create mode 100644 src/content/blog/talks/post-1.md create mode 100644 src/pages/404.mdx diff --git a/src/content/blog/note/post-1.md b/src/content/blog/notes/post-1.md similarity index 100% rename from src/content/blog/note/post-1.md rename to src/content/blog/notes/post-1.md diff --git a/src/content/blog/note/post-2.md b/src/content/blog/notes/post-2.md similarity index 100% rename from src/content/blog/note/post-2.md rename to src/content/blog/notes/post-2.md diff --git a/src/content/blog/note/post-3.md b/src/content/blog/notes/post-3.md similarity index 100% rename from src/content/blog/note/post-3.md rename to src/content/blog/notes/post-3.md diff --git a/src/content/blog/note/post-4.md b/src/content/blog/notes/post-4.md similarity index 100% rename from src/content/blog/note/post-4.md rename to src/content/blog/notes/post-4.md diff --git a/src/content/blog/talks/post-1.md b/src/content/blog/talks/post-1.md new file mode 100644 index 0000000..9aa9ac5 --- /dev/null +++ b/src/content/blog/talks/post-1.md @@ -0,0 +1,7 @@ +--- +title: Talk Name +duration: 30min +date: 2022-12-01 +--- + +Writing... diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro index 239813f..5d9ae61 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -6,7 +6,7 @@ import Header from '@/components/Header.vue' import Footer from '@/components/Footer.vue' import ScrollToTop from '@/components/ScrollToTop.vue' -const { pageOperate = false, ...head } = Astro.props +const { ...head } = Astro.props --- diff --git a/src/pages/404.mdx b/src/pages/404.mdx new file mode 100644 index 0000000..3a556ad --- /dev/null +++ b/src/pages/404.mdx @@ -0,0 +1,9 @@ +import BaseLayout from '@/layouts/BaseLayout.astro'; + + +
+

404 :(

+

Page Not Found

+

Sorry, we couldn't find what you were looking for.

+
+ diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro index 204e823..737396f 100644 --- a/src/pages/[...slug].astro +++ b/src/pages/[...slug].astro @@ -21,11 +21,9 @@ const { title, description, image } = page.data const { Content } = await page.render() --- - -
-

- {title} -

+ +
+

{title}

{ image && (

diff --git a/src/pages/blog/[...path].astro b/src/pages/blog/[...path].astro index 238c63b..b5aa3ca 100644 --- a/src/pages/blog/[...path].astro +++ b/src/pages/blog/[...path].astro @@ -1,24 +1,17 @@ --- import BaseLayout from '@/layouts/BaseLayout.astro' import ListPosts from '@/components/ListPosts.vue' -import { getPosts } from '@/utils/posts' import siteConfig from '@/site-config' -import { uniqBy } from 'lodash-es' +import { getPosts } from '@/utils/posts' export async function getStaticPaths() { - const blogEntries = await getPosts() - return uniqBy( - blogEntries.map((entry) => { - return { - params: { - path: entry.slug.includes('/') - ? entry.slug.split('/').shift() - : undefined, - }, - } - }), - 'params.path', - ) + const paths = siteConfig.page.blogLinks.map((nav) => { + const href = nav.href.replace('/blog', '') + return { + params: { path: href === '' ? undefined : href }, + } + }) + return paths } const { path } = Astro.params @@ -34,7 +27,7 @@ const posts = await getPosts(path) >

{ - siteConfig.page.navLinks.map((nav) => ( + siteConfig.page.blogLinks.map((nav) => ( for style, it's fast.

- Visit + Visit it - it on GitHub + on GitHub to fork the repository, read the docs or one-click deploy on Netlify.

If you like Vitesse theme for Astro, please - - click follow for me - . + click follow + for me.


Find me on

diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 61857a0..c7d2dc9 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -27,16 +27,9 @@ function getDate(date: string) { } --- - -
-

- {title} -

+ +
+

{title}

{date && } {duration && ยท {duration}} diff --git a/src/pages/projects/index.astro b/src/pages/projects/index.astro index 1172be8..c848955 100644 --- a/src/pages/projects/index.astro +++ b/src/pages/projects/index.astro @@ -4,11 +4,7 @@ import BaseLayout from '@/layouts/BaseLayout.astro' import ListProjects from '@/components/ListProjects.vue' --- - +

Projects

{ diff --git a/src/site-config.ts b/src/site-config.ts index e007ab2..8ede02b 100644 --- a/src/site-config.ts +++ b/src/site-config.ts @@ -58,8 +58,12 @@ export const siteConfig = { href: '/blog', }, { - text: 'Note', - href: '/blog/note', + text: 'Notes', + href: '/blog/notes', + }, + { + text: 'Talks', + href: '/blog/talks', }, { text: 'Projects', @@ -68,14 +72,18 @@ export const siteConfig = { ], }, page: { - navLinks: [ + blogLinks: [ { text: 'Blog', href: '/blog', }, { - text: 'Note', - href: '/blog/note', + text: 'Notes', + href: '/blog/notes', + }, + { + text: 'Talks', + href: '/blog/talks', }, ], }, diff --git a/src/styles/global.css b/src/styles/global.css index 3464123..5bb123c 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -34,6 +34,10 @@ img { --at-apply: rd-1.5; } +.prose { + --at-apply: mb-16 max-w-none min-h-60; +} + .prose-link i { --at-apply: text-sm mr-1; } @@ -43,7 +47,7 @@ img { } .prose h1 { - --at-apply: text-9 mb-4; + --at-apply: text-9 mb-4 text-title; } .prose h2 {