From b8675e5a8c486e3604f3fad25aefd43468c0323c Mon Sep 17 00:00:00 2001 From: Michal Vanko Date: Fri, 16 Aug 2019 16:19:39 +0200 Subject: [PATCH] Parse portfolio markdown and expose it as json --- package-lock.json | 40 +++++++++++++++++++++++++++ package.json | 2 ++ src/routes/portfolio.svelte | 19 ------------- src/routes/portfolio/index.json.js | 26 +++++++++++++++++ src/routes/portfolio/portfolio.svelte | 19 +++++++++++++ 5 files changed, 87 insertions(+), 19 deletions(-) delete mode 100644 src/routes/portfolio.svelte create mode 100644 src/routes/portfolio/index.json.js create mode 100644 src/routes/portfolio/portfolio.svelte diff --git a/package-lock.json b/package-lock.json index f9071a5..9f59dd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -890,6 +890,14 @@ "color-convert": "^1.9.0" } }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "requires": { + "sprintf-js": "~1.0.2" + } + }, "array-filter": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/array-filter/-/array-filter-0.0.1.tgz", @@ -1170,6 +1178,11 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" + }, "estree-walker": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", @@ -1182,6 +1195,14 @@ "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", "dev": true }, + "front-matter": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/front-matter/-/front-matter-3.0.2.tgz", + "integrity": "sha512-iBGZaWyzqgsrPGsqrXZP6N4hp5FzSKDi18nfAoYpgz3qK5sAwFv/ojmn3VS60SOgLvq6CtojNqy0y6ZNz05IzQ==", + "requires": { + "js-yaml": "^3.13.1" + } + }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -1365,6 +1386,15 @@ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", "dev": true }, + "js-yaml": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -1434,6 +1464,11 @@ "sourcemap-codec": "^1.4.4" } }, + "marked": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", + "integrity": "sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg==" + }, "matchit": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/matchit/-/matchit-1.0.8.tgz", @@ -1992,6 +2027,11 @@ "integrity": "sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q==", "dev": true }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" + }, "string-hash": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/string-hash/-/string-hash-1.1.3.tgz", diff --git a/package.json b/package.json index 0a0360c..dac0435 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ }, "dependencies": { "compression": "^1.7.1", + "front-matter": "^3.0.2", + "marked": "^0.7.0", "polka": "^0.5.0", "sirv": "^0.4.0" }, diff --git a/src/routes/portfolio.svelte b/src/routes/portfolio.svelte deleted file mode 100644 index 80ec7d0..0000000 --- a/src/routes/portfolio.svelte +++ /dev/null @@ -1,19 +0,0 @@ - - - - Portfolio - Michal Vanko - - -

Michal Vanko

- -

Software Developer

- - - - - diff --git a/src/routes/portfolio/index.json.js b/src/routes/portfolio/index.json.js new file mode 100644 index 0000000..4bd9510 --- /dev/null +++ b/src/routes/portfolio/index.json.js @@ -0,0 +1,26 @@ +import { readFile } from 'fs' +import { promisify } from 'util' +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), + } + + res.setHeader('Content-Type', 'application/json') + res.end(JSON.stringify(response)) +} \ No newline at end of file diff --git a/src/routes/portfolio/portfolio.svelte b/src/routes/portfolio/portfolio.svelte new file mode 100644 index 0000000..d6fc765 --- /dev/null +++ b/src/routes/portfolio/portfolio.svelte @@ -0,0 +1,19 @@ + + + + Portfolio - Michal Vanko + + +

Michal Vanko

+ +

Software Developer

+ + + + +