display blog article

This commit is contained in:
Michal Vanko 2019-12-26 07:50:57 +01:00
parent b67fb2e6a5
commit 1dd89aef87
4 changed files with 65 additions and 38 deletions

View File

@ -71,3 +71,24 @@ adspexit Circe est iuvencae ut favilla inque vir. Fas gelidas depressitque, et
ipse, occidit **afflatibus** est caesosque Liber? Animam [gramine quam
melior](http://nequesolum.net/in.html); arbor parte gestit moras trementia
aquilone se membris prima; Atlantis.
- Iunget quem color baculumque insistere perque nequiquam
- Temptabat Macareus hoc urbem inmanem alasque averserisque
- Tibia vita ita
- Mihi caput audito Hippolytus debita finita
- Ignis murmura summa nimis fragmina
- Aeneadae omnibus
## Tractus aderat
Datque **in sidera** timorem in fuerant partem, sit hi lapidis robora et
Phrygii! Dixisse dato posse et balatus tu tractare adit, merito quid tamen se.
[Huic](http://quibus-corpus.net/dissimulare-condit.html) nivea in modo iam enixa
sinistrum, haud collabitur misit, bello.
1. Stimuletur orbem vestigia regina
2. Pedibusque Latona in sub ponderis sustinuit maiora
3. Paverunt metiris malorum genetrice de illis
4. Sedebant ora
5. Deae bicolor submisso
6. Suis astra ut illas frontes

View File

@ -23,7 +23,11 @@ export async function get(req, res, next) {
}
const parsedPost = fm(postSource)
const response = parseField('body')(parsedPost)
const response = parseField('body')({
...parsedPost.attributes,
body: parsedPost.body,
})
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify(response))

View File

@ -2,19 +2,19 @@
export async function preload({ params, query }) {
// the `slug` parameter is available because
// this file is called [slug].svelte
const res = await this.fetch(`blog/${params.slug}.json`);
const data = await res.json();
const res = await this.fetch(`blog/${params.slug}.json`)
const data = await res.json()
if (res.status === 200) {
return { post: data };
return { post: data }
} else {
this.error(res.status, data.message);
this.error(res.status, data.message)
}
}
</script>
<script>
export let post;
export let post
</script>
<style>
@ -59,6 +59,6 @@
<h1>{post.title}</h1>
<div class='content'>
{@html post.html}
<div class="content">
{@html post.body}
</div>

View File

@ -1,5 +1,6 @@
import { readdir, readFile } from 'fs'
import { promisify } from 'util'
import { basename } from 'path'
import fm from 'front-matter'
import marked from 'marked'
@ -24,6 +25,7 @@ export async function get(req, res) {
return {
...parsedAttributes.attributes,
preview,
slug: basename(file, '.md'),
}
})
)