Mikael's blog

A developers sixth time trying to maintain a blog

Source Code - Root / masterController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*****************************************
 *   Master Controller
 *****************************************
 *   Author:  mikael.lofjard@gmail.com
 *   Website: http://lofjard.se
 *   License: MIT License
 ****************************************/
  
var MasterController = (function() {
  
  var marked = require('./forked/marked');
  // Server Side Syntax Highlighting
  var sh = require('./forked/sssh/shCore').SyntaxHighlighter;
  var bashBrush = require('./forked/sssh/shBrushBash').Brush;
  var csharpBrush = require('./forked/sssh/shBrushCSharp').Brush;
  var cssBrush = require('./forked/sssh/shBrushCss').Brush;
  var jsBrush = require('./forked/sssh/shBrushJScript').Brush;
  var xmlBrush = require('./forked/sssh/shBrushXml').Brush;
  // end SSSH
  
  var blogPostController = require('./controllers/blogPostController').BlogPostController;
  var listController = require('./controllers/listController').ListController;
  var aboutController = require('./controllers/aboutController').AboutController;
  var adminController = require('./controllers/adminController').AdminController;
  var bundleController = require('./controllers/bundleController').BundleController;
  var feedController = require('./controllers/feedController').FeedController;
  var sourceController = require('./controllers/sourceController').SourceController;
  var searchController = require('./controllers/searchController').SearchController;
  
  return {
    init: function(db, options) {
  
      marked.setOptions({
        gfm: true,
        pedantic: false,
        sanitize: false,
        highlight: function (code, lang) {
          var wrappedCode = '';
          if (lang === 'htmljs') {
            wrappedCode = '<pre class="brush:js;toolbar:false;html-script:true">' + code + '</pre>';
          } else {
            wrappedCode = '<pre class="brush:' + lang + ';toolbar:false">' + code + '</pre>';
          }
          return sh.highlight(wrappedCode);
        },
        wrapCodeBlock: false
      });
  
  
      adminController.init(db, options.uploadPath);
      aboutController.init(db);
      blogPostController.init(db);
      listController.init(db);
      feedController.init(db);
      sourceController.init(db);
      searchController.init(db);
      bundleController.init(options.bundleConfig);
    },
  
    about: aboutController.index,
  
    getPost: blogPostController.getPost,
  
    comment: blogPostController.comment,
  
    page: listController.page,
  
    archive: listController.archive,
  
    tags: listController.tags,
  
    tag: listController.tag,
  
    admin: adminController.index,
  
    upload: adminController.upload,
  
    getPostAsJson: adminController.getPostAsJson,
  
    submitPost: adminController.submitPost,
  
    atomFeed: feedController.atom,
  
    searchIndex: searchController.index,
  
    search: searchController.list,
  
    source: sourceController.index,
  
    sourceDir: sourceController.dir,
  
    sourceFile: sourceController.file
  };
  
}());
  
typeof(exports) != 'undefined' ? exports.MasterController = MasterController : null;