basic dynamic sitemap implementation

This commit is contained in:
James Shiffer 2020-08-31 21:19:19 -07:00
parent 453daa9319
commit cd878c2b25
No known key found for this signature in database
GPG Key ID: C0DB8774A1B3BA45

29
src/routes/sitemap.txt.js Normal file
View File

@ -0,0 +1,29 @@
import Article from '../models/article.js';
import Category from '../models/category.js';
/**
* generates a simple .txt sitemap with all articles and categories.
*/
export async function get(req, res)
{
// include static, publicly visible pages here
let routes = [
'https://howfeed.biz/',
'https://howfeed.biz/contact',
'https://howfeed.biz/search',
];
const articles = await Article.find();
const categories = await Category.find();
for (let article of articles) {
routes.push(`https://howfeed.biz/a/${article.slug}`);
}
for (let category of categories) {
routes.push(`https://howfeed.biz/c/${category.slug}`);
}
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end(routes.join('\n'));
}