|
|
@@ -312,11 +312,11 @@ module.exports = function(crowi, app) {
|
|
|
pageTeamplate = 'customlayout-selector/not_found';
|
|
|
|
|
|
const templatePath = cutOffLastSlash(originalPath);
|
|
|
- const pathList = findAllAscendantPaths(originalPath, []);
|
|
|
+ const pathList = generatePathsOnTree(originalPath, []);
|
|
|
|
|
|
return Page.findAllTemplates(pathList)
|
|
|
.then(templates => {
|
|
|
- renderVars.template = templateFinder(templates, templatePath);
|
|
|
+ renderVars.template = fetchTemplate(templates, templatePath);
|
|
|
});
|
|
|
})
|
|
|
// get list pages
|
|
|
@@ -372,7 +372,7 @@ module.exports = function(crowi, app) {
|
|
|
return path.substr(0, lastSlash);
|
|
|
};
|
|
|
|
|
|
- const findAllAscendantPaths = (path, pathList) => {
|
|
|
+ const generatePathsOnTree = (path, pathList) => {
|
|
|
const newPath = cutOffLastSlash(path);
|
|
|
|
|
|
if (newPath === '') {
|
|
|
@@ -380,10 +380,10 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
pathList.push(newPath);
|
|
|
- return findAllAscendantPaths(newPath, pathList);
|
|
|
+ return generatePathsOnTree(newPath, pathList);
|
|
|
};
|
|
|
|
|
|
- const findTemplateByType = (templates, path, type) => {
|
|
|
+ const assignTemplateByType = (templates, path, type) => {
|
|
|
for (let i = 0; i < templates.length; i++) {
|
|
|
if (templates[i].path === `${path}/${type}template`) {
|
|
|
return templates[i];
|
|
|
@@ -391,8 +391,8 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const globalTemplateFinder = (globalTemplates, path) => {
|
|
|
- const globalTemplate = findTemplateByType(globalTemplates, path, '_');
|
|
|
+ const assignGlobalTemplate = (globalTemplates, path) => {
|
|
|
+ const globalTemplate = assignTemplateByType(globalTemplates, path, '_');
|
|
|
if (globalTemplate) {
|
|
|
return globalTemplate;
|
|
|
}
|
|
|
@@ -402,19 +402,22 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
const newPath = cutOffLastSlash(path);
|
|
|
- return globalTemplateFinder(globalTemplates, newPath);
|
|
|
+ return assignGlobalTemplate(globalTemplates, newPath);
|
|
|
};
|
|
|
|
|
|
- const templateFinder = (templates, templatePath) => {
|
|
|
+ const fetchTemplate = (templates, templatePath) => {
|
|
|
let templateBody;
|
|
|
-
|
|
|
- //get local template
|
|
|
- //@tempate: applicable only to immediate decendants
|
|
|
- const localTemplate = findTemplateByType(templates, templatePath, '@');
|
|
|
-
|
|
|
- //get global templates
|
|
|
- //_tempate: applicable to all pages under
|
|
|
- const globalTemplate = globalTemplateFinder(templates, templatePath);
|
|
|
+ /**
|
|
|
+ * get local template
|
|
|
+ * @tempate: applicable only to immediate decendants
|
|
|
+ */
|
|
|
+ const localTemplate = assignTemplateByType(templates, templatePath, '@');
|
|
|
+
|
|
|
+ /**
|
|
|
+ * get global templates
|
|
|
+ * _tempate: applicable to all pages under
|
|
|
+ */
|
|
|
+ const globalTemplate = assignGlobalTemplate(templates, templatePath);
|
|
|
|
|
|
if (localTemplate) {
|
|
|
templateBody = localTemplate.revision.body;
|