update
This commit is contained in:
@@ -68,8 +68,26 @@ export default defineNuxtConfig({
|
|||||||
robots: { groups: [{ userAgent: ["GPTBot", "ChatGPT-User"], disallow: ["/"] }] },
|
robots: { groups: [{ userAgent: ["GPTBot", "ChatGPT-User"], disallow: ["/"] }] },
|
||||||
|
|
||||||
sitemap: {
|
sitemap: {
|
||||||
sources: ["/api/__sitemap__/urls"],
|
sitemapsPathPrefix: "/",
|
||||||
autoLastmod: true,
|
autoLastmod: true,
|
||||||
|
sitemaps: {
|
||||||
|
posts: {
|
||||||
|
sources: ["/api/__sitemap__/urls"],
|
||||||
|
include: ["/posts/**"],
|
||||||
|
},
|
||||||
|
tags: {
|
||||||
|
sources: ["/api/__sitemap__/urls"],
|
||||||
|
include: ["/tags/**"],
|
||||||
|
},
|
||||||
|
categories: {
|
||||||
|
sources: ["/api/__sitemap__/urls"],
|
||||||
|
include: ["/categories/**"],
|
||||||
|
},
|
||||||
|
pages: {
|
||||||
|
sources: ["/api/__sitemap__/urls"],
|
||||||
|
include: ["/", "/about", "/archive", "/tags", "/categories"],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
typescript: {
|
typescript: {
|
||||||
|
|||||||
@@ -3,32 +3,45 @@ import siteConfig from "~/config";
|
|||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
setHeader(event, "content-type", "text/xml");
|
setHeader(event, "content-type", "text/xml");
|
||||||
const docs = await queryCollection(event, "content").all();
|
const docs = await queryCollection(event, "content").where("published", "=", true).all();
|
||||||
|
|
||||||
|
const baseUrl = siteConfig.siteMeta.url ?? "";
|
||||||
|
const favicon = siteConfig.siteMeta.favicon
|
||||||
|
? `${baseUrl}/${siteConfig.siteMeta.favicon}`
|
||||||
|
: undefined;
|
||||||
|
const language = siteConfig.siteMeta.lang ?? "zh-CN";
|
||||||
|
|
||||||
const feed = new Feed({
|
const feed = new Feed({
|
||||||
title: siteConfig.siteMeta.title,
|
title: siteConfig.siteMeta.title ?? "",
|
||||||
description: siteConfig.siteMeta.description,
|
description: siteConfig.siteMeta.description ?? "",
|
||||||
id: siteConfig.siteMeta.url,
|
id: baseUrl,
|
||||||
link: siteConfig.siteMeta.url,
|
link: baseUrl,
|
||||||
language: siteConfig.siteMeta.lang,
|
language,
|
||||||
favicon: `${siteConfig.siteMeta.url}/${siteConfig.siteMeta.favicon}`,
|
favicon,
|
||||||
copyright: "MIT",
|
copyright: "MIT",
|
||||||
author: {
|
author: {
|
||||||
name: siteConfig.siteMeta.author,
|
name: siteConfig.siteMeta.author ?? "",
|
||||||
email: siteConfig.siteMeta.email,
|
email: siteConfig.siteMeta.email ?? undefined,
|
||||||
link: siteConfig.siteMeta.url,
|
link: baseUrl,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add the feed items
|
// Add the feed items
|
||||||
docs.forEach((doc) => {
|
docs.forEach((doc: Record<string, unknown>) => {
|
||||||
// console.log(doc)
|
const title = typeof doc.title === "string" ? doc.title : "";
|
||||||
|
const path = typeof doc.path === "string" ? doc.path : "";
|
||||||
|
const description = typeof doc.description === "string" ? doc.description : "";
|
||||||
|
const meta = (doc as { meta?: Record<string, unknown> }).meta;
|
||||||
|
const dateStr = meta && typeof meta.date === "string" ? meta.date : undefined;
|
||||||
|
const date = dateStr ? new Date(dateStr) : new Date();
|
||||||
|
|
||||||
feed.addItem({
|
feed.addItem({
|
||||||
title: doc.title || "",
|
title,
|
||||||
id: siteConfig.siteMeta.url + "/" + doc.path,
|
id: `${baseUrl}/${path}`,
|
||||||
link: siteConfig.siteMeta.url + "/" + doc.path,
|
link: `${baseUrl}/${path}`,
|
||||||
description: doc.description,
|
description,
|
||||||
content: doc.description,
|
content: description,
|
||||||
date: new Date(doc.meta?.date as string),
|
date,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user