- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateLastPosts.js
More file actions
Latest commit
20 lines (17 loc) · 829 Bytes
/
Copy pathgenerateLastPosts.js
File metadata and controls
20 lines (17 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
constfs=require('fs');
constpath=require('path');
constpostsDir=path.join(__dirname,'_posts');
constlastPostsFile=path.join(__dirname,'lastposts.json');
// Lee archivos de la carpeta _posts y ordena por fecha
constposts=fs.readdirSync(postsDir)
.filter(file=>file.endsWith('.json'))
.map(file=>{
constfilePath=path.join(postsDir,file);
constcontent=JSON.parse(fs.readFileSync(filePath,'utf8'));
return{ ...content,filename: file};
})
.sort((a,b)=>newDate(b.date)-newDate(a.date))// Ordena por fecha, el más reciente primero
.slice(0,10);// Limita a los 10 posts más recientes
// Escribe el archivo lastposts.json
fs.writeFileSync(lastPostsFile,JSON.stringify(posts,null,2),'utf8');
console.log('lastposts.json generado exitosamente.');