From 90eaaa8ae4bf3032839a7d097141f3718dda27e1 Mon Sep 17 00:00:00 2001 From: kaivanwong Date: Sat, 11 May 2024 17:20:49 +0800 Subject: [PATCH] feat!: add file to src --- src/components/ScrollToTop.vue | 24 +++++++++ src/content/blog/note/post-1.md | 7 +++ src/content/blog/note/post-2.md | 7 +++ src/content/blog/note/post-3.md | 7 +++ src/content/blog/note/post-4.md | 7 +++ src/content/blog/post-1.md | 7 +++ src/content/blog/post-2.md | 8 +++ src/content/blog/post-3.md | 8 +++ src/content/blog/post-4.md | 6 +++ src/content/blog/post-5.md | 6 +++ src/content/blog/post-6.md | 5 ++ src/content/blog/post-7.md | 6 +++ src/content/blog/post-8.md | 5 ++ src/content/pages/page-1.md | 6 +++ src/content/pages/page-2.md | 6 +++ src/pages/blog/[...path].astro | 49 ++++++++++++++++++ src/pages/posts/[...slug].astro | 61 +++++++++++++++++++++++ src/pages/projects/data.ts | 88 +++++++++++++++++++++++++++++++++ src/pages/projects/index.astro | 31 ++++++++++++ src/pages/robots.txt.ts | 15 ++++++ src/pages/rss.xml.ts | 26 ++++++++++ src/styles/dot.css | 24 +++++++++ src/styles/global.css | 59 ++++++++++++++++++++++ src/utils/link.ts | 3 ++ 24 files changed, 471 insertions(+) create mode 100644 src/components/ScrollToTop.vue create mode 100644 src/content/blog/note/post-1.md create mode 100644 src/content/blog/note/post-2.md create mode 100644 src/content/blog/note/post-3.md create mode 100644 src/content/blog/note/post-4.md create mode 100644 src/content/blog/post-1.md create mode 100644 src/content/blog/post-2.md create mode 100644 src/content/blog/post-3.md create mode 100644 src/content/blog/post-4.md create mode 100644 src/content/blog/post-5.md create mode 100644 src/content/blog/post-6.md create mode 100644 src/content/blog/post-7.md create mode 100644 src/content/blog/post-8.md create mode 100644 src/content/pages/page-1.md create mode 100644 src/content/pages/page-2.md create mode 100644 src/pages/blog/[...path].astro create mode 100644 src/pages/posts/[...slug].astro create mode 100644 src/pages/projects/data.ts create mode 100644 src/pages/projects/index.astro create mode 100644 src/pages/robots.txt.ts create mode 100644 src/pages/rss.xml.ts create mode 100644 src/styles/dot.css create mode 100644 src/styles/global.css create mode 100644 src/utils/link.ts diff --git a/src/components/ScrollToTop.vue b/src/components/ScrollToTop.vue new file mode 100644 index 0000000..c2b2256 --- /dev/null +++ b/src/components/ScrollToTop.vue @@ -0,0 +1,24 @@ + + + diff --git a/src/content/blog/note/post-1.md b/src/content/blog/note/post-1.md new file mode 100644 index 0000000..6f26b24 --- /dev/null +++ b/src/content/blog/note/post-1.md @@ -0,0 +1,7 @@ +--- +title: Note Name +duration: 5min +date: 2022-12-01 +--- + +Writing... diff --git a/src/content/blog/note/post-2.md b/src/content/blog/note/post-2.md new file mode 100644 index 0000000..17b4696 --- /dev/null +++ b/src/content/blog/note/post-2.md @@ -0,0 +1,7 @@ +--- +title: Note Name +duration: 5min +date: 2018-01-01 +--- + +Writing... diff --git a/src/content/blog/note/post-3.md b/src/content/blog/note/post-3.md new file mode 100644 index 0000000..9916de2 --- /dev/null +++ b/src/content/blog/note/post-3.md @@ -0,0 +1,7 @@ +--- +title: Note Name +duration: 5min +date: 2022-02-01 +--- + +Writing... diff --git a/src/content/blog/note/post-4.md b/src/content/blog/note/post-4.md new file mode 100644 index 0000000..f5c6e81 --- /dev/null +++ b/src/content/blog/note/post-4.md @@ -0,0 +1,7 @@ +--- +title: Note Name +duration: 5min +date: 2024-03-01 +--- + +Writing... diff --git a/src/content/blog/post-1.md b/src/content/blog/post-1.md new file mode 100644 index 0000000..b7e5647 --- /dev/null +++ b/src/content/blog/post-1.md @@ -0,0 +1,7 @@ +--- +title: Blog Name +description: Your blog description, which is long text, can be an introduction to the post or a paragraph of the post. +date: 2024-05-01 +--- + +Writing... diff --git a/src/content/blog/post-2.md b/src/content/blog/post-2.md new file mode 100644 index 0000000..c8df847 --- /dev/null +++ b/src/content/blog/post-2.md @@ -0,0 +1,8 @@ +--- +title: Blog Name +description: If you set the lang field to include zh, it will display an identifier. +date: 2024-04-01 +lang: zh +--- + +Writing... diff --git a/src/content/blog/post-3.md b/src/content/blog/post-3.md new file mode 100644 index 0000000..f415db8 --- /dev/null +++ b/src/content/blog/post-3.md @@ -0,0 +1,8 @@ +--- +title: Blog Name +description: A tag field is provided, which can be used to display custom information. +date: 2024-03-01 +tag: Tag Text +--- + +Writing... diff --git a/src/content/blog/post-4.md b/src/content/blog/post-4.md new file mode 100644 index 0000000..df91822 --- /dev/null +++ b/src/content/blog/post-4.md @@ -0,0 +1,6 @@ +--- +title: Blog Name +description: If you need to link to an external address, you can set the redirect field. +date: 2024-02-01 +redirect: '/' +--- diff --git a/src/content/blog/post-5.md b/src/content/blog/post-5.md new file mode 100644 index 0000000..bc391b0 --- /dev/null +++ b/src/content/blog/post-5.md @@ -0,0 +1,6 @@ +--- +title: Blog Name +description: If you want to tell the visitor that there is a video, you can set the video field to true. +date: 2024-02-01 +video: true +--- diff --git a/src/content/blog/post-6.md b/src/content/blog/post-6.md new file mode 100644 index 0000000..a739d34 --- /dev/null +++ b/src/content/blog/post-6.md @@ -0,0 +1,5 @@ +--- +title: Blog Name +description: Vitesse theme groups posts by year and displays them sorted by date. +date: 2023-08-01 +--- diff --git a/src/content/blog/post-7.md b/src/content/blog/post-7.md new file mode 100644 index 0000000..89a5d42 --- /dev/null +++ b/src/content/blog/post-7.md @@ -0,0 +1,6 @@ +--- +title: Blog Name +description: You can set a duration to tell the viewer how long it will take to watch it。 +duration: 20min +date: 2023-05-01 +--- diff --git a/src/content/blog/post-8.md b/src/content/blog/post-8.md new file mode 100644 index 0000000..65fbed6 --- /dev/null +++ b/src/content/blog/post-8.md @@ -0,0 +1,5 @@ +--- +title: Blog Name +description: The date and title fields are required. +date: 2022-11-01 +--- diff --git a/src/content/pages/page-1.md b/src/content/pages/page-1.md new file mode 100644 index 0000000..340a51d --- /dev/null +++ b/src/content/pages/page-1.md @@ -0,0 +1,6 @@ +--- +title: Sponsor +description: How to sponsor for me. +--- + +Writing... diff --git a/src/content/pages/page-2.md b/src/content/pages/page-2.md new file mode 100644 index 0000000..340a51d --- /dev/null +++ b/src/content/pages/page-2.md @@ -0,0 +1,6 @@ +--- +title: Sponsor +description: How to sponsor for me. +--- + +Writing... diff --git a/src/pages/blog/[...path].astro b/src/pages/blog/[...path].astro new file mode 100644 index 0000000..238c63b --- /dev/null +++ b/src/pages/blog/[...path].astro @@ -0,0 +1,49 @@ +--- +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' + +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 { path } = Astro.params + +const posts = await getPosts(path) +--- + + +
+ { + siteConfig.page.navLinks.map((nav) => ( + + {nav.text} + + )) + } +
+ +
diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro new file mode 100644 index 0000000..61857a0 --- /dev/null +++ b/src/pages/posts/[...slug].astro @@ -0,0 +1,61 @@ +--- +import BaseLayout from '@/layouts/BaseLayout.astro' +import { type CollectionPosts } from '@/types' +import { getPosts } from '@/utils/posts' + +export async function getStaticPaths() { + const posts = await getPosts() + return posts.map((post) => { + return { + params: { slug: post.slug }, + props: { + post, + }, + } + }) +} + +type Props = { post: CollectionPosts } + +const { post } = Astro.props +const { title, image, description, date, duration, tag } = post.data + +const { Content } = await post.render() + +function getDate(date: string) { + return new Date(date).toISOString() +} +--- + + +
+

