+27
-2
lines changedFilter options
+27
-2
lines changed Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@ const chokidar = require('chokidar')
10
10
const mount = st({
11
11
path: path.join(__dirname, 'build'),
12
12
cache: false,
13
-
index: 'index.html'
13
+
index: 'index.html',
14
+
passthrough: true
14
15
})
15
16
16
17
const build = require('./build')
@@ -34,6 +35,28 @@ const locales = chokidar.watch(path.join(__dirname, 'locale'), opts)
34
35
const layouts = chokidar.watch(path.join(__dirname, 'layouts'), opts)
35
36
const statics = chokidar.watch(path.join(__dirname, 'static'), opts)
36
37
38
+
// Redirect mechanism meant as a fix for languages where some pages
39
+
// has not translated yet, therefore redirect to the english equivalent,
40
+
// which ofc isn't the correct language, but better than a 404-page
41
+
function redirectToEnglishUrl (req, res) {
42
+
return () => {
43
+
const isAlreadyEnglish = req.url.startsWith('/en')
44
+
const urlContainsLanguage = req.url.split('/').length > 2
45
+
46
+
if (isAlreadyEnglish || !urlContainsLanguage) {
47
+
res.writeHead(404, 'Not found')
48
+
return res.end()
49
+
}
50
+
51
+
let englishUrl = req.url.replace(/^\/\w+\//, '/en/')
52
+
53
+
res.writeHead(302, {
54
+
location: englishUrl
55
+
})
56
+
res.end()
57
+
}
58
+
}
59
+
37
60
// Gets the locale name by path.
38
61
function getLocale (filePath) {
39
62
const pre = path.join(__dirname, 'locale')
@@ -65,7 +88,9 @@ statics.on('add', (filePath) => {
65
88
})
66
89
67
90
// Initializes the server and mounts it in the generated build directory.
68
-
http.createServer(mount).listen(port, () => console.log(`http://localhost:${port}/en/`))
91
+
http.createServer((req, res) => {
92
+
mount(req, res, redirectToEnglishUrl(req, res))
93
+
}).listen(port, () => console.log(`http://localhost:${port}/en/`))
69
94
70
95
// Start the initial build of static HTML pages
71
96
build.fullBuild()
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4