From 9d06c9833390430ee06c60819b21bcc40316eb4d Mon Sep 17 00:00:00 2001 From: Michal Vanko Date: Fri, 16 Aug 2019 20:26:46 +0200 Subject: [PATCH] Load projects from cms in portfolio --- src/components/portfolio/project.svelte | 17 ++++++++++ src/routes/portfolio/index.json.js | 39 ++++++++++++----------- src/routes/portfolio/index.svelte | 41 +++++++++++++++++++++++++ src/routes/portfolio/portfolio.svelte | 19 ------------ 4 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 src/components/portfolio/project.svelte create mode 100644 src/routes/portfolio/index.svelte delete mode 100644 src/routes/portfolio/portfolio.svelte diff --git a/src/components/portfolio/project.svelte b/src/components/portfolio/project.svelte new file mode 100644 index 0000000..aa285c4 --- /dev/null +++ b/src/components/portfolio/project.svelte @@ -0,0 +1,17 @@ + + +
+

{project.name}

+
+ {@html project.description} +
+ {#if project.image} + + {/if} + +
diff --git a/src/routes/portfolio/index.json.js b/src/routes/portfolio/index.json.js index 4bd9510..cd1d31d 100644 --- a/src/routes/portfolio/index.json.js +++ b/src/routes/portfolio/index.json.js @@ -4,23 +4,26 @@ import fm from 'front-matter' import marked from 'marked' export async function get(req, res, next) { - let pageSource - try { - console.log(process.cwd()) - pageSource = await promisify(readFile)('_pages/portfolio.md', 'utf-8') - } catch (e) { - res.statusCode = 500 - res.end('Error loading portfolio source file. \n' + e.toString()) - return - } - - const parsed = fm(pageSource) - console.log(parsed) - const response = { - title: parsed.attributes.title, - content: marked(parsed.attributes.content), - } + let pageSource + try { + pageSource = await promisify(readFile)('_pages/portfolio.md', 'utf-8') + } catch (e) { + res.statusCode = 500 + res.end('Error loading portfolio source file. \n' + e.toString()) + return + } - res.setHeader('Content-Type', 'application/json') - res.end(JSON.stringify(response)) + const parsed = fm(pageSource) + const projects = (parsed.attributes.projects || []).map(project => ({ + ...project, + description: marked(project.description) + })) + const response = { + title: parsed.attributes.title, + body: marked(parsed.body), + projects, + } + + res.setHeader('Content-Type', 'application/json') + res.end(JSON.stringify(response)) } \ No newline at end of file diff --git a/src/routes/portfolio/index.svelte b/src/routes/portfolio/index.svelte new file mode 100644 index 0000000..125efad --- /dev/null +++ b/src/routes/portfolio/index.svelte @@ -0,0 +1,41 @@ + + + + + + {content.title} + + +

Michal Vanko

+ +

Software Developer

+ +
+ {@html content.body} +
+ + + +
+

Projects

+
    + {#each content.projects as project} +
  • + +
  • + {/each} +
+
diff --git a/src/routes/portfolio/portfolio.svelte b/src/routes/portfolio/portfolio.svelte deleted file mode 100644 index d6fc765..0000000 --- a/src/routes/portfolio/portfolio.svelte +++ /dev/null @@ -1,19 +0,0 @@ - - - - Portfolio - Michal Vanko - - -

Michal Vanko

- -

Software Developer

- - - - -