mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Make Template Gallery optional; rename environment variables
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import Settings from '@overleaf/settings'
|
||||
import TemplateGalleryRouter from './app/src/TemplateGalleryRouter.mjs'
|
||||
const TemplateGalleryModule = {
|
||||
router: TemplateGalleryRouter,
|
||||
}
|
||||
|
||||
function boolFromEnv(env) {
|
||||
if (env === undefined || env === null) return undefined
|
||||
@@ -11,23 +8,35 @@ function boolFromEnv(env) {
|
||||
if (envLower === 'true') return true
|
||||
if (envLower === 'false') return false
|
||||
}
|
||||
throw new Error("Invalid value for boolean envirionment variable")
|
||||
throw new Error("Invalid value for boolean environment variable")
|
||||
}
|
||||
|
||||
Settings.templates = {
|
||||
nonAdminCanManage: boolFromEnv(process.env.OVERLEAF_NON_ADMIN_CAN_MANAGE_TEMPLATES)
|
||||
}
|
||||
let TemplateGalleryModule = {}
|
||||
|
||||
Settings.templateLinks = (`${process.env.OVERLEAF_TEMPLATE_KEYS} all`).split(/\s+/).map(key => {
|
||||
const envKeyBase = key.toUpperCase().replace(/-/g, "_")
|
||||
const name = process.env[`TEMPLATE_${envKeyBase}_NAME`]
|
||||
const description = process.env[`TEMPLATE_${envKeyBase}_DESCRIPTION`]
|
||||
|
||||
return {
|
||||
name: name || key,
|
||||
url: `/templates/${key}`,
|
||||
description: description || "Templates category"
|
||||
if (process.env.OVERLEAF_TEMPLATE_GALLERY === 'true') {
|
||||
TemplateGalleryModule = {
|
||||
router: TemplateGalleryRouter,
|
||||
}
|
||||
})
|
||||
|
||||
Settings.templates = {
|
||||
nonAdminCanManage: boolFromEnv(process.env.OVERLEAF_NON_ADMIN_CAN_PUBLISH_TEMPLATES)
|
||||
}
|
||||
|
||||
const templateKeys = process.env.OVERLEAF_TEMPLATE_CATEGORIES
|
||||
? process.env.OVERLEAF_TEMPLATE_CATEGORIES + ' all'
|
||||
: 'all'
|
||||
|
||||
Settings.templateLinks = templateKeys.split(/\s+/).map(key => {
|
||||
const envKeyBase = key.toUpperCase().replace(/-/g, "_")
|
||||
const name = process.env[`TEMPLATE_${envKeyBase}_NAME`] || ( key === 'all' ? 'All templates' : key)
|
||||
const description = process.env[`TEMPLATE_${envKeyBase}_DESCRIPTION`] || ''
|
||||
|
||||
return {
|
||||
name,
|
||||
url: `/templates/${key}`,
|
||||
description
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default TemplateGalleryModule
|
||||
|
||||
Reference in New Issue
Block a user