+ feed script
This commit is contained in:
1 parent
29a9383756
commit
0a7a9587fc
4 files changed
+73
-10
No files matched your search
@@ -0,0 +1,43 @@
|
||||
const { Feed } = require('feed')
|
||||
const axios = require('axios')
|
||||
const fs = require('fs').promises
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: 'http://localhost:3000',
|
||||
})
|
||||
|
||||
async function getArticles(pageSize) {
|
||||
const page = 1
|
||||
const res = await api.get(`/api/articles?page=${page}&pageSize=${pageSize}`)
|
||||
|
||||
return res.data.items
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const articles = await getArticles(30)
|
||||
|
||||
const url = 'https://art.shlisselburg.org'
|
||||
const feed = new Feed({
|
||||
title: 'Шлиссельбургская ДХШ',
|
||||
id: url,
|
||||
link: url,
|
||||
feedLinks: {
|
||||
atom: 'https://art.shlisselburg.org/feed.xml',
|
||||
},
|
||||
});
|
||||
|
||||
articles.forEach(article => {
|
||||
feed.addItem({
|
||||
title: article.title,
|
||||
date: new Date(article.date),
|
||||
id: article.id,
|
||||
link: article.url,
|
||||
content: article.post,
|
||||
})
|
||||
})
|
||||
|
||||
const content = feed.atom1()
|
||||
|
||||
await fs.writeFile('dist/feed.xml', content, { encoding: 'utf-8' })
|
||||
})()
|
||||
|
||||
Reference in new issue
Block a user