fix: make feeds contain the 5 most recent posts
This commit is contained in:
parent
e1ae6da34e
commit
6283dd4486
10
gulpfile.js
10
gulpfile.js
|
@ -404,6 +404,8 @@ function createFeeds() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const posts = fs.readdirSync(path.join(paths.out, 'posts'));
|
const posts = fs.readdirSync(path.join(paths.out, 'posts'));
|
||||||
|
// Remove the template, that doesn't need to be included
|
||||||
|
posts.splice(posts.indexOf('template.html'), 1);
|
||||||
// Sort the posts descending year and month
|
// Sort the posts descending year and month
|
||||||
posts.sort((a, b) => {
|
posts.sort((a, b) => {
|
||||||
const yearA = Number(a.replace(/\D/g, ''));
|
const yearA = Number(a.replace(/\D/g, ''));
|
||||||
|
@ -416,12 +418,8 @@ function createFeeds() {
|
||||||
|
|
||||||
return yearB - yearA;
|
return yearB - yearA;
|
||||||
});
|
});
|
||||||
for (const post of posts) {
|
for (let i = 0; i < 5; i++) {
|
||||||
// Skip the template, that doesn't need to be included
|
const post = posts[i];
|
||||||
if (post.includes('template')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const html = fs.readFileSync(path.join(paths.out, 'posts', post), 'UTF8');
|
const html = fs.readFileSync(path.join(paths.out, 'posts', post), 'UTF8');
|
||||||
const $ = cheerio.load(html);
|
const $ = cheerio.load(html);
|
||||||
const title = $('#wrapper>h1').text();
|
const title = $('#wrapper>h1').text();
|
||||||
|
|
Reference in New Issue