1 Commits f4d8823bbd ... 6ca7ebc727

Author SHA1 Message Date
  James Peret 6ca7ebc727 EJS Templating for Markdown and HTML files 6 years ago
2 changed files with 28 additions and 128 deletions
  1. 28 1
      index.js
  2. 0 127
      npm-debug.log

+ 28 - 1
index.js

@@ -66,6 +66,9 @@ var get_file = function(req, res){
66 66
     if(extension == "md"){
67 67
       file_type = "markdown"
68 68
     }
69
+    else if(extension == "html"){
70
+      file_type = "html"
71
+    }
69 72
   } else {
70 73
     // return index file if it exists
71 74
   }
@@ -76,7 +79,16 @@ var get_file = function(req, res){
76 79
         return console.log(err);
77 80
       } else {
78 81
         console.log("Rendered: " + path)
79
-        res.render('index', { body: markdown_parser(data) });
82
+        res.render('index', build_data(data));
83
+      }
84
+    });
85
+  } else if(file_type == "html"){
86
+    fs.readFile(path, 'utf8', function (err,data) {
87
+      if (err) {
88
+        return console.log(err);
89
+      } else {
90
+        console.log("Rendered: " + path)
91
+        res.render(process.cwd() + "/" + path, extra_data());
80 92
       }
81 93
     });
82 94
   } else {
@@ -136,6 +148,21 @@ var markdown_parser = function(data){
136 148
   return md.render(data)
137 149
 }
138 150
 
151
+var build_data = function(data){
152
+  var obj = extra_data();
153
+  obj.body = markdown_parser(data);
154
+  return obj;
155
+}
156
+
157
+var extra_data = function(){
158
+  var time = new Date();
159
+  var date = time.getFullYear();
160
+  var obj = {
161
+    date: date
162
+  }
163
+  return obj;
164
+}
165
+
139 166
 var url_paths = [
140 167
   '/:file',
141 168
   '/:folder_1/:file',

+ 0 - 127
npm-debug.log

@@ -1,127 +0,0 @@
1
-0 info it worked if it ends with ok
2
-1 verbose cli [ '/usr/local/Cellar/node/7.5.0/bin/node',
3
-1 verbose cli   '/usr/local/bin/npm',
4
-1 verbose cli   'publish' ]
5
-2 info using npm@4.1.2
6
-3 info using node@v7.5.0
7
-4 verbose publish [ '.' ]
8
-5 silly cache add args [ '.', null ]
9
-6 verbose cache add spec .
10
-7 silly cache add parsed spec Result {
11
-7 silly cache add   raw: '.',
12
-7 silly cache add   scope: null,
13
-7 silly cache add   escapedName: null,
14
-7 silly cache add   name: null,
15
-7 silly cache add   rawSpec: '.',
16
-7 silly cache add   spec: '/Users/james/dev/codex-server',
17
-7 silly cache add   type: 'directory' }
18
-8 verbose addLocalDirectory /Users/james/.npm/@jamesperet/codex-server/0.0.3/package.tgz not in flight; packing
19
-9 verbose correctMkdir /Users/james/.npm correctMkdir not in flight; initializing
20
-10 info lifecycle @jamesperet/codex-server@0.0.3~prepublish: @jamesperet/codex-server@0.0.3
21
-11 silly lifecycle @jamesperet/codex-server@0.0.3~prepublish: no script for prepublish, continuing
22
-12 info lifecycle @jamesperet/codex-server@0.0.3~prepare: @jamesperet/codex-server@0.0.3
23
-13 silly lifecycle @jamesperet/codex-server@0.0.3~prepare: no script for prepare, continuing
24
-14 verbose tar pack [ '/Users/james/.npm/@jamesperet/codex-server/0.0.3/package.tgz',
25
-14 verbose tar pack   '/Users/james/dev/codex-server' ]
26
-15 verbose tarball /Users/james/.npm/@jamesperet/codex-server/0.0.3/package.tgz
27
-16 verbose folder /Users/james/dev/codex-server
28
-17 verbose addLocalTarball adding from inside cache /Users/james/.npm/@jamesperet/codex-server/0.0.3/package.tgz
29
-18 verbose correctMkdir /Users/james/.npm correctMkdir not in flight; initializing
30
-19 silly cache afterAdd @jamesperet/codex-server@0.0.3
31
-20 verbose afterAdd /Users/james/.npm/@jamesperet/codex-server/0.0.3/package/package.json not in flight; writing
32
-21 verbose correctMkdir /Users/james/.npm correctMkdir not in flight; initializing
33
-22 verbose afterAdd /Users/james/.npm/@jamesperet/codex-server/0.0.3/package/package.json written
34
-23 silly publish { name: '@jamesperet/codex-server',
35
-23 silly publish   version: '0.0.3',
36
-23 silly publish   description: 'A node file server with super powers.',
37
-23 silly publish   main: 'index.js',
38
-23 silly publish   scripts: { test: 'echo "Error: no test specified" && exit 1' },
39
-23 silly publish   repository:
40
-23 silly publish    { type: 'git',
41
-23 silly publish      url: 'git+https://github.com/jamesperet/codex-server.git' },
42
-23 silly publish   author: { name: 'James Peret' },
43
-23 silly publish   license: 'ISC',
44
-23 silly publish   bin: { codex: './index.js' },
45
-23 silly publish   dependencies:
46
-23 silly publish    { ascii2mathml: '^0.5.4',
47
-23 silly publish      'body-parser': '^1.17.2',
48
-23 silly publish      ejs: '^2.5.6',
49
-23 silly publish      express: '^4.15.2',
50
-23 silly publish      lodash: '^4.17.4',
51
-23 silly publish      markdown: '^0.5.0',
52
-23 silly publish      'markdown-it': '^8.3.1',
53
-23 silly publish      'markdown-it-highlightjs': '^3.0.0',
54
-23 silly publish      'markdown-it-math': '^4.0.1',
55
-23 silly publish      'markdown-it-mathjax': '^2.0.0',
56
-23 silly publish      marked: '^0.3.6',
57
-23 silly publish      mathjax: '^2.7.1' },
58
-23 silly publish   readme: '# Codex Server\n',
59
-23 silly publish   readmeFilename: 'readme.md',
60
-23 silly publish   gitHead: 'f5d9ba7212546d1bb2050ce116a770a035a595fd',
61
-23 silly publish   bugs: { url: 'https://github.com/jamesperet/codex-server/issues' },
62
-23 silly publish   homepage: 'https://github.com/jamesperet/codex-server#readme',
63
-23 silly publish   _id: '@jamesperet/codex-server@0.0.3',
64
-23 silly publish   _shasum: '9236619733512f40b492c27458a916d9e341256d',
65
-23 silly publish   _from: '.' }
66
-24 info lifecycle @jamesperet/codex-server@0.0.3~prepublishOnly: @jamesperet/codex-server@0.0.3
67
-25 silly lifecycle @jamesperet/codex-server@0.0.3~prepublishOnly: no script for prepublishOnly, continuing
68
-26 verbose getPublishConfig undefined
69
-27 silly mapToRegistry name @jamesperet/codex-server
70
-28 silly mapToRegistry scope (from package name) @jamesperet
71
-29 verbose mapToRegistry no registry URL found in name for scope @jamesperet
72
-30 silly mapToRegistry using default registry
73
-31 silly mapToRegistry registry https://registry.npmjs.org/
74
-32 silly mapToRegistry data Result {
75
-32 silly mapToRegistry   raw: '@jamesperet/codex-server',
76
-32 silly mapToRegistry   scope: '@jamesperet',
77
-32 silly mapToRegistry   escapedName: '@jamesperet%2fcodex-server',
78
-32 silly mapToRegistry   name: '@jamesperet/codex-server',
79
-32 silly mapToRegistry   rawSpec: '',
80
-32 silly mapToRegistry   spec: 'latest',
81
-32 silly mapToRegistry   type: 'tag' }
82
-33 silly mapToRegistry uri https://registry.npmjs.org/@jamesperet%2fcodex-server
83
-34 verbose publish registryBase https://registry.npmjs.org/
84
-35 silly publish uploading /Users/james/.npm/@jamesperet/codex-server/0.0.3/package.tgz
85
-36 verbose request uri https://registry.npmjs.org/@jamesperet%2fcodex-server
86
-37 verbose request sending authorization for write operation
87
-38 info attempt registry request try #1 at 2:43:12 AM
88
-39 verbose request using bearer token for auth
89
-40 verbose request id 92c0a8cff47e2c6d
90
-41 http request PUT https://registry.npmjs.org/@jamesperet%2fcodex-server
91
-42 http 403 https://registry.npmjs.org/@jamesperet%2fcodex-server
92
-43 verbose headers { 'content-type': 'application/json',
93
-43 verbose headers   'cache-control': 'max-age=0',
94
-43 verbose headers   'content-length': '95',
95
-43 verbose headers   'accept-ranges': 'bytes',
96
-43 verbose headers   date: 'Tue, 04 Jul 2017 05:43:15 GMT',
97
-43 verbose headers   via: '1.1 varnish',
98
-43 verbose headers   connection: 'keep-alive',
99
-43 verbose headers   'x-served-by': 'cache-yyz8328-YYZ',
100
-43 verbose headers   'x-cache': 'MISS',
101
-43 verbose headers   'x-cache-hits': '0',
102
-43 verbose headers   'x-timer': 'S1499146995.347352,VS0,VE391' }
103
-44 verbose request invalidating /Users/james/.npm/registry.npmjs.org/_40jamesperet_252fcodex-server on PUT
104
-45 error publish Failed PUT 403
105
-46 verbose stack Error: "You cannot publish over the previously published version 0.0.3." : @jamesperet/codex-server
106
-46 verbose stack     at makeError (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:304:12)
107
-46 verbose stack     at CachingRegistryClient.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:292:14)
108
-46 verbose stack     at Request._callback (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:212:14)
109
-46 verbose stack     at Request.self.callback (/usr/local/lib/node_modules/npm/node_modules/request/request.js:186:22)
110
-46 verbose stack     at emitTwo (events.js:106:13)
111
-46 verbose stack     at Request.emit (events.js:192:7)
112
-46 verbose stack     at Request.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/request.js:1081:10)
113
-46 verbose stack     at emitOne (events.js:96:13)
114
-46 verbose stack     at Request.emit (events.js:189:7)
115
-46 verbose stack     at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/request.js:1001:12)
116
-47 verbose statusCode 403
117
-48 verbose pkgid @jamesperet/codex-server
118
-49 verbose cwd /Users/james/dev/codex-server
119
-50 error Darwin 16.1.0
120
-51 error argv "/usr/local/Cellar/node/7.5.0/bin/node" "/usr/local/bin/npm" "publish"
121
-52 error node v7.5.0
122
-53 error npm  v4.1.2
123
-54 error code E403
124
-55 error "You cannot publish over the previously published version 0.0.3." : @jamesperet/codex-server
125
-56 error If you need help, you may report this error at:
126
-56 error     <https://github.com/npm/npm/issues>
127
-57 verbose exit [ 1, true ]