mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05: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,29 +2,36 @@ request = require("request")
|
||||||
settings = require("settings-sharelatex")
|
settings = require("settings-sharelatex")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
ErrorController = require "../Errors/ErrorController"
|
ErrorController = require "../Errors/ErrorController"
|
||||||
|
_ = require("underscore")
|
||||||
|
|
||||||
|
other_lngs = ["es"]
|
||||||
|
|
||||||
module.exports = WikiController =
|
module.exports = WikiController =
|
||||||
getPage: (req, res, next) ->
|
getPage: (req, res, next) ->
|
||||||
|
|
||||||
page = req.url.replace(/^\/learn/, "").replace(/^\//, "")
|
page = req.url.replace(/^\/learn/, "").replace(/^\//, "")
|
||||||
if page == ""
|
if page == ""
|
||||||
page = "Main_Page"
|
page = "Main_Page"
|
||||||
|
|
||||||
logger.log page: page, "getting page from wiki"
|
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) ->
|
WikiController._getPageContent "Contents", (error, contents) ->
|
||||||
return next(error) if error?
|
return next(error) if error?
|
||||||
WikiController._getPageContent page, (error, page) ->
|
WikiController._getPageContent lngPage, (error, pageData) ->
|
||||||
return next(error) if error?
|
return next(error) if error?
|
||||||
if page.title == "Main Page"
|
if pageData.content?.length > 280
|
||||||
title = "Documentation"
|
WikiController._renderPage(pageData, contents, res)
|
||||||
else
|
else
|
||||||
title = page.title
|
WikiController._getPageContent page, (error, pageData) ->
|
||||||
|
return next(error) if error?
|
||||||
|
WikiController._renderPage(pageData, contents, res)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
res.render "wiki/page", {
|
|
||||||
page: page
|
|
||||||
contents: contents
|
|
||||||
title: title
|
|
||||||
}
|
|
||||||
|
|
||||||
_getPageContent: (page, callback = (error, data = { content: "", title: "" }) ->) ->
|
_getPageContent: (page, callback = (error, data = { content: "", title: "" }) ->) ->
|
||||||
request {
|
request {
|
||||||
|
@ -40,7 +47,21 @@ module.exports = WikiController =
|
||||||
data = JSON.parse(data)
|
data = JSON.parse(data)
|
||||||
catch err
|
catch err
|
||||||
logger.err err:err, data:data, "error parsing data from wiki"
|
logger.err err:err, data:data, "error parsing data from wiki"
|
||||||
callback null, {
|
result =
|
||||||
content: data?.parse?.text?['*']
|
content: data?.parse?.text?['*']
|
||||||
title: data?.parse?.title
|
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