This commit is contained in:
2026-01-01 19:02:59 +08:00
parent 315ca37dba
commit ac944d05ec
9 changed files with 107 additions and 56 deletions

2
.gitignore vendored
View File

@@ -2,8 +2,10 @@
.output .output
.nuxt .nuxt
.data .data
dist/
# Node dependencies # Node dependencies
node_modules node_modules
# System files # System files
*.log *.log
.env .env

View File

@@ -8,12 +8,6 @@ useHead({
}, },
], ],
}); });
defineOgImageComponent("About", {
headline: "Wrong Path",
title: "404",
description: "Page Not Found",
});
</script> </script>
<template> <template>

View File

@@ -71,16 +71,6 @@ useHead({
}, },
], ],
}); });
// Generate OG Image
const siteData = useSiteConfig();
defineOgImage({
props: {
title: "Archive",
description: "Here you will find all the blog posts I have written & published on this site.",
siteName: siteData.url,
},
});
</script> </script>
<template> <template>

View File

@@ -28,16 +28,6 @@ useHead({
], ],
}); });
// Generate OG Image
const siteData = useSiteConfig();
defineOgImage({
props: {
title: "Categories",
description:
"Below All the topics are listed on which either I have written a blog or will write a blog in near future.",
siteName: siteData.url,
},
});
</script> </script>
<template> <template>

View File

@@ -48,16 +48,6 @@ useHead({
}, },
], ],
}); });
// Generate OG Image
const siteData = useSiteConfig();
defineOgImage({
props: {
title: `Tag: ${tag.value?.toUpperCase()}`,
description: `Explore all posts tagged with ${tag.value}`,
siteName: siteData.url,
},
});
</script> </script>
<template> <template>

View File

@@ -26,16 +26,6 @@ useHead({
}, },
], ],
}); });
// Generate OG Image
const siteData = useSiteConfig();
defineOgImage({
props: {
title: "Tags",
description: "Explore all the tags used in the blog posts.",
siteName: siteData.url,
},
});
</script> </script>
<template> <template>

View File

@@ -22,7 +22,7 @@ export default defineNuxtConfig({
"@nuxt/eslint", "@nuxt/eslint",
"@vueuse/nuxt", "@vueuse/nuxt",
"@nuxtjs/robots", "@nuxtjs/robots",
"@nuxtjs/seo", // "@nuxtjs/seo",
"@nuxtjs/sitemap", "@nuxtjs/sitemap",
"@nuxt/content", "@nuxt/content",
"@nuxtjs/color-mode", "@nuxtjs/color-mode",
@@ -65,16 +65,9 @@ export default defineNuxtConfig({
// robots: { groups: [{ userAgent: ["GPTBot", "ChatGPT-User"], disallow: ["/"] }] }, // robots: { groups: [{ userAgent: ["GPTBot", "ChatGPT-User"], disallow: ["/"] }] },
sitemap: { sitemap: {
sitemapsPathPrefix: "/", sources: ["/api/__sitemap__/urls"],
zeroRuntime: true, excludeAppSources: true,
sitemaps: {
posts: {
include: ["/blog/**"],
},
},
autoLastmod: true, autoLastmod: true,
// sources: ["/api/sitemap"],
// sources: ["/api/__sitemap__/urls"],
}, },
typescript: { typescript: {

View File

@@ -0,0 +1,64 @@
export default defineEventHandler(async (event) => {
const docs = await queryCollection(event, "content").all();
const urls: Array<{ loc: string; lastmod: string }> = [];
// 添加静态页面
urls.push({ loc: "/", lastmod: new Date().toISOString() });
urls.push({ loc: "/about", lastmod: new Date().toISOString() });
urls.push({ loc: "/archive", lastmod: new Date().toISOString() });
urls.push({ loc: "/categories", lastmod: new Date().toISOString() });
urls.push({ loc: "/tags", lastmod: new Date().toISOString() });
// 添加博客文章
docs.forEach((doc: Record<string, unknown>) => {
if (typeof doc.path === "string" && !doc.path.includes("about")) {
urls.push({
loc: doc.path,
lastmod: typeof doc._mtime === "string" ? doc._mtime : new Date().toISOString(),
});
}
});
// 获取所有分类
const categories = new Set<string>();
docs.forEach((doc: Record<string, unknown>) => {
if (doc.categories && Array.isArray(doc.categories)) {
doc.categories.forEach((cat: unknown) => {
if (typeof cat === "string") categories.add(cat);
});
} else if (doc.category && Array.isArray(doc.category)) {
doc.category.forEach((cat: unknown) => {
if (typeof cat === "string") categories.add(cat);
});
} else if (typeof doc.category === "string") {
categories.add(doc.category);
}
});
categories.forEach((category) => {
urls.push({
loc: `/categories/${category}`,
lastmod: new Date().toISOString(),
});
});
// 获取所有标签
const tags = new Set<string>();
docs.forEach((doc: Record<string, unknown>) => {
if (doc.tags && Array.isArray(doc.tags)) {
doc.tags.forEach((tag: unknown) => {
if (typeof tag === "string") tags.add(tag);
});
}
});
tags.forEach((tag) => {
urls.push({
loc: `/tags/${tag}`,
lastmod: new Date().toISOString(),
});
});
return urls;
});

38
server/routes/rss.xml.ts Normal file
View File

@@ -0,0 +1,38 @@
import { Feed } from "feed";
const basePath = "https://blog.rhen.cloud";
export default defineEventHandler(async (event) => {
setHeader(event, "content-type", "text/xml");
const docs = await queryCollection(event, "content").all();
const feed = new Feed({
title: "RhenCloud's Blog",
description:
"Welcome To My Blog Site. Get Web Development, Javascript, Typescript, NodeJs, Vue, and Nuxt, Related Articles, Tips, Learning resources and more.",
id: basePath,
link: basePath,
language: "zh-CN",
favicon: `${basePath}/favicon.ico`,
copyright: "MIT",
author: {
name: "RhenCloud",
email: "i@rhen.cloud",
link: basePath,
},
});
// Add the feed items
docs.forEach((doc) => {
// console.log(doc)
feed.addItem({
title: doc.title || "",
id: basePath + doc.path,
link: basePath + doc.path,
description: doc.description,
content: doc.description,
date: new Date(doc.meta?.date as string),
});
});
return feed.rss2();
});