|
|
@@ -527,21 +527,21 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- // check if a given page has a local and global tempalte
|
|
|
+ // check if a given page has a children and decendants tempalte
|
|
|
pageSchema.statics.checkIfTemplatesExist = function(path) {
|
|
|
const Page = this;
|
|
|
const pathList = generatePathsOnTree(path, []);
|
|
|
const regexpList = pathList.map(path => new RegExp(`${path}/_{1,2}template`));
|
|
|
let templateInfo = {
|
|
|
- localTemplateExists: false,
|
|
|
- globalTemplateExists: false,
|
|
|
+ childrenTemplateExists: false,
|
|
|
+ decendantsTemplateExists: false,
|
|
|
};
|
|
|
|
|
|
return Page
|
|
|
.find({path: {$in: regexpList}})
|
|
|
.then(templates => {
|
|
|
- templateInfo.localTemplateExists = (assignTemplateByType(templates, path, '__') ? true : false);
|
|
|
- templateInfo.globalTemplateExists = (assignGlobalTemplate(templates, path) ? true : false);
|
|
|
+ templateInfo.childrenTemplateExists = (assignTemplateByType(templates, path, '_') ? true : false);
|
|
|
+ templateInfo.decendantsTemplateExists = (assignTemplateByType(templates, path, '__') ? true : false);
|
|
|
|
|
|
return templateInfo;
|
|
|
});
|
|
|
@@ -588,10 +588,10 @@ module.exports = function(crowi) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const assignGlobalTemplate = (globalTemplates, path) => {
|
|
|
- const globalTemplate = assignTemplateByType(globalTemplates, path, '_');
|
|
|
- if (globalTemplate) {
|
|
|
- return globalTemplate;
|
|
|
+ const assignDecendantsTemplate = (decendantsTemplates, path) => {
|
|
|
+ const decendantsTemplate = assignTemplateByType(decendantsTemplates, path, '__');
|
|
|
+ if (decendantsTemplate) {
|
|
|
+ return decendantsTemplate;
|
|
|
}
|
|
|
|
|
|
if (path === '') {
|
|
|
@@ -599,28 +599,28 @@ module.exports = function(crowi) {
|
|
|
}
|
|
|
|
|
|
const newPath = cutOffLastSlash(path);
|
|
|
- return assignGlobalTemplate(globalTemplates, newPath);
|
|
|
+ return assignDecendantsTemplate(decendantsTemplates, newPath);
|
|
|
};
|
|
|
|
|
|
const fetchTemplate = (templates, templatePath) => {
|
|
|
let templateBody;
|
|
|
/**
|
|
|
- * get local template
|
|
|
+ * get children template
|
|
|
* __tempate: applicable only to immediate decendants
|
|
|
*/
|
|
|
- const localTemplate = assignTemplateByType(templates, templatePath, '__');
|
|
|
+ const childrenTemplate = assignTemplateByType(templates, templatePath, '_');
|
|
|
|
|
|
/**
|
|
|
- * get global templates
|
|
|
+ * get decendants templates
|
|
|
* _tempate: applicable to all pages under
|
|
|
*/
|
|
|
- const globalTemplate = assignGlobalTemplate(templates, templatePath);
|
|
|
+ const decendantsTemplate = assignDecendantsTemplate(templates, templatePath);
|
|
|
|
|
|
- if (localTemplate) {
|
|
|
- templateBody = localTemplate.revision.body;
|
|
|
+ if (childrenTemplate) {
|
|
|
+ templateBody = childrenTemplate.revision.body;
|
|
|
}
|
|
|
- else if (globalTemplate) {
|
|
|
- templateBody = globalTemplate.revision.body;
|
|
|
+ else if (decendantsTemplate) {
|
|
|
+ templateBody = decendantsTemplate.revision.body;
|
|
|
}
|
|
|
|
|
|
return templateBody;
|