Parse portfolio markdown and expose it as json

This commit is contained in:
Michal Vanko 2019-08-16 16:19:39 +02:00
parent 87777ad19f
commit b8675e5a8c
5 changed files with 87 additions and 19 deletions

40
package-lock.json generated
View File

@ -890,6 +890,14 @@
"color-convert": "^1.9.0" "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": { "array-filter": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/array-filter/-/array-filter-0.0.1.tgz", "resolved": "https://registry.npmjs.org/array-filter/-/array-filter-0.0.1.tgz",
@ -1170,6 +1178,11 @@
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true "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": { "estree-walker": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz",
@ -1182,6 +1195,14 @@
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=",
"dev": true "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": { "function-bind": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
@ -1365,6 +1386,15 @@
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true "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": { "jsesc": {
"version": "2.5.2", "version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
@ -1434,6 +1464,11 @@
"sourcemap-codec": "^1.4.4" "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": { "matchit": {
"version": "1.0.8", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/matchit/-/matchit-1.0.8.tgz", "resolved": "https://registry.npmjs.org/matchit/-/matchit-1.0.8.tgz",
@ -1992,6 +2027,11 @@
"integrity": "sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q==", "integrity": "sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q==",
"dev": true "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": { "string-hash": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/string-hash/-/string-hash-1.1.3.tgz", "resolved": "https://registry.npmjs.org/string-hash/-/string-hash-1.1.3.tgz",

View File

@ -13,6 +13,8 @@
}, },
"dependencies": { "dependencies": {
"compression": "^1.7.1", "compression": "^1.7.1",
"front-matter": "^3.0.2",
"marked": "^0.7.0",
"polka": "^0.5.0", "polka": "^0.5.0",
"sirv": "^0.4.0" "sirv": "^0.4.0"
}, },

View File

@ -1,19 +0,0 @@
<script>
import Personal from '../components/portfolio/personal.svelte';
import Skills from '../components/portfolio/skills.svelte';
import Workhistory from '../components/portfolio/workhistory.svelte';
import Projects from '../components/portfolio/projects.svelte';
</script>
<svelte:head>
<title>Portfolio - Michal Vanko</title>
</svelte:head>
<h1>Michal Vanko</h1>
<h2>Software Developer</h2>
<Personal />
<Skills />
<Workhistory />
<Projects />

View File

@ -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))
}

View File

@ -0,0 +1,19 @@
<script>
import Personal from '../../components/portfolio/personal.svelte';
import Skills from '../../components/portfolio/skills.svelte';
import Workhistory from '../../components/portfolio/workhistory.svelte';
import Projects from '../../components/portfolio/projects.svelte';
</script>
<svelte:head>
<title>Portfolio - Michal Vanko</title>
</svelte:head>
<h1>Michal Vanko</h1>
<h2>Software Developer</h2>
<Personal />
<Skills />
<Workhistory />
<Projects />