-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #998 from dbauszus-glx/nonlanguage-templates
Get nonlanguage [view] templates
- Loading branch information
Showing
2 changed files
with
32 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
const getFrom = require('../provider/getFrom') | ||
|
||
const getTemplate = require('../workspace/getTemplate') | ||
|
||
const workspaceCache = require('../workspace/cache') | ||
|
||
module.exports = async (params) => { | ||
|
||
if (params.template === undefined) return; | ||
if (params.template === undefined) return; | ||
|
||
// Set english as default template language. | ||
params.language ??= 'en' | ||
|
||
const workspace = await workspaceCache() | ||
|
||
if (!Object.hasOwn(workspace.templates, params.template)) { | ||
|
||
// Set english as default template language. | ||
params.language ??= 'en' | ||
console.warn(`Template ${params.template} not found.`) | ||
return params.template; | ||
} | ||
|
||
const workspace = await workspaceCache() | ||
// NOT a language template | ||
if (workspace.templates[params.template].src) { | ||
|
||
if (!Object.hasOwn(workspace.templates, params.template)) { | ||
const nonLanguage = await getTemplate(workspace.templates[params.template]) | ||
|
||
console.warn(`Template ${params.template} not found.`) | ||
return params.template; | ||
} | ||
return nonLanguage.template | ||
} | ||
|
||
const allLanguages = workspace.templates[params.template] | ||
const allLanguages = workspace.templates[params.template] | ||
|
||
let template = Object.hasOwn(allLanguages, params.language)? allLanguages[params.language]: allLanguages.en; | ||
let template = Object.hasOwn(allLanguages, params.language) | ||
? allLanguages[params.language] | ||
: allLanguages.en; | ||
|
||
if (typeof template === 'string' && Object.hasOwn(getFrom, template.split(':')[0])) { | ||
if (typeof template === 'string' && Object.hasOwn(getFrom, template.split(':')[0])) { | ||
|
||
// Get template from method. | ||
template = await getFrom[template.split(':')[0]](template) | ||
} | ||
// Get template from method. | ||
template = await getFrom[template.split(':')[0]](template) | ||
} | ||
|
||
return template | ||
return template | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters