|
@@ -528,8 +528,10 @@ module.exports = function(crowi) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// find all templates applicable to the new page
|
|
// find all templates applicable to the new page
|
|
|
- pageSchema.statics.findTemplate = function(pathList, templatePath) {
|
|
|
|
|
|
|
+ pageSchema.statics.findTemplate = function(path) {
|
|
|
const Page = this;
|
|
const Page = this;
|
|
|
|
|
+ const templatePath = cutOffLastSlash(path);
|
|
|
|
|
+ const pathList = generatePathsOnTree(templatePath, []);
|
|
|
const regexpList = pathList.map(path => new RegExp(`${path}/[_@]template`));
|
|
const regexpList = pathList.map(path => new RegExp(`${path}/[_@]template`));
|
|
|
|
|
|
|
|
return Page
|
|
return Page
|
|
@@ -545,6 +547,16 @@ module.exports = function(crowi) {
|
|
|
return path.substr(0, lastSlash);
|
|
return path.substr(0, lastSlash);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const generatePathsOnTree = (path, pathList) => {
|
|
|
|
|
+ if (path === '') {
|
|
|
|
|
+ return pathList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ pathList.push(path);
|
|
|
|
|
+ const newPath = cutOffLastSlash(path);
|
|
|
|
|
+ return generatePathsOnTree(newPath, pathList);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
const assignTemplateByType = (templates, path, type) => {
|
|
const assignTemplateByType = (templates, path, type) => {
|
|
|
for (let i = 0; i < templates.length; i++) {
|
|
for (let i = 0; i < templates.length; i++) {
|
|
|
if (templates[i].path === `${path}/${type}template`) {
|
|
if (templates[i].path === `${path}/${type}template`) {
|