Sotaro KARASAWA 9 лет назад
Родитель
Сommit
a861078a31
3 измененных файлов с 48 добавлено и 0 удалено
  1. 18 0
      lib/util/middlewares.js
  2. 25 0
      lib/views/_form.html
  3. 5 0
      resource/js/crowi-form.js

+ 18 - 0
lib/util/middlewares.js

@@ -70,6 +70,24 @@ exports.swigFilters = function(app, swig) {
       return name.replace(/.+\/(.+)?$/, '$1'); // ページの末尾を拾う
       return name.replace(/.+\/(.+)?$/, '$1'); // ページの末尾を拾う
     });
     });
 
 
+    swig.setFilter('normalizeDateInPath', function(path) {
+      // warning for /(20\d{4}|20\d{6}|20\d{2}_\d{1,2}|20\d{2}_\d{1,2}_\d{1,2})/
+      if (path.match(/20(\d{2})(\d{2})(\d{2})/g)) {
+        return path.replace(/20(\d{2})(\d{2})(\d{2})/g, '20$1/$2/$3');
+      }
+      if (path.match(/20(\d{2})(\d{2})/g)) {
+        return path.replace(/20(\d{2})(\d{2})/g, '20$1/$2');
+      }
+      if (path.match(/20(\d{2})_(\d{1,2})_(\d{1,2})/g)) {
+        return path.replace(/20(\d{2})_(\d{1,2})_(\d{1,2})/g, '20$1/$2/$3');
+      }
+      if (path.match(/20(\d{2})_(\d{1,2})/g)) {
+        return path.replace(/20(\d{2})_(\d{1,2})/g, '20$1/$2');
+      }
+
+      return path;
+    });
+
     swig.setFilter('datetz', function(input, format) {
     swig.setFilter('datetz', function(input, format) {
       // timezone
       // timezone
       var swigFilters = require('swig/lib/filters');
       var swigFilters = require('swig/lib/filters');

+ 25 - 0
lib/views/_form.html

@@ -61,4 +61,29 @@
   <div class="file-module hidden">
   <div class="file-module hidden">
   </div>
   </div>
 </div>
 </div>
+
+<div class="modal fade page-warning-modal" id="page-warning-modal">
+  <div class="modal-dialog">
+    <div class="modal-content">
+
+      <div class="modal-header">
+        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+        <h4 class="modal-title">ページ名に関するヒント</h4>
+      </div>
+      <div class="modal-body alert alert-danger">
+
+        <strong>Warning!</strong><br>
+
+        <p>
+        スラッシュ <code>/</code> で区切られていない、日付の入ったページ名をつけようとしていませんか?<br>
+        ページ名に日付を入れる場合、スラッシュ <code>/</code> で区切ることが推奨されています。<br>
+        <br>
+        推奨されるページ名で作成する場合、<br>
+        <a href="{{ path|normalizeDateInPath }}">{{ path|normalizeDateInPath }}</a> から作成をはじめてください。
+        </p>
+
+      </div>
+    </div>
+  </div>
+</div>
 <script src="/js/form{% if env  == 'production' %}.min{% endif %}.js"></script>
 <script src="/js/form{% if env  == 'production' %}.min{% endif %}.js"></script>

+ 5 - 0
resource/js/crowi-form.js

@@ -16,6 +16,11 @@ $(function() {
     });
     });
   }
   }
 
 
+  //
+  if (pagePath.match(/(20\d{4}|20\d{6}|20\d{2}_\d{1,2}|20\d{2}_\d{1,2}_\d{1,2})/)) {
+    $('#page-warning-modal').modal('show');
+  }
+
   var slackConfigured = $('#page-form-setting').data('slack-configured');
   var slackConfigured = $('#page-form-setting').data('slack-configured');
 
 
   // for new page
   // for new page