|
|
@@ -345,22 +345,23 @@ module.exports = function(crowi, app) {
|
|
|
const pathList = pathGenerator(originalUrl, []);
|
|
|
|
|
|
return Page.findAllTemplates(pathList)
|
|
|
- .then(pages => {
|
|
|
-
|
|
|
+ .then(templates => {
|
|
|
//get local template
|
|
|
//@tempate: applicable only to immediate decendants
|
|
|
- const regexForLocalTemplate = new RegExp(`${templateUrl}/@template`);
|
|
|
- const localTemplate = pages.filter(page => page.path.match(regexForLocalTemplate)).pop();
|
|
|
-
|
|
|
+ const localTemplate = templateFinder(templates, templateUrl, '@');
|
|
|
if (localTemplate) {
|
|
|
- renderVars.template = localTemplate.revision.body; //this is not working, gotta populate revision somewhere
|
|
|
- console.log(renderVars.template)
|
|
|
+ console.log('l temp found ', localTemplate.path);
|
|
|
+ renderVars.template = localTemplate.revision.body;
|
|
|
return Promise.resolve();
|
|
|
}
|
|
|
|
|
|
//get global templates
|
|
|
//_tempate: applicable to all pages under
|
|
|
- const globalTemplates = pages.filter(page => page.path.match(/_template/));
|
|
|
+ const globalTemplate = globalTemplateFinder(templates, templateUrl);
|
|
|
+ if (globalTemplate) {
|
|
|
+ console.log('g temp found ', globalTemplate.path);
|
|
|
+ renderVars.template = globalTemplate.revision.body;
|
|
|
+ }
|
|
|
|
|
|
return Promise.resolve();
|
|
|
})
|
|
|
@@ -446,6 +447,31 @@ module.exports = function(crowi, app) {
|
|
|
return pathGenerator(newPath, pathList);
|
|
|
};
|
|
|
|
|
|
+ const globalTemplateFinder = (globalTemplates, path) => {
|
|
|
+ console.log(path);
|
|
|
+ const globalTemplate = templateFinder(globalTemplates, path, '_');
|
|
|
+ if (globalTemplate) {
|
|
|
+ return globalTemplate;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (path === '') {
|
|
|
+ console.log('default template');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const lastSlash = path.lastIndexOf('/');
|
|
|
+ const newPath = path.substr(0, lastSlash);
|
|
|
+ return globalTemplateFinder(globalTemplates, newPath);
|
|
|
+ };
|
|
|
+
|
|
|
+ const templateFinder = (templates, path, type) => {
|
|
|
+ for (let i = 0; i < templates.length; i++) {
|
|
|
+ if (templates[i].path === `${path}/${type}template`) {
|
|
|
+ return templates[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
actions.deletedPageListShow = function(req, res) {
|
|
|
var path = '/trash' + getPathFromRequest(req);
|
|
|
var limit = 50;
|