Просмотр исходного кода

create definitions in and renamed placeholderReader

sou 7 лет назад
Родитель
Сommit
05949197b5
1 измененных файлов с 9 добавлено и 15 удалено
  1. 9 15
      lib/routes/page.js

+ 9 - 15
lib/routes/page.js

@@ -331,13 +331,7 @@ module.exports = function(crowi, app) {
       return Page.findTemplate(path)
         .then(template => {
           if (template) {
-            const definitions = {
-              pagepath: path,
-              username: req.user.name,
-              today: getToday(),
-            };
-
-            template = placeholderReader(template, definitions);
+            template = replacePlaceholders(template, req);
           }
 
           renderVars.template = template;
@@ -376,8 +370,14 @@ module.exports = function(crowi, app) {
     });
   };
 
-  const placeholderReader = (template, definitions) => {
+  const replacePlaceholders = (template, req) => {
+    const definitions = {
+      pagepath: getPathFromRequest(req),
+      username: req.user.name,
+      today: getToday(),
+    };
     const compiledTemplate = swig.compile(template);
+
     return compiledTemplate(definitions);
   };
 
@@ -457,13 +457,7 @@ module.exports = function(crowi, app) {
       return Page.findTemplate(path)
         .then(template => {
           if (template) {
-            const definitions = {
-              pagepath: path,
-              username: req.user.name,
-              today: getToday(),
-            };
-
-            template = placeholderReader(template, definitions);
+            template = replacePlaceholders(template, req);
           }
 
           return res.render('customlayout-selector/not_found', {