Task #27 - Fix for export markdown functions and click link markdown type

This commit is contained in:
QiTao 2020-02-08 12:01:17 -06:00
parent 270da67977
commit d3cd8b4d38

View File

@ -44,26 +44,30 @@ class Export extends Controller {
return res.api({ temp_dir })
}
async _markdown_recurse(root, temp_dir) {
async _markdown_recurse(root, temp_dir) { //recursive function for creating directory and generating markdown pages
console.log('root', root)
const Page = this.models.get('api:Page')
//const child = await root.childPages
const child = await Page.find({ UUID: { $in: root.ChildPageIds } })
console.log('child', child)
for (const page of child) {
const markdown = this._generate_markdown(page)
if (page.ChildPageIds && page.ChildPageIds.length) {
const sub_temp_dir = path.resolve(temp_dir, page.Name.replace(/\s/g, '_'))
console.log('page', page, 'sub_temp', sub_temp_dir)
await fs.mkdir(sub_temp_dir)
this._markdown_recurse(page, sub_temp_dir)
}
}
}
async _generate_markdown(page) {
async _generate_markdown(page) { //generate mark down
const Node = this.models.get('api:Node')
const nodes = await Node.find({ PageId: page.UUID })
return nodes.map(x => { return x.Value.Value }).join('\n')
return nodes.map(x => {
if (x.Type === 'click_link') {
return '[' + x.Value.Value + ']' + '(' + x.Value.Value + ')'
}
return x.Value.Value
}).join('\n')
}
}