crear todos los paths dinamicamente para cada idioma

This commit is contained in:
simio 2025-05-05 07:15:34 -03:00
parent 65c1fa23ee
commit 42e1a65b43
3 changed files with 14 additions and 4 deletions

View File

@ -6,6 +6,7 @@ const { dirname } = require('path');
const thisDirectory = dirname(require.main.filename);
const fs = require('fs');
const makeRss = require('../utils/rss');
const langs = ["es", "en"]
function addPaths(path, renderParams = {}){
let currentDefaultParams = {...renderParams}
@ -42,7 +43,6 @@ function addPaths(path, renderParams = {}){
}
else{
if (file === 'partials' || file === 'layouts') return
addPaths(path + file + '/', currentDefaultParams)
}
}
@ -85,7 +85,7 @@ router.get('/update_log/rss', async (_req, res) => {
rss.item({
title: "Update #" + i,
description: `${u.link && `<a href="${u.link}">`}${u.description}${u.link && `</a>`}`,
author: "Gor Down",
author: "Lyrical Tokarev",
date: u.date
})
})

View File

@ -1,6 +1,7 @@
const { dirname } = require('path');
const appDir = dirname(require.main.filename);
const fs = require('fs')
const langs = ["es", "en"]
function createCommonPath(router, path, renderParams = {
}, cb = () => {}){
@ -28,7 +29,16 @@ function createCommonPath(router, path, renderParams = {
...fileGeneralParams
}
}
router.get('/' + path, async (req, res) => {
renderOptions.lang = "es"
createPath('/' + path, cb, renderOptions, router)
langs.forEach(l => {
renderOptions.lang = l
createPath('/' + l + "/" + path, cb, renderOptions, router)
})
}
async function createPath(path, cb, renderOptions, router){
router.get(path, async (req, res) => {
const cb_params = await cb(req, res)
renderOptions = {...renderOptions, ...cb_params}
res.render(renderOptions.view, renderOptions)

View File

@ -16,7 +16,7 @@
<p>Blasonador: <a id="cidoku" href="http://cidoku.net">Cidoku</a></p>
</td>
<td valign="top">
<p>Armígero: <a href="http://lyricaltokarev.com"><span id="celeste">Gor Down</span></a></p>
<p>Armígero: <a href="http://lyricaltokarev.com"><span id="celeste">Lyrical Tokarev</span></a></p>
</td>
<td valign="top">
<p>Otorgado el: 9 de marzo, 2025</p>