+ {title} +

+

+ {date && } + {duration && · {duration}} + {tag && · {tag}} +

+ { + image && ( +

+ {image.alt +

+ ) + } + +
+
diff --git a/src/pages/projects/data.ts b/src/pages/projects/data.ts new file mode 100644 index 0000000..37e4a6e --- /dev/null +++ b/src/pages/projects/data.ts @@ -0,0 +1,88 @@ +import type { ProjectData } from '@/types' + +export const projectData: ProjectData = [ + { + title: 'Projects Group', + projects: [ + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + ], + }, + { + title: 'Projects Group', + projects: [ + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + ], + }, + { + title: 'Project Name', + projects: [], + }, + { + title: 'Projects Group', + projects: [ + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + ], + }, + { + title: 'Projects Group', + projects: [ + { + text: 'Project Name', + description: 'Your project description information is a long piece of text.', + icon: 'i-carbon-campsite', + href: '/', + }, + ], + }, +] diff --git a/src/pages/projects/index.astro b/src/pages/projects/index.astro new file mode 100644 index 0000000..1172be8 --- /dev/null +++ b/src/pages/projects/index.astro @@ -0,0 +1,31 @@ +--- +import { projectData } from './data' +import BaseLayout from '@/layouts/BaseLayout.astro' +import ListProjects from '@/components/ListProjects.vue' +--- + + +

Projects

+
+ { + projectData.length > 0 && ( +
+ {projectData.map((i) => ( +
+

+ + {i.title} + +

+ +
+ ))} +
+ ) + } +
+
diff --git a/src/pages/robots.txt.ts b/src/pages/robots.txt.ts new file mode 100644 index 0000000..d7d57a4 --- /dev/null +++ b/src/pages/robots.txt.ts @@ -0,0 +1,15 @@ +interface Context { + site: string +} + +export function GET(context: Context) { + const robots = ` +User-agent: * +Allow: / + +Sitemap: ${new URL('sitemap-index.xml', context.site).href}`.trim() + + return new Response(robots, { + headers: { 'Content-Type': 'text/plain; charset=utf-8' }, + }) +} diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts new file mode 100644 index 0000000..f731ddb --- /dev/null +++ b/src/pages/rss.xml.ts @@ -0,0 +1,26 @@ +import rss from '@astrojs/rss' +import siteConfig from '@/site-config' +import { getPosts } from '@/utils/posts' + +interface Context { + site: string +} + +export async function GET(context: Context) { + const posts = await getPosts() + + return rss({ + title: siteConfig.title, + description: siteConfig.description, + site: context.site, + items: posts!.map((item) => { + return { + ...item.data, + link: `${context.site}/posts/${item.slug}/`, + pubDate: new Date(item.data.date), + content: item.body, + author: `${siteConfig.author} <${siteConfig.email}>`, + } + }), + }) +} diff --git a/src/styles/dot.css b/src/styles/dot.css new file mode 100644 index 0000000..47f896f --- /dev/null +++ b/src/styles/dot.css @@ -0,0 +1,24 @@ +html.dark { + --dot-bg-color: #0d1117; + --dot-color: #2f353c; + --dot-mask-color: #000000; +} + +html:not(.dark) { + --dot-bg-color: #ffffff; + --dot-color: #a5aeb850; + --dot-mask-color: #ffffff; +} + +.bg-dot::before { + content: ''; + position: absolute; + inset: 0; + background: + linear-gradient(90deg, var(--dot-bg-color) 22px, transparent 1%) 50%, + linear-gradient(var(--dot-bg-color) 22px, transparent 1%) 50%, + var(--dot-color); + background-position: center center; + background-size: 24px 24px; + mask-image: linear-gradient(0deg, transparent 5%, var(--dot-mask-color)); +} diff --git a/src/styles/global.css b/src/styles/global.css new file mode 100644 index 0000000..3464123 --- /dev/null +++ b/src/styles/global.css @@ -0,0 +1,59 @@ +html.dark .astro-code, +html.dark .astro-code span { + color: var(--shiki-dark) !important; + background-color: #161b22 !important; + font-style: var(--shiki-dark-font-style) !important; + font-weight: var(--shiki-dark-font-weight) !important; + text-decoration: var(--shiki-dark-text-decoration) !important; +} + +html.dark { + color-scheme: dark; +} + +html:not(.dark) { + color-scheme: light; +} + +#nprogress { + pointer-events: none; +} + +#nprogress .bar { + background: #888; + opacity: 0.75; + position: fixed; + z-index: 999; + top: 0; + left: 0; + width: 100%; + height: 2px; +} + +img { + --at-apply: rd-1.5; +} + +.prose-link i { + --at-apply: text-sm mr-1; +} + +.prose a { + --at-apply: prose-link; +} + +.prose h1 { + --at-apply: text-9 mb-4; +} + +.prose h2 { + --at-apply: mt-16 mb-4 text-6; +} + +.prose h3 { + --at-apply: mt-10 mb-4 text-5; +} + +article { + --at-apply: sm: min-h-38 min-h-28; +} diff --git a/src/utils/link.ts b/src/utils/link.ts new file mode 100644 index 0000000..96e5ee2 --- /dev/null +++ b/src/utils/link.ts @@ -0,0 +1,3 @@ +export function getLinkTarget(link: string) { + return link.includes('http') ? '_blank' : '_self' +}