From 403e98dced86103cce59583a357865d1ea59ea70 Mon Sep 17 00:00:00 2001 From: Nicolas Giard Date: Sun, 2 Feb 2025 16:16:52 -0500 Subject: [PATCH] feat: add git always namespace option --- server/modules/storage/git/definition.yml | 6 ++++++ server/modules/storage/git/storage.js | 14 +++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/server/modules/storage/git/definition.yml b/server/modules/storage/git/definition.yml index 63c095a2..bea279ed 100644 --- a/server/modules/storage/git/definition.yml +++ b/server/modules/storage/git/definition.yml @@ -87,6 +87,12 @@ props: default: './data/repo' hint: 'Path where the local git repository will be created.' order: 30 + alwaysNamespace: + type: Boolean + title: Always Locale Namespace + default: false + hint: 'Whether to put content from the primary language into a subfolder.' + order: 40 gitBinaryPath: type: String title: Git Binary Path diff --git a/server/modules/storage/git/storage.js b/server/modules/storage/git/storage.js index 62401b0d..fcb197bc 100644 --- a/server/modules/storage/git/storage.js +++ b/server/modules/storage/git/storage.js @@ -298,7 +298,7 @@ module.exports = { async created(page) { WIKI.logger.info(`(STORAGE/GIT) Committing new file [${page.localeCode}] ${page.path}...`) let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}` - if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) { + if (this.config.alwaysNamespace || (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode)) { fileName = `${page.localeCode}/${fileName}` } const filePath = path.join(this.repoPath, fileName) @@ -320,7 +320,7 @@ module.exports = { async updated(page) { WIKI.logger.info(`(STORAGE/GIT) Committing updated file [${page.localeCode}] ${page.path}...`) let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}` - if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) { + if (this.config.alwaysNamespace || (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode)) { fileName = `${page.localeCode}/${fileName}` } const filePath = path.join(this.repoPath, fileName) @@ -342,7 +342,7 @@ module.exports = { async deleted(page) { WIKI.logger.info(`(STORAGE/GIT) Committing removed file [${page.localeCode}] ${page.path}...`) let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}` - if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) { + if (this.config.alwaysNamespace || (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode)) { fileName = `${page.localeCode}/${fileName}` } @@ -364,11 +364,11 @@ module.exports = { let sourceFileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}` let destinationFileName = `${page.destinationPath}.${pageHelper.getFileExtension(page.contentType)}` - if (WIKI.config.lang.namespacing) { - if (WIKI.config.lang.code !== page.localeCode) { + if (this.config.alwaysNamespace || WIKI.config.lang.namespacing) { + if (this.config.alwaysNamespace || WIKI.config.lang.code !== page.localeCode) { sourceFileName = `${page.localeCode}/${sourceFileName}` } - if (WIKI.config.lang.code !== page.destinationLocaleCode) { + if (this.config.alwaysNamespace || WIKI.config.lang.code !== page.destinationLocaleCode) { destinationFileName = `${page.destinationLocaleCode}/${destinationFileName}` } } @@ -483,7 +483,7 @@ module.exports = { page.tags = await pageObject.$relatedQuery('tags') let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}` - if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) { + if (this.config.alwaysNamespace || (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode)) { fileName = `${page.localeCode}/${fileName}` } WIKI.logger.info(`(STORAGE/GIT) Adding page ${fileName}...`)