From d3cd8b4d382b43ac411461aef1f68ea90117f0f9 Mon Sep 17 00:00:00 2001 From: QiTao Date: Sat, 8 Feb 2020 12:01:17 -0600 Subject: [PATCH] Task #27 - Fix for export markdown functions and click link markdown type --- app/controllers/Export.controller.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/Export.controller.js b/app/controllers/Export.controller.js index a172d9f..a96fb41 100644 --- a/app/controllers/Export.controller.js +++ b/app/controllers/Export.controller.js @@ -41,29 +41,33 @@ class Export extends Controller { await fs.mkdir(temp_dir) this._markdown_recurse(page0, temp_dir) - return res.api({temp_dir}) + 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) + const child = await Page.find({ UUID: { $in: root.ChildPageIds } }) + 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') } }