Skip to content

Commit ff0e968

Browse files
authored
Fix special keywords search redirecting
Fix if you search a special keywords, search result page broken css
1 parent 9315353 commit ff0e968

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/routes.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ module.exports = (app, utils) => {
8888
return handleWikiPage(req, res, '/wiki/')
8989
})
9090

91-
// This route handles wiki-pages starting with forward slash (issue #21))
9291
app.get('/wiki//:page?/:sub_page?', (req, res, next) => {
9392
const page = req.params.page
9493
if(page) {
@@ -98,6 +97,18 @@ module.exports = (app, utils) => {
9897
return handleWikiPage(req, res, '/wiki/')
9998
})
10099

100+
// Handle the search request and redirect to the correct wiki page
101+
app.get('/w/index.php', (req, res, next) => {
102+
const searchQuery = req.query.search
103+
if (searchQuery) {
104+
// Construct the URL to redirect to the proper wiki page
105+
const lang = req.query.lang || req.cookies.default_lang || config.default_lang
106+
const redirectUrl = `/wiki/${encodeURIComponent(searchQuery)}?lang=${lang}`
107+
return res.redirect(redirectUrl)
108+
}
109+
return next()
110+
})
111+
101112
app.get('/w/:file', (req, res, next) => {
102113
return handleWikiPage(req, res, '/w/')
103114
})
@@ -132,10 +143,6 @@ module.exports = (app, utils) => {
132143
return handleWikiPage(req, res, '/')
133144
})
134145

135-
app.get('Open in Wikipedia', (req, res, next) => {
136-
return res.sendFile(path.join(__dirname, 'https://wikipedia.org/wiki/Wikipedia'))
137-
})
138-
139146
app.get('/about', (req, res, next) => {
140147
return res.sendFile(path.join(__dirname, '../static/about.html'))
141148
})

0 commit comments

Comments
 (0)