seperated url and title + escape
This commit is contained in:
@@ -3,6 +3,7 @@ import type { APIRoute } from 'astro';
|
||||
interface PostInfo {
|
||||
slug: string;
|
||||
date: string;
|
||||
title?: string;
|
||||
summary?: string;
|
||||
excerpt?: string;
|
||||
tags: string[];
|
||||
@@ -14,8 +15,12 @@ interface SiteConfig {
|
||||
subtitle: string;
|
||||
}
|
||||
|
||||
// Strip C0/DEL control chars that are illegal in XML 1.0 (allow tab, LF, CR).
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const XML_INVALID = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g;
|
||||
|
||||
function escapeXml(s: string): string {
|
||||
return s.replace(/[<>&'"]/g, c => ({
|
||||
return s.replace(XML_INVALID, '').replace(/[<>&'"]/g, c => ({
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'&': '&',
|
||||
@@ -56,7 +61,7 @@ export const GET: APIRoute = async ({ site }) => {
|
||||
const pubDate = new Date(p.date).toUTCString();
|
||||
const categories = p.tags.map(t => ` <category>${escapeXml(t)}</category>`).join('\n');
|
||||
return ` <item>
|
||||
<title>${escapeXml(formatSlug(p.slug))}</title>
|
||||
<title>${escapeXml(p.title || formatSlug(p.slug))}</title>
|
||||
<link>${escapeXml(url)}</link>
|
||||
<guid isPermaLink="true">${escapeXml(url)}</guid>
|
||||
<pubDate>${pubDate}</pubDate>
|
||||
|
||||
Reference in New Issue
Block a user