This commit is contained in:
1 parent
f80e901b21
commit
c14493c00f
3 files changed
+28
-1
No files matched your search
@@ -86,6 +86,7 @@ function makeUniqueAbbrlink(seed, usedAbbrlinks) {
|
||||
async function main() {
|
||||
const files = await listMarkdownFiles(POSTS_DIR);
|
||||
const usedAbbrlinks = new Set();
|
||||
const existingFiles = new Map();
|
||||
const pending = [];
|
||||
|
||||
for (const file of files) {
|
||||
@@ -97,6 +98,10 @@ async function main() {
|
||||
const existing = getScalar(frontmatterLines, 'abbrlink');
|
||||
|
||||
if (existing) {
|
||||
if (existingFiles.has(existing)) {
|
||||
throw new Error(`Duplicate abbrlink "${existing}" in ${relative(process.cwd(), existingFiles.get(existing))} and ${relative(process.cwd(), file)}`);
|
||||
}
|
||||
existingFiles.set(existing, file);
|
||||
usedAbbrlinks.add(existing);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ const consoleSites = [
|
||||
{keywords.length > 0 && <meta name="keywords" content={keywords.join(', ')} />}
|
||||
<link rel="canonical" href={canonicalUrl} />
|
||||
<link rel="alternate" type="application/rss+xml" title={`${siteTitle} RSS`} href={new URL('/rss.xml', siteConfig.site.url).href} />
|
||||
<link rel="alternate" type="application/atom+xml" title={`${siteTitle} Atom`} href={new URL('/atom.xml', siteConfig.site.url).href} />
|
||||
<meta property="og:site_name" content={siteTitle} />
|
||||
<meta property="og:locale" content="zh_CN" />
|
||||
<meta property="og:type" content={type} />
|
||||
|
||||
+22
-1
@@ -1 +1,22 @@
|
||||
export { GET } from './rss.xml.js';
|
||||
import { getAllPosts } from '@/lib/posts';
|
||||
import { siteConfig } from '../../site.config.mjs';
|
||||
|
||||
const escapeXml = (value) => String(value).replace(/[&<>"']/g, (char) => ({
|
||||
'&': '&', '<': '<', '>': '>', '"': '"', "'": ''',
|
||||
})[char]);
|
||||
|
||||
export async function GET(context) {
|
||||
const posts = await getAllPosts();
|
||||
const site = context.site || new URL(siteConfig.site.url);
|
||||
const absolute = (path) => new URL(path, site).href;
|
||||
const updated = posts.reduce((latest, post) => {
|
||||
const date = post.updated || post.date;
|
||||
return date > latest ? date : latest;
|
||||
}, new Date(0));
|
||||
const entries = posts.map((post) => {
|
||||
const url = escapeXml(absolute(post.href));
|
||||
return `<entry><title>${escapeXml(post.title)}</title><id>${url}</id><link href="${url}"/><published>${post.date.toISOString()}</published><updated>${(post.updated || post.date).toISOString()}</updated><summary>${escapeXml(post.summary)}</summary></entry>`;
|
||||
}).join('');
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>${escapeXml(siteConfig.site.name)}</title><id>${escapeXml(absolute('/'))}</id><link href="${escapeXml(absolute('/'))}"/><link rel="self" href="${escapeXml(absolute('/atom.xml'))}"/><updated>${updated.toISOString()}</updated><author><name>${escapeXml(siteConfig.author.name)}</name></author>${entries}</feed>`;
|
||||
return new Response(xml, { headers: { 'Content-Type': 'application/atom+xml; charset=utf-8' } });
|
||||
}
|
||||
Reference in new issue
Block a user