Make Template Gallery optional; rename environment variables

This commit is contained in:
yu-i-i
2026-07-07 14:42:51 +02:00
parent 8dc220fdc5
commit 6b3472e3a8
8 changed files with 61 additions and 40 deletions
+26 -17
View File
@@ -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