MCPcopy Index your code
hub / github.com/jaredly/hexo-admin / use

Function use

api.js:117–143  ·  view source on GitHub ↗
(path, fn)

Source from the content-addressed store, hash-verified

115 }
116
117 var use = function (path, fn) {
118 app.use(hexo.config.root + 'admin/api/' + path, function (req, res) {
119 var done = function (val) {
120 if (!val) {
121 res.statusCode = 204
122 return res.end('');
123 }
124 res.setHeader('Content-type', 'application/json')
125 res.end(JSON.stringify(val, function(k, v) {
126 // tags and cats have posts reference resulting in circular json..
127 if ( k == 'tags' || k == 'categories' ) {
128 // convert object to simple array
129 return v.toArray ? v.toArray().map(function(obj) {
130 return obj.name
131 }) : v
132 }
133 return v;
134 }))
135 }
136 res.done = done
137 res.send = function (num, data) {
138 res.statusCode = num
139 res.end(data)
140 }
141 fn(req, res)
142 })
143 }
144
145 use('tags-categories-and-metadata', function (req, res) {
146 res.done(tagsCategoriesAndMetadata())

Callers 1

api.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected