17e4c776c1
* Place redesign pages on seperate urls with redirects, refactor into StaticPageController * Add page titles to variant pages (#16710) * Add features-page-view event (#14911) * Add canonical URLs to variant marketing pages GitOrigin-RevId: 3f65f53d856a063dde1e9d60fd3cc327437294f6
121 lines
3.6 KiB
JavaScript
121 lines
3.6 KiB
JavaScript
/* eslint-disable
|
|
n/handle-callback-err,
|
|
max-len,
|
|
no-unused-vars,
|
|
n/no-deprecated-api,
|
|
*/
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
// Fix any style issues and re-enable lint.
|
|
/*
|
|
* decaffeinate suggestions:
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
* DS207: Consider shorter variations of null checks
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
let HomeController
|
|
const Features = require('../../infrastructure/Features')
|
|
const AnalyticsManager = require('../Analytics/AnalyticsManager')
|
|
|
|
const Path = require('path')
|
|
const fs = require('fs')
|
|
|
|
const ErrorController = require('../Errors/ErrorController')
|
|
const SessionManager = require('../Authentication/SessionManager')
|
|
|
|
const SplitTestHandler = require('../SplitTests/SplitTestHandler')
|
|
const logger = require('@overleaf/logger')
|
|
|
|
const homepageExists = fs.existsSync(
|
|
Path.join(__dirname, '/../../../views/external/home/v2.pug')
|
|
)
|
|
|
|
module.exports = HomeController = {
|
|
index(req, res) {
|
|
if (SessionManager.isUserLoggedIn(req.session)) {
|
|
if (req.query.scribtex_path != null) {
|
|
return res.redirect(`/project?scribtex_path=${req.query.scribtex_path}`)
|
|
} else {
|
|
return res.redirect('/project')
|
|
}
|
|
} else {
|
|
return HomeController.home(req, res)
|
|
}
|
|
},
|
|
|
|
async home(req, res) {
|
|
if (Features.hasFeature('homepage') && homepageExists) {
|
|
const websiteRedesignVariant =
|
|
res.locals.splitTestVariants?.['website-redesign']
|
|
const websiteRedesignActive =
|
|
websiteRedesignVariant === 'new-design' ||
|
|
websiteRedesignVariant === 'new-design-registration'
|
|
|
|
if (websiteRedesignActive) {
|
|
return res.redirect(302, '/home-2')
|
|
}
|
|
|
|
const onboardingFlowAssignment =
|
|
await SplitTestHandler.promises.getAssignment(
|
|
req,
|
|
res,
|
|
'onboarding-flow'
|
|
)
|
|
AnalyticsManager.recordEventForSession(req.session, 'home-page-view', {
|
|
page: req.path,
|
|
'website-redesign': websiteRedesignVariant,
|
|
})
|
|
|
|
return res.render('external/home/v2', {
|
|
onboardingFlowVariant: onboardingFlowAssignment.variant,
|
|
hideNewsletterCheckbox:
|
|
onboardingFlowAssignment.variant === 'token-confirmation-odc',
|
|
})
|
|
} else {
|
|
return res.redirect('/login')
|
|
}
|
|
},
|
|
|
|
async homeNew(req, res) {
|
|
if (Features.hasFeature('homepage') && homepageExists) {
|
|
const websiteRedesignVariant =
|
|
res.locals.splitTestVariants?.['website-redesign']
|
|
|
|
const onboardingFlowAssignment =
|
|
await SplitTestHandler.promises.getAssignment(
|
|
req,
|
|
res,
|
|
'onboarding-flow'
|
|
)
|
|
AnalyticsManager.recordEventForSession(req.session, 'home-page-view', {
|
|
page: req.path,
|
|
'website-redesign': websiteRedesignVariant,
|
|
})
|
|
|
|
return res.render('external/home/website-redesign/index', {
|
|
onboardingFlowVariant: onboardingFlowAssignment.variant,
|
|
hideNewsletterCheckbox:
|
|
onboardingFlowAssignment.variant === 'token-confirmation-odc',
|
|
})
|
|
} else {
|
|
return res.redirect('/login')
|
|
}
|
|
},
|
|
|
|
externalPage(page, title) {
|
|
return function (req, res, next) {
|
|
if (next == null) {
|
|
next = function () {}
|
|
}
|
|
const path = Path.join(__dirname, `/../../../views/external/${page}.pug`)
|
|
return fs.exists(path, function (exists) {
|
|
// No error in this callback - old method in Node.js!
|
|
if (exists) {
|
|
return res.render(`external/${page}.pug`, { title })
|
|
} else {
|
|
return ErrorController.notFound(req, res, next)
|
|
}
|
|
})
|
|
}
|
|
},
|
|
}
|