|
|
@@ -310,46 +310,81 @@ module.exports = function(crowi, app) {
|
|
|
// look for templates if page not exists
|
|
|
.catch(function(err) {
|
|
|
// use not_found pageTempalte for both a new page with either tempalte and a new page with no templates
|
|
|
+ // pageTeamplate = 'customlayout-selector/not_found';
|
|
|
+
|
|
|
+ // const lastSlash = originalUrl.lastIndexOf('/');
|
|
|
+ // const templateUrl = `${originalUrl.substr(0, lastSlash)}/@template`;
|
|
|
+
|
|
|
+ // // @tempate: applicable only to immediate decendants
|
|
|
+ // const getLocalTemplate = Page.findPage(templateUrl)
|
|
|
+ // .then(function(page) {
|
|
|
+ // return Promise.resolve(page.path);
|
|
|
+ // })
|
|
|
+ // .catch(function(err) {
|
|
|
+ // console.log('no @template for you');
|
|
|
+ // return Promise.resolve();
|
|
|
+ // });
|
|
|
+
|
|
|
+ // //FIXME
|
|
|
+ // const rootPageName = originalUrl.replace(/^\/([^\/]*).*$/, '$1');
|
|
|
+
|
|
|
+ // // _tempate: applicable to all pages under
|
|
|
+ // const getGlobalTemplate = Page.findPage(`/${rootPageName}/_template`)
|
|
|
+ // .then(page => {
|
|
|
+ // return Promise.resolve(page.path);
|
|
|
+ // })
|
|
|
+ // .catch(function(err) {
|
|
|
+ // console.log('no _template for you');
|
|
|
+ // return Promise.resolve();
|
|
|
+ // });
|
|
|
+
|
|
|
pageTeamplate = 'customlayout-selector/not_found';
|
|
|
|
|
|
const lastSlash = originalUrl.lastIndexOf('/');
|
|
|
- const templateUrl = `${originalUrl.substr(0, lastSlash)}/@template`;
|
|
|
+ const templateUrl = originalUrl.substr(0, lastSlash);
|
|
|
+ const pathList = pathGenerator(originalUrl, []);
|
|
|
|
|
|
- // @tempate: applicable only to immediate decendants
|
|
|
- const getLocalTemplate = Page.findPage(templateUrl)
|
|
|
- .then(function(page) {
|
|
|
- return Promise.resolve(page.path);
|
|
|
- })
|
|
|
- .catch(function(err) {
|
|
|
- console.log('no @template for you');
|
|
|
- return Promise.resolve();
|
|
|
- });
|
|
|
+ return Page.findAllTemplates(pathList)
|
|
|
+ .then(pages => {
|
|
|
|
|
|
- //FIXME
|
|
|
- const rootPageName = originalUrl.replace(/^\/([^\/]*).*$/, '$1');
|
|
|
+ //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();
|
|
|
|
|
|
- // _tempate: applicable to all pages under
|
|
|
- const getGlobalTemplate = Page.findPage(`/${rootPageName}/_template`)
|
|
|
- .then(function(page) {
|
|
|
- return Promise.resolve(page.path);
|
|
|
- })
|
|
|
- .catch(function(err) {
|
|
|
- console.log('no _template for you');
|
|
|
- return Promise.resolve();
|
|
|
- });
|
|
|
+ if (localTemplate) {
|
|
|
+ renderVars.template = localTemplate.revision.body; //this is not working, gotta populate revision somewhere
|
|
|
+ console.log(renderVars.template)
|
|
|
+ return Promise.resolve();
|
|
|
+ }
|
|
|
|
|
|
- return Promise.all([getGlobalTemplate, getLocalTemplate])
|
|
|
- .then(function(templates) {
|
|
|
- const globalTemplate = templates[0];
|
|
|
- const localTemplate = templates[1];
|
|
|
+ //get global templates
|
|
|
+ //_tempate: applicable to all pages under
|
|
|
+ const globalTemplates = pages.filter(page => page.path.match(/_template/));
|
|
|
|
|
|
- if (globalTemplate) {
|
|
|
- renderVars.template = globalTemplate.revision.body;
|
|
|
- }
|
|
|
- else if (localTemplate) {
|
|
|
- renderVars.template = localTemplate.revision.body;
|
|
|
- }
|
|
|
+ return Promise.resolve();
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.log('no templates found');
|
|
|
+ return Promise.resolve();
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // return Promise.all([getGlobalTemplate, getLocalTemplate])
|
|
|
+ // .then(function(templates) {
|
|
|
+ // const globalTemplate = templates[0];
|
|
|
+ // const localTemplate = templates[1];
|
|
|
+
|
|
|
+ // if (globalTemplate) {
|
|
|
+ // renderVars.template = globalTemplate.revision.body;
|
|
|
+ // }
|
|
|
+ // else if (localTemplate) {
|
|
|
+ // renderVars.template = localTemplate.revision.body;
|
|
|
+ // }
|
|
|
+ // });
|
|
|
})
|
|
|
// get list pages
|
|
|
.then(function() {
|