|
|
@@ -311,28 +311,25 @@ module.exports = function(crowi, app) {
|
|
|
.catch(function(err) {
|
|
|
pageTeamplate = 'customlayout-selector/not_found';
|
|
|
|
|
|
- const lastSlash = originalUrl.lastIndexOf('/');
|
|
|
- const templateUrl = originalUrl.substr(0, lastSlash);
|
|
|
- const pathList = pathGenerator(originalUrl, []);
|
|
|
+ const templateUrl = cutOffLastSlash(originalUrl);
|
|
|
+ const pathList = findAllAscendantPaths(originalUrl, []);
|
|
|
|
|
|
return Page.findAllTemplates(pathList)
|
|
|
.then(templates => {
|
|
|
//get local template
|
|
|
//@tempate: applicable only to immediate decendants
|
|
|
const localTemplate = templateFinder(templates, templateUrl, '@');
|
|
|
- if (localTemplate) {
|
|
|
- renderVars.template = localTemplate.revision.body;
|
|
|
- return Promise.resolve();
|
|
|
- }
|
|
|
|
|
|
//get global templates
|
|
|
//_tempate: applicable to all pages under
|
|
|
const globalTemplate = globalTemplateFinder(templates, templateUrl);
|
|
|
- if (globalTemplate) {
|
|
|
+
|
|
|
+ if (localTemplate) {
|
|
|
+ renderVars.template = localTemplate.revision.body;
|
|
|
+ }
|
|
|
+ else if (globalTemplate) {
|
|
|
renderVars.template = globalTemplate.revision.body;
|
|
|
}
|
|
|
-
|
|
|
- return Promise.resolve();
|
|
|
});
|
|
|
})
|
|
|
// get list pages
|
|
|
@@ -383,16 +380,20 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- const pathGenerator = (path, pathList) => {
|
|
|
+ const cutOffLastSlash = path => {
|
|
|
const lastSlash = path.lastIndexOf('/');
|
|
|
- const newPath = path.substr(0, lastSlash);
|
|
|
+ return path.substr(0, lastSlash);
|
|
|
+ };
|
|
|
+
|
|
|
+ const findAllAscendantPaths = (path, pathList) => {
|
|
|
+ const newPath = cutOffLastSlash(path);
|
|
|
|
|
|
if (newPath === '') {
|
|
|
return pathList;
|
|
|
}
|
|
|
|
|
|
pathList.push(newPath);
|
|
|
- return pathGenerator(newPath, pathList);
|
|
|
+ return findAllAscendantPaths(newPath, pathList);
|
|
|
};
|
|
|
|
|
|
const globalTemplateFinder = (globalTemplates, path) => {
|
|
|
@@ -405,8 +406,7 @@ module.exports = function(crowi, app) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const lastSlash = path.lastIndexOf('/');
|
|
|
- const newPath = path.substr(0, lastSlash);
|
|
|
+ const newPath = cutOffLastSlash(path);
|
|
|
return globalTemplateFinder(globalTemplates, newPath);
|
|
|
};
|
|
|
|