Skip to content

Commit 31de1e7

Browse files
committed
chore: fix build and deploy with og
1 parent b566299 commit 31de1e7

File tree

4 files changed

+83
-14
lines changed

4 files changed

+83
-14
lines changed

generateContentRoutes.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const fs = require('fs').promises;
2+
const path = require('path');
3+
4+
const contentDir = path.join(process.cwd(), 'content');
5+
6+
async function walkDir(dir) {
7+
let filesList = [];
8+
const files = await fs.readdir(dir, { withFileTypes: true });
9+
for (const file of files) {
10+
const res = path.resolve(dir, file.name);
11+
if (file.isDirectory()) {
12+
filesList = filesList.concat(await walkDir(res));
13+
} else if (file.isFile() && path.extname(file.name).toLowerCase() === '.md' || path.extname(file.name) != 'yml') {
14+
filesList.push(res);
15+
}
16+
}
17+
return filesList;
18+
}
19+
20+
function filePathToRoute(filePath) {
21+
let route = filePath
22+
.replace(contentDir, '')
23+
.replace(/\.md$/, '')
24+
.replace(/\\/g, '/'); // Reemplazar backslashes con forward slashes para compatibilidad
25+
26+
// Manejar index.md
27+
if (route.endsWith('/index')) {
28+
route = route.replace('/index', '');
29+
}
30+
31+
// Manejar _dir.md (directorios)
32+
route = route.replace(/\/_([^/]+)/g, '');
33+
34+
// Eliminar números al inicio de los segmentos de la ruta
35+
route = route.split('/').map(segment => segment.replace(/^\d+\./, '')).join('/');
36+
37+
// Asegurarse de que la ruta comience con '/'
38+
if (!route.startsWith('/')) {
39+
route = '/' + route;
40+
}
41+
42+
return route || '/';
43+
}
44+
45+
async function generateContentRoutes() {
46+
const filePaths = await walkDir(contentDir);
47+
const routes = filePaths.map(filePath => filePathToRoute(filePath));
48+
return routes;
49+
}
50+
51+
generateContentRoutes()
52+
.then(routes => {
53+
console.log('Content Routes:');
54+
console.log(JSON.stringify(routes, null, 2));
55+
})
56+
.catch(error => {
57+
console.error('Error generating routes:', error);
58+
});
59+
60+
module.exports = generateContentRoutes;

nuxt.config.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const generateContentRoutes = require('./generateContentRoutes');
2+
13
// https://nuxt.com/docs/api/configuration/nuxt-config
24
export default defineNuxtConfig({
35
devtools: { enabled: true },
@@ -11,10 +13,7 @@ export default defineNuxtConfig({
1113
ogImage: { enabled: false },
1214
nitro: {
1315
prerender: {
14-
// crawlLinks: true,
15-
// concurrency: 250,
16-
// interval: 100,
17-
routes: ['/sitemap.xml']
16+
routes: ['/sitemap.xml'],
1817
}
1918
},
2019
app: {
@@ -40,4 +39,13 @@ export default defineNuxtConfig({
4039
}
4140
},
4241
},
42+
hooks: {
43+
async 'prerender:routes'(ctx) {
44+
const contentRoutes = await generateContentRoutes();
45+
46+
for (const route of contentRoutes) {
47+
ctx.routes.add(route)
48+
}
49+
}
50+
}
4351
})

pages/[...slug].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<HeroSection />
44
<Roadmap />
55
<Teleport to="body">
6-
<div v-if="content" :class="['fixed top-0 h-screen', sidebarClass]">
6+
<div v-if="content" :class="['fixed top-0 h-screen z-10', sidebarClass]">
77
<div
88
id="sidebar"
99
class="scroll-smooth prose dark:prose-invert max-w-full flex overflow-y-auto overflow-x-hidden h-full w-full flex-col items-center p-4 focus:outline-0 sm:p-6 bg-orange-50 dark:bg-[#131313]/90 border-l-2 dark:backdrop-blur-xl border-black dark:border-0"

server/routes/sitemap.xml.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ import { SitemapStream, streamToPromise } from 'sitemap'
33

44
export default defineEventHandler(async (event) => {
55
// Fetch all documents
6-
const docs = await serverQueryContent(event).find()
7-
const sitemap = new SitemapStream()
6+
const articles = await serverQueryContent(event).find()
7+
const sitemap = new SitemapStream({ hostname: 'https://roadmap.rustlang-es.org/' })
88

9-
for (const doc of docs) {
10-
sitemap.write({
11-
url: doc._path,
12-
changefreq: 'monthly'
13-
})
14-
}
9+
console.log(articles)
10+
11+
articles.forEach(article => sitemap.write({ url: article._path, img: [ {
12+
url: `https://roadmap.rustlang-es.org/previews/${article._path.substring(1).replaceAll('/', "-")}.png`,
13+
caption: article.description,
14+
title: article.title,
15+
}, ] }))
1516
sitemap.end()
1617

17-
return streamToPromise(sitemap)
18+
return (await streamToPromise(sitemap))
1819
})

0 commit comments

Comments
 (0)