diff --git a/astro.config.mjs b/astro.config.mjs
index af4988b..7b5a8e9 100644
--- a/astro.config.mjs
+++ b/astro.config.mjs
@@ -12,4 +12,5 @@ export default defineConfig({
},
},
},
+ site: "https://blog.cloverta.top"
})
diff --git a/package-lock.json b/package-lock.json
index 640056e..716a31e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8,6 +8,7 @@
"name": "sanyecao-blog",
"version": "0.0.1",
"dependencies": {
+ "@astrojs/rss": "^4.0.17",
"astro": "^6.0.8",
"url": "^0.11.4"
},
@@ -73,6 +74,17 @@
"node": ">=22.12.0"
}
},
+ "node_modules/@astrojs/rss": {
+ "version": "4.0.17",
+ "resolved": "https://registry.npmjs.org/@astrojs/rss/-/rss-4.0.17.tgz",
+ "integrity": "sha512-eV+wdMbeVKC9+sPaV0LN8JL1LGo9YAh3GKl4Ou4nzMNLmXM/aswYpSGxVEAuHilgBZ6/++/Pv08ICmuOqX107w==",
+ "license": "MIT",
+ "dependencies": {
+ "fast-xml-parser": "5.4.1",
+ "piccolore": "^0.1.3",
+ "zod": "^4.3.6"
+ }
+ },
"node_modules/@astrojs/telemetry": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/@astrojs/telemetry/-/telemetry-3.3.0.tgz",
@@ -2371,6 +2383,40 @@
"integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==",
"license": "MIT"
},
+ "node_modules/fast-xml-builder": {
+ "version": "1.1.4",
+ "resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.1.4.tgz",
+ "integrity": "sha512-f2jhpN4Eccy0/Uz9csxh3Nu6q4ErKxf0XIsasomfOihuSUa3/xw6w8dnOtCDgEItQFJG8KyXPzQXzcODDrrbOg==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/NaturalIntelligence"
+ }
+ ],
+ "license": "MIT",
+ "dependencies": {
+ "path-expression-matcher": "^1.1.3"
+ }
+ },
+ "node_modules/fast-xml-parser": {
+ "version": "5.4.1",
+ "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.4.1.tgz",
+ "integrity": "sha512-BQ30U1mKkvXQXXkAGcuyUA/GA26oEB7NzOtsxCDtyu62sjGw5QraKFhx2Em3WQNjPw9PG6MQ9yuIIgkSDfGu5A==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/NaturalIntelligence"
+ }
+ ],
+ "license": "MIT",
+ "dependencies": {
+ "fast-xml-builder": "^1.0.0",
+ "strnum": "^2.1.2"
+ },
+ "bin": {
+ "fxparser": "src/cli/cli.js"
+ }
+ },
"node_modules/fdir": {
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
@@ -3892,6 +3938,21 @@
"url": "https://github.com/inikulin/parse5?sponsor=1"
}
},
+ "node_modules/path-expression-matcher": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.2.0.tgz",
+ "integrity": "sha512-DwmPWeFn+tq7TiyJ2CxezCAirXjFxvaiD03npak3cRjlP9+OjTmSy1EpIrEbh+l6JgUundniloMLDQ/6VTdhLQ==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/NaturalIntelligence"
+ }
+ ],
+ "license": "MIT",
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
"node_modules/piccolore": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/piccolore/-/piccolore-0.1.3.tgz",
@@ -4482,6 +4543,18 @@
"url": "https://github.com/sponsors/wooorm"
}
},
+ "node_modules/strnum": {
+ "version": "2.2.2",
+ "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.2.2.tgz",
+ "integrity": "sha512-DnR90I+jtXNSTXWdwrEy9FakW7UX+qUZg28gj5fk2vxxl7uS/3bpI4fjFYVmdK9etptYBPNkpahuQnEwhwECqA==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/NaturalIntelligence"
+ }
+ ],
+ "license": "MIT"
+ },
"node_modules/svgo": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/svgo/-/svgo-4.0.1.tgz",
diff --git a/package.json b/package.json
index f87d44f..c85ab4c 100644
--- a/package.json
+++ b/package.json
@@ -12,6 +12,7 @@
"astro": "astro"
},
"dependencies": {
+ "@astrojs/rss": "^4.0.17",
"astro": "^6.0.8",
"url": "^0.11.4"
},
diff --git a/src/pages/posts/post-1.md b/src/blog/post-1.md
similarity index 95%
rename from src/pages/posts/post-1.md
rename to src/blog/post-1.md
index 3fb7150..8f2e7b7 100644
--- a/src/pages/posts/post-1.md
+++ b/src/blog/post-1.md
@@ -1,5 +1,4 @@
---
-layout: ../../layouts/MarkdownPostLayout.astro
title: 'My First Blog Post'
pubDate: 2022-07-01
description: 'This is the first post of my new Astro blog.'
diff --git a/src/components/Header.astro b/src/components/Header.astro
index e69de29..4a13a56 100644
--- a/src/components/Header.astro
+++ b/src/components/Header.astro
@@ -0,0 +1,20 @@
+---
+import Navigation from "./Navigation.astro";
+import ThemeIcon from "./ThemeIcon.astro";
+---
+
+
+
+
diff --git a/src/components/Posts/PostList.astro b/src/components/Posts/PostList.astro
index db45052..81f7961 100644
--- a/src/components/Posts/PostList.astro
+++ b/src/components/Posts/PostList.astro
@@ -1,18 +1,24 @@
---
+import { getCollection } from "astro:content";
import PostItem from "./PostItem.astro";
-const allPosts = Object.values(import.meta.glob('@/pages/posts/*.md', { eager: true }));
+const allPosts = await getCollection("blog");
---
- {allPosts.map((post: any) => {
- const formattedDate = new Date(post.frontmatter.pubDate)
- .toISOString()
- .split("T")[0];
+ {
+ allPosts.map((post: any) => {
+ const formattedDate = new Date(post.data.pubDate)
+ .toISOString()
+ .split("T")[0];
- return (
-
- );
- })}
+ return (
+
+ );
+ })
+ }
-
diff --git a/src/components/ThemeIcon.astro b/src/components/ThemeIcon.astro
new file mode 100644
index 0000000..f7b7ed6
--- /dev/null
+++ b/src/components/ThemeIcon.astro
@@ -0,0 +1,77 @@
+---
+
+---
+
+
+
+
+
+
diff --git a/src/content.config.ts b/src/content.config.ts
new file mode 100644
index 0000000..ecea83b
--- /dev/null
+++ b/src/content.config.ts
@@ -0,0 +1,23 @@
+// Import the glob loader
+import { glob } from "astro/loaders";
+// Import utilities from `astro:content`
+import { defineCollection } from "astro:content";
+// Import Zod
+import { z } from "astro/zod";
+// Define a `loader` and `schema` for each collection
+const blog = defineCollection({
+ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }),
+ schema: z.object({
+ title: z.string(),
+ pubDate: z.date(),
+ description: z.string(),
+ author: z.string(),
+ image: z.object({
+ url: z.string(),
+ alt: z.string()
+ }),
+ tags: z.array(z.string())
+ })
+});
+// Export a single `collections` object to register your collection(s)
+export const collections = { blog };
\ No newline at end of file
diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro
index b4bc5f6..51ecd43 100644
--- a/src/layouts/BaseLayout.astro
+++ b/src/layouts/BaseLayout.astro
@@ -1,5 +1,6 @@
---
-import Footer from "../components/Footer.astro"
+import Footer from "../components/Footer.astro";
+import Header from "@/components/Header.astro";
const { pageTitle } = Astro.props;
---
@@ -14,6 +15,7 @@ const { pageTitle } = Astro.props;
{pageTitle}
+
diff --git a/src/layouts/MarkdownPostLayout.astro b/src/layouts/MarkdownPostLayout.astro
index 8b1220c..d9369d6 100644
--- a/src/layouts/MarkdownPostLayout.astro
+++ b/src/layouts/MarkdownPostLayout.astro
@@ -1,14 +1,46 @@
---
-import BaseLayout from './BaseLayout.astro';
-import '../styles/global.css'
+import BaseLayout from "./BaseLayout.astro";
+import "@/styles/global.css";
const { frontmatter } = Astro.props;
---
+
-
{frontmatter.title}
- {frontmatter.pubDate.toString().slice(0,10)}
{frontmatter.description}
+ {frontmatter.pubDate.toString().slice(0, 10)}
+
Written by: {frontmatter.author}
+
+
+
+
-
\ No newline at end of file
+
+
diff --git a/src/pages/about.astro b/src/pages/about.astro
index c669e44..3dcd2f1 100644
--- a/src/pages/about.astro
+++ b/src/pages/about.astro
@@ -1,17 +1,13 @@
---
import Footer from "@/components/Footer.astro";
import PostList from "@/components/Posts/PostList.astro";
+import BaseLayout from "@/layouts/BaseLayout.astro";
import "@/styles/global.css";
const pageTitle = "About Me";
---
-
-
-
- {pageTitle}
-
-
+
{pageTitle}
... and my new Astro site!
@@ -28,6 +24,4 @@ const pageTitle = "About Me";
My Astro Learning Blog
This is where I will post about my journey learning Astro.
-
-
-
+
diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro
new file mode 100644
index 0000000..18918fe
--- /dev/null
+++ b/src/pages/posts/[...slug].astro
@@ -0,0 +1,19 @@
+---
+import { getCollection, render } from "astro:content";
+import MarkdownPostLayout from "@/layouts/MarkdownPostLayout.astro";
+
+export async function getStaticPaths() {
+ const posts = await getCollection("blog");
+ return posts.map((post) => ({
+ params: { slug: post.id },
+ props: { post },
+ }));
+}
+
+const { post } = Astro.props;
+const { Content } = await render(post);
+---
+
+
+
+
diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js
new file mode 100644
index 0000000..fa16634
--- /dev/null
+++ b/src/pages/rss.xml.js
@@ -0,0 +1,11 @@
+import rss, { pagesGlobToRssItems } from '@astrojs/rss';
+
+export async function GET(context) {
+ return rss({
+ title: 'Astro Learner | Blog',
+ description: 'My journey learning Astro',
+ site: context.site,
+ items: await pagesGlobToRssItems(import.meta.glob('./**/*.md')),
+ customData: `en-us`,
+ });
+}
\ No newline at end of file
diff --git a/src/pages/tags/[tag].astro b/src/pages/tags/[tag].astro
index 5f56ee1..c7622ff 100644
--- a/src/pages/tags/[tag].astro
+++ b/src/pages/tags/[tag].astro
@@ -1,19 +1,17 @@
---
-import BaseLayout from "@/layouts/BaseLayout.astro";
+import { getCollection } from "astro:content";
+import BaseLayout from "../../layouts/BaseLayout.astro";
import PostItem from "@/components/Posts/PostItem.astro";
export async function getStaticPaths() {
- const allPosts = Object.values(
- import.meta.glob("../posts/*.md", { eager: true }),
- );
-
+ const allPosts = await getCollection("blog");
const uniqueTags = [
- ...new Set(allPosts.map((post: any) => post.frontmatter.tags).flat()),
+ ...new Set(allPosts.map((post) => post.data.tags).flat()),
];
return uniqueTags.map((tag) => {
- const filteredPosts = allPosts.filter((post: any) =>
- post.frontmatter.tags.includes(tag),
+ const filteredPosts = allPosts.filter((post) =>
+ post.data.tags.includes(tag),
);
return {
params: { tag },
@@ -24,17 +22,14 @@ export async function getStaticPaths() {
const { tag } = Astro.params;
const { posts } = Astro.props;
-const filteredPosts = posts.filter((post: any) =>
- post.frontmatter.tags?.includes(tag),
-);
---
Posts tagged with {tag}
{
- posts.map((post: any) => (
-
+ posts.map((post) => (
+
))
}
diff --git a/src/styles/global.css b/src/styles/global.css
index 87e6aef..c621a7f 100644
--- a/src/styles/global.css
+++ b/src/styles/global.css
@@ -18,4 +18,27 @@ body {
h1 {
margin: 1rem 0;
font-size: 2.5rem;
+}
+
+html.dark {
+ background-color: #0d0950;
+ color: #fff;
+}
+
+.dark .menu {
+ background-color: #fff;
+ color: #000;
+}
+
+.dark .nav-links a:hover,
+.dark .nav-links a:focus {
+ color: #0d0950;
+}
+
+.dark .nav-links a {
+ color: #fff;
+}
+
+.dark a {
+ color: #ff9776;
}
\ No newline at end of file