From ff0e968907fd441e89e73f7ffdbc19ea34ed1891 Mon Sep 17 00:00:00 2001 From: Sky Date: Thu, 21 Nov 2024 13:52:12 +0800 Subject: [PATCH] Fix special keywords search redirecting Fix if you search a special keywords, search result page broken css --- src/routes.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/routes.js b/src/routes.js index a5de7cf..5f33fd2 100644 --- a/src/routes.js +++ b/src/routes.js @@ -88,7 +88,6 @@ module.exports = (app, utils) => { return handleWikiPage(req, res, '/wiki/') }) - // This route handles wiki-pages starting with forward slash (issue #21)) app.get('/wiki//:page?/:sub_page?', (req, res, next) => { const page = req.params.page if(page) { @@ -98,6 +97,18 @@ module.exports = (app, utils) => { return handleWikiPage(req, res, '/wiki/') }) + // Handle the search request and redirect to the correct wiki page + app.get('/w/index.php', (req, res, next) => { + const searchQuery = req.query.search + if (searchQuery) { + // Construct the URL to redirect to the proper wiki page + const lang = req.query.lang || req.cookies.default_lang || config.default_lang + const redirectUrl = `/wiki/${encodeURIComponent(searchQuery)}?lang=${lang}` + return res.redirect(redirectUrl) + } + return next() + }) + app.get('/w/:file', (req, res, next) => { return handleWikiPage(req, res, '/w/') }) @@ -132,10 +143,6 @@ module.exports = (app, utils) => { return handleWikiPage(req, res, '/') }) - app.get('Open in Wikipedia', (req, res, next) => { - return res.sendFile(path.join(__dirname, 'https://wikipedia.org/wiki/Wikipedia')) - }) - app.get('/about', (req, res, next) => { return res.sendFile(path.join(__dirname, '../static/about.html')) })