Skip to content

Commit accab1c

Browse files
author
Invers3
committed
Update app
Testing post
1 parent ab94e55 commit accab1c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

generateLastPosts.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const postsDir = path.join(__dirname, '_posts');
5+
const lastPostsFile = path.join(__dirname, 'lastposts.json');
6+
7+
// Lee archivos de la carpeta _posts y ordena por fecha
8+
const posts = fs.readdirSync(postsDir)
9+
.filter(file => file.endsWith('.json'))
10+
.map(file => {
11+
const filePath = path.join(postsDir, file);
12+
const content = JSON.parse(fs.readFileSync(filePath, 'utf8'));
13+
return { ...content, filename: file };
14+
})
15+
.sort((a, b) => new Date(b.date) - new Date(a.date)) // Ordena por fecha, el más reciente primero
16+
.slice(0, 10); // Limita a los 10 posts más recientes
17+
18+
// Escribe el archivo lastposts.json
19+
fs.writeFileSync(lastPostsFile, JSON.stringify(posts, null, 2), 'utf8');
20+
console.log('lastposts.json generado exitosamente.');

0 commit comments

Comments
 (0)