mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 21:31:41 +00:00
wiki will try and get spanish version of page then fall back to english if it is not there
This commit is contained in:
parent
e0aae65050
commit
aeb956c8a4
1 changed files with 35 additions and 14 deletions
|
@ -2,30 +2,37 @@ request = require("request")
|
|||
settings = require("settings-sharelatex")
|
||||
logger = require("logger-sharelatex")
|
||||
ErrorController = require "../Errors/ErrorController"
|
||||
_ = require("underscore")
|
||||
|
||||
other_lngs = ["es"]
|
||||
|
||||
module.exports = WikiController =
|
||||
getPage: (req, res, next) ->
|
||||
|
||||
page = req.url.replace(/^\/learn/, "").replace(/^\//, "")
|
||||
if page == ""
|
||||
page = "Main_Page"
|
||||
|
||||
logger.log page: page, "getting page from wiki"
|
||||
|
||||
if _.include(other_lngs, req.lng)
|
||||
lngPage = "#{page}_#{req.lng}"
|
||||
else
|
||||
lngPage = page
|
||||
|
||||
WikiController._getPageContent "Contents", (error, contents) ->
|
||||
return next(error) if error?
|
||||
WikiController._getPageContent page, (error, page) ->
|
||||
WikiController._getPageContent lngPage, (error, pageData) ->
|
||||
return next(error) if error?
|
||||
if page.title == "Main Page"
|
||||
title = "Documentation"
|
||||
if pageData.content?.length > 280
|
||||
WikiController._renderPage(pageData, contents, res)
|
||||
else
|
||||
title = page.title
|
||||
|
||||
res.render "wiki/page", {
|
||||
page: page
|
||||
contents: contents
|
||||
title: title
|
||||
}
|
||||
|
||||
WikiController._getPageContent page, (error, pageData) ->
|
||||
return next(error) if error?
|
||||
WikiController._renderPage(pageData, contents, res)
|
||||
|
||||
|
||||
|
||||
|
||||
_getPageContent: (page, callback = (error, data = { content: "", title: "" }) ->) ->
|
||||
request {
|
||||
url: "#{settings.apis.wiki.url}/learn-scripts/api.php"
|
||||
|
@ -40,7 +47,21 @@ module.exports = WikiController =
|
|||
data = JSON.parse(data)
|
||||
catch err
|
||||
logger.err err:err, data:data, "error parsing data from wiki"
|
||||
callback null, {
|
||||
result =
|
||||
content: data?.parse?.text?['*']
|
||||
title: data?.parse?.title
|
||||
}
|
||||
|
||||
callback null, result
|
||||
|
||||
|
||||
_renderPage: (page, contents, res)->
|
||||
if page.title == "Main Page"
|
||||
title = "Documentation"
|
||||
else
|
||||
title = page.title
|
||||
|
||||
res.render "wiki/page", {
|
||||
page: page
|
||||
contents: contents
|
||||
title: title
|
||||
}
|
Loading…
Reference in a new issue