From 44ffc564da1dd20b2fae3247d9fa314a52e0aaca Mon Sep 17 00:00:00 2001 From: Claudius Date: Thu, 13 Sep 2018 21:26:39 +0200 Subject: [PATCH] removing global site layout vars from individual routers, putting them into app.local Signed-off-by: Claudius --- app.js | 23 ++++++++++ lib/response.js | 52 +---------------------- public/views/codimd/foot.ejs | 6 +-- public/views/codimd/head.ejs | 6 +-- public/views/codimd/header.ejs | 6 +-- public/views/error.ejs | 4 +- public/views/index/body.ejs | 30 +++++++------- public/views/index/head.ejs | 4 +- public/views/pretty.ejs | 12 +++--- public/views/shared/refresh-modal.ejs | 4 +- public/views/shared/signin-modal.ejs | 60 +++++++++++++-------------- public/views/slide.ejs | 24 +++++------ 12 files changed, 103 insertions(+), 128 deletions(-) diff --git a/app.js b/app.js index 46fd041c8..7795dd838 100644 --- a/app.js +++ b/app.js @@ -175,6 +175,29 @@ app.set('views', config.viewPath) app.engine('ejs', ejs.renderFile) // set view engine app.set('view engine', 'ejs') +// set generally available variables for all views +app.locals.useCDN = config.useCDN +app.locals.serverURL = config.serverURL +app.locals.allowAnonymous = config.allowAnonymous +app.locals.allowAnonymousEdits = config.allowAnonymousEdits +app.locals.allowPDFExport = config.allowPDFExport +app.locals.authProviders = { + facebook: config.isFacebookEnable, + twitter: config.isTwitterEnable, + github: config.isGitHubEnable, + gitlab: config.isGitLabEnable, + mattermost: config.isMattermostEnable, + dropbox: config.isDropboxEnable, + google: config.isGoogleEnable, + ldap: config.isLDAPEnable, + ldapProviderName: config.ldap.providerName, + saml: config.isSAMLEnable, + oauth2: config.isOAuth2Enable, + oauth2ProviderName: config.oauth2.providerName, + openID: config.isOpenIDEnable, + email: config.isEmailEnable, + allowEmailRegister: config.allowEmailRegister +} app.use(require('./lib/web/baseRouter')) app.use(require('./lib/web/statusRouter')) diff --git a/lib/response.js b/lib/response.js index 4f572e471..3cbd32039 100644 --- a/lib/response.js +++ b/lib/response.js @@ -55,12 +55,10 @@ var response = { function responseError (res, code, detail, msg) { res.status(code).render('error.ejs', { - url: config.serverURL, title: code + ' ' + detail + ' ' + msg, code: code, detail: detail, - msg: msg, - useCDN: config.useCDN + msg: msg }) } @@ -69,26 +67,6 @@ function showIndex (req, res, next) { var deleteToken = '' var data = { - url: config.serverURL, - useCDN: config.useCDN, - allowAnonymous: config.allowAnonymous, - allowAnonymousEdits: config.allowAnonymousEdits, - facebook: config.isFacebookEnable, - twitter: config.isTwitterEnable, - github: config.isGitHubEnable, - gitlab: config.isGitLabEnable, - mattermost: config.isMattermostEnable, - dropbox: config.isDropboxEnable, - google: config.isGoogleEnable, - ldap: config.isLDAPEnable, - ldapProviderName: config.ldap.providerName, - saml: config.isSAMLEnable, - oauth2: config.isOAuth2Enable, - oauth2ProviderName: config.oauth2.providerName, - email: config.isEmailEnable, - allowEmailRegister: config.allowEmailRegister, - allowPDFExport: config.allowPDFExport, - openID: config.isOpenIDEnable, signin: authStatus, infoMessage: req.flash('info'), errorMessage: req.flash('error'), @@ -124,27 +102,7 @@ function responseCodiMD (res, note) { 'X-Robots-Tag': 'noindex, nofollow' // prevent crawling }) res.render('codimd.ejs', { - url: config.serverURL, - title: title, - useCDN: config.useCDN, - allowAnonymous: config.allowAnonymous, - allowAnonymousEdits: config.allowAnonymousEdits, - facebook: config.isFacebookEnable, - twitter: config.isTwitterEnable, - github: config.isGitHubEnable, - gitlab: config.isGitLabEnable, - mattermost: config.isMattermostEnable, - dropbox: config.isDropboxEnable, - google: config.isGoogleEnable, - ldap: config.isLDAPEnable, - ldapProviderName: config.ldap.providerName, - oauth2ProviderName: config.oauth2.providerName, - saml: config.isSAMLEnable, - oauth2: config.isOAuth2Enable, - email: config.isEmailEnable, - allowEmailRegister: config.allowEmailRegister, - allowPDFExport: config.allowPDFExport, - openID: config.isOpenIDEnable + title: title }) } @@ -254,16 +212,13 @@ function showPublishNote (req, res, next) { var updatetime = note.lastchangeAt var title = models.Note.decodeTitle(note.title) title = models.Note.generateWebTitle(meta.title || title) - var origin = config.serverURL var data = { title: title, description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null), viewcount: note.viewcount, createtime: createtime, updatetime: updatetime, - url: origin, body: body, - useCDN: config.useCDN, owner: note.owner ? note.owner.id : null, ownerprofile: note.owner ? models.User.getProfile(note.owner) : null, lastchangeuser: note.lastchangeuser ? note.lastchangeuser.id : null, @@ -634,18 +589,15 @@ function showPublishSlide (req, res, next) { var updatetime = note.lastchangeAt var title = models.Note.decodeTitle(note.title) title = models.Note.generateWebTitle(meta.title || title) - var origin = config.serverURL var data = { title: title, description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null), viewcount: note.viewcount, createtime: createtime, updatetime: updatetime, - url: origin, body: markdown, theme: meta.slideOptions && utils.isRevealTheme(meta.slideOptions.theme), meta: JSON.stringify(extracted.meta), - useCDN: config.useCDN, owner: note.owner ? note.owner.id : null, ownerprofile: note.owner ? models.User.getProfile(note.owner) : null, lastchangeuser: note.lastchangeuser ? note.lastchangeuser.id : null, diff --git a/public/views/codimd/foot.ejs b/public/views/codimd/foot.ejs index 000ccb6da..9b1c68d66 100644 --- a/public/views/codimd/foot.ejs +++ b/public/views/codimd/foot.ejs @@ -1,4 +1,4 @@ - + <% if(useCDN) { %> @@ -21,7 +21,7 @@ <%- include ../build/index-scripts %> <% } else { %> - - + + <%- include ../build/index-pack-scripts %> <% } %> diff --git a/public/views/codimd/head.ejs b/public/views/codimd/head.ejs index 356ded6d2..afa89d132 100644 --- a/public/views/codimd/head.ejs +++ b/public/views/codimd/head.ejs @@ -5,8 +5,8 @@ <%= title %> - - + + <% if(useCDN) { %> @@ -16,6 +16,6 @@ <%- include ../build/index-header %> <%- include ../shared/polyfill %> <% } else { %> - + <%- include ../build/index-pack-header %> <% } %> diff --git a/public/views/codimd/header.ejs b/public/views/codimd/header.ejs index 1b5e42226..d8df33b8b 100644 --- a/public/views/codimd/header.ejs +++ b/public/views/codimd/header.ejs @@ -13,7 +13,7 @@ - CodiMD + CodiMD diff --git a/public/views/index/head.ejs b/public/views/index/head.ejs index fc10dfa00..7a601bdfc 100644 --- a/public/views/index/head.ejs +++ b/public/views/index/head.ejs @@ -7,8 +7,8 @@ CodiMD - <%= __('Collaborative markdown notes') %> - - + + <% if(useCDN) { %> diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs index a087be7fe..ff4dcc236 100644 --- a/public/views/pretty.ejs +++ b/public/views/pretty.ejs @@ -15,8 +15,8 @@ <% } %> <%= title %> - - + + <% if(useCDN) { %> @@ -25,7 +25,7 @@ <%- include build/pretty-header %> <%- include shared/polyfill %> <% } else { %> - + <%- include build/pretty-pack-header %> <% } %> @@ -71,7 +71,7 @@ - + <% if(useCDN) { %> @@ -90,8 +90,8 @@ <%- include build/pretty-scripts %> <% } else { %> - - + + <%- include build/pretty-pack-scripts %> <% } %> <%- include shared/ga %> diff --git a/public/views/shared/refresh-modal.ejs b/public/views/shared/refresh-modal.ejs index 645805454..2aa652aac 100644 --- a/public/views/shared/refresh-modal.ejs +++ b/public/views/shared/refresh-modal.ejs @@ -14,7 +14,7 @@ @@ -28,4 +28,4 @@ - \ No newline at end of file + diff --git a/public/views/shared/signin-modal.ejs b/public/views/shared/signin-modal.ejs index b413511c2..d46b8d548 100644 --- a/public/views/shared/signin-modal.ejs +++ b/public/views/shared/signin-modal.ejs @@ -8,56 +8,56 @@ - + <% if(useCDN) { %> @@ -106,8 +106,8 @@ <%- include build/slide-scripts %> <% } else { %> - - + + <%- include build/slide-pack-scripts %> <% } %>