/
githubmirror
/
30-seconds-of-code
Обзор
Документация
Войти
/
githubmirror
/
30-seconds-of-code
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/lib/feed.js
54 строки
1 KB
Angelos Chalaris
Fix broken RSS feed
12 май 2025, 21:09
Не верифицирован
12 май 2025, 21:09
5310417
Код
Авторство
О чём код?
import fs from 'fs'; import Snippet from '#src/models/snippet.js'; import StringUtils from '#src/lib/stringUtils.js'; import settings from '#src/config/settings.js'; export default class Feed { static generate() { const { name, description, url } = settings.website; const data = `\ <rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" version="2.0" > <channel> <title>${name}</title> <description>${description}</description> <link>${url}</link> <language>en-us</language> <image> <url>${url}/assets/logo.png</url> <title>${name}</title> <link>${url}</link> </image> <ttl>1440</ttl> <atom:link href="${url}/feed.xml" rel="self" type="application/rss+xml" /> ${Feed.nodes.join('\n')} </channel> </rss>`; // Write to file fs.writeFileSync(settings.paths.out.feed, data); } static get nodes() { return Snippet.scope('published', 'listed', 'byNew') .slice(0, 50) .map( snippet => `\ <item> <title>${StringUtils.escapeHtml(snippet.title)}</title> <link>${snippet.fullUrl}</link> <description>${StringUtils.escapeHtml( snippet.seoDescription )}</description> <pubDate>${new Date(snippet.dateModified).toUTCString()}</pubDate> </item>` ); } }