diff --git a/index.js b/index.js
index a501a96..d336c88 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,6 @@
+global.langs = ["en", "es"]
+global.default_lang = "es"
+
const express = require('express')
const webserver = express()
const port = 3003
diff --git a/src/router/common_path_logic/update_log/rss.js b/src/router/common_path_logic/update_log/rss.js
new file mode 100644
index 0000000..e69de29
diff --git a/src/router/indexRouter.js b/src/router/indexRouter.js
index 84c64ef..66194fe 100644
--- a/src/router/indexRouter.js
+++ b/src/router/indexRouter.js
@@ -48,24 +48,32 @@ function addPaths(path, renderParams = {}){
)
}
-
-router.get('/', (_req, res) => {
- //...
- // res.redirect('/public/pages/neocities-lyricaltokarev/index.html')
- res.redirect('/home')
+router.use('/:lang?/', (req, res, next) => {
+ if (req.params.lang == global.default_lang) {
+ const pathWithoutLang = req.originalUrl.replace(`/${global.default_lang}`, '');
+ return res.redirect(pathWithoutLang);
+ }
+ const lang = req.params.lang ? req.params.lang : global.default_lang
+ if(lang !== global.default_lang && global.langs.includes(lang)){
+ req.body.langPath = '/' + lang + '/'
+ }else{
+ req.body.langPath = '/'
+ }
+ next()
})
-
const recent_posters = []
-router.post('/comment', (req, res) => {
+
+router.post('/:lang?/comment', (req, res) => {
+ const redirect_path = req.body.langPath + "home#visitor_table"
if (req.body.checkbox === "on"){
- return res.redirect('/home#visitor_table')
+ return res.redirect(redirect_path)
}
const ip = req.header('x-forwarded-for') || req.connection.remoteAddress;
if(recent_posters.some( poster => poster.ip === ip)){
console.log("spammer, " + ip)
- return res.redirect('/home#visitor_table')
+ return res.redirect(redirect_path)
}
recent_posters.push({
ip,
@@ -74,10 +82,10 @@ router.post('/comment', (req, res) => {
const comment = req.body.comment.replace(/"/g, '""');
fs.appendFileSync(thisDirectory + "/public/dynamic/sync/comments.csv", `${Date.now()},"${comment}",,0` + "\n")
- res.redirect('/home#visitor_table')
+ res.redirect(redirect_path)
})
-router.get('/update_log/rss', async (_req, res) => {
+router.get('/:lang?/update_log/rss', async (_req, res) => {
const csvData = await readCsv(thisDirectory + '/public/dynamic/sync/updates.csv')
const rss = makeRss('https://lyricaltokarev.com/update_log/rss', "Update Log")
csvData.forEach((u, i) => {
@@ -105,10 +113,12 @@ setInterval(() => {
}, 1000)
-
-
-
addPaths(thisDirectory + '/views/')
+router.get('/:lang?', (req, res) => {
+ res.redirect(req.body.langPath + 'home')
+})
+
+
module.exports = router;
diff --git a/src/utils/createCommonPath.js b/src/utils/createCommonPath.js
index 3a693dd..a418794 100644
--- a/src/utils/createCommonPath.js
+++ b/src/utils/createCommonPath.js
@@ -1,8 +1,7 @@
const { dirname } = require('path');
const appDir = dirname(require.main.filename);
const fs = require('fs')
-const langs = ["en", "es", "jp"]
-const default_lang = "es"
+const {langs, default_lang} = global
function createCommonPath(router, path, renderParams = {
}, cb = () => {}){
diff --git a/views/home.hbs b/views/home.hbs
index 89e1190..916d2c9 100644
--- a/views/home.hbs
+++ b/views/home.hbs
@@ -216,7 +216,7 @@