forked from colmena/colmena
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.js
More file actions
44 lines (39 loc) · 840 Bytes
/
page.js
File metadata and controls
44 lines (39 loc) · 840 Bytes
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
'use strict'
import { Converter } from 'showdown'
const converter = new Converter()
module.exports = function (Page) {
Page.createFakeData = (faker) => {
const name = faker.company.catchPhrase()
const slug = faker.helpers.slugify(name)
return Page.create({
id: slug,
name: name,
slug: slug,
content: `> ${faker.lorem.paragraph()}`,
})
}
Page.html = (id, cb) => {
Page.findById(id, (err, page) => {
if (err) {
return cb(err)
}
const result = page
result.html = converter.makeHtml(page.content)
cb(err, result)
})
}
Page.remoteMethod('html', {
accepts: {
arg: 'id',
type: 'string',
},
returns: {
arg: 'content',
type: 'string',
},
http: {
path: '/:id/html',
verb: 'get',
},
})
}