RSS генерирует HTML с миниатюрой и её альт-текстом
This commit is contained in:
parent
0edf7022e8
commit
84512c7a9b
1 changed files with 10 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { fetchPostsSorted } from "$src/lib/util/Blogs";
|
||||
import { fetchPostsSorted, resolveBlogPath } from "$src/lib/util/Blogs";
|
||||
|
||||
export const prerender = true;
|
||||
|
||||
|
|
@ -13,6 +13,14 @@ function escapeXml(unsafe: string): string {
|
|||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function makeThumbnail(post: App.BlogPost): string {
|
||||
if (!post.thumbnail) return '';
|
||||
|
||||
const alt = !!post.thumbnailAlt ? ` alt="${escapeXml(post.thumbnailAlt)}"` : '';
|
||||
|
||||
return `<br><br><img src="https://teasanctuary.ru${resolveBlogPath(post.slug, post.thumbnail)}"${alt}>`;
|
||||
}
|
||||
|
||||
export async function GET({ setHeaders }) {
|
||||
setHeaders({
|
||||
'Cache-Control': 'max-age=0, s-maxage=3600',
|
||||
|
|
@ -28,7 +36,7 @@ export async function GET({ setHeaders }) {
|
|||
<updated>${feedUpdated.toUTCString()}</updated>
|
||||
${posts.map((post) => `<item>
|
||||
<title>${escapeXml(post.title)}</title>
|
||||
<description>${escapeXml(post.description)}</description>
|
||||
<description><![CDATA[${escapeXml(post.description)}${makeThumbnail(post)}]]></description>
|
||||
<guid isPermaLink="true">https://teasanctuary.ru/blog/${post.slug}</guid>
|
||||
<link>https://teasanctuary.ru/blog/${post.slug}</link>
|
||||
<pubDate>${(new Date(post.date!)).toUTCString()}</pubDate>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue