2020-11-13 13:57:23 -08:00
|
|
|
<template>
|
|
|
|
<NotFound v-if="!content"/>
|
2020-12-11 11:37:04 -08:00
|
|
|
<div v-else class="blog-post">
|
2020-11-13 13:57:23 -08:00
|
|
|
<div v-html="content"></div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { head } from "../src/helpers";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
async asyncData({route}) {
|
|
|
|
try {
|
2020-11-29 02:03:01 -08:00
|
|
|
const content = (await import(`../data/blog/${route.params.slug}.md`)).default;
|
2020-11-23 08:41:12 -08:00
|
|
|
const titleMatch = content.match('<h1[^>]*>([^<]+)</h1>');
|
|
|
|
const title = titleMatch ? titleMatch[1] : null;
|
|
|
|
const imgMatch = content.match('<img src="([^"]+)"[^>]*>');
|
|
|
|
const img = imgMatch ? imgMatch[1] : null;
|
2020-11-13 13:57:23 -08:00
|
|
|
|
|
|
|
return {
|
|
|
|
content,
|
|
|
|
title,
|
2020-11-13 14:09:18 -08:00
|
|
|
img,
|
2020-11-13 13:57:23 -08:00
|
|
|
}
|
|
|
|
} catch {
|
2020-11-29 02:03:01 -08:00
|
|
|
return {
|
|
|
|
content: null,
|
|
|
|
};
|
2020-11-13 13:57:23 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
head() {
|
|
|
|
return head({
|
|
|
|
title: this.title,
|
2020-11-13 14:09:18 -08:00
|
|
|
banner: this.img,
|
2020-11-13 13:57:23 -08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-01-01 15:24:51 -08:00
|
|
|
@import "assets/variables";
|
|
|
|
|
|
|
|
.blog-post {
|
|
|
|
img {
|
|
|
|
max-width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
figure {
|
|
|
|
width: 100%;
|
|
|
|
max-width: 24rem;
|
|
|
|
padding: $spacer;
|
|
|
|
img {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
figcaption {
|
|
|
|
font-size: $small-font-size;
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 13:57:23 -08:00
|
|
|
}
|
|
|
|
</style>
|