This repository has been archived by the owner on Dec 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_slug.vue
64 lines (55 loc) · 1.7 KB
/
_slug.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<template>
<article v-html="parsedMD"></article>
</template>
<script lang="ts">
/**
*
* Hooo boy it's a mess in here...
* Cant decide if I should be parsing the markdown or just use the body_html
*
* using markdown I have more control but need to work out how to process the shortcode
* using the html everything has been processed but need to figure out how to use highlight.js to style the code blocks
*
*/
import Vue from 'vue'
import unified from 'unified'
import markdown from 'remark-parse'
import remark2rehype from 'remark-rehype'
import format from 'rehype-format'
import html from 'rehype-stringify'
import report from 'vfile-reporter'
// import hljs from 'highlight.js'
// import 'highlight.js/styles/default.css'
// import javascript from 'highlight.js/lib/languages/javascript'
// import 'highlight.js/styles/github.css'
// hljs.registerLanguage('javascript', javascript)
// import javascript from 'highlight.js/lib/languages/javascript'
// hljs.registerLanguage('javascript', javascript)
export default Vue.extend({
async asyncData({ params, $axios }) {
const post: DevTo.ArticleBySlug = await $axios.$get(
'https://dev.to/api/articles/chiubaca/' + params.slug
)
let parsedMD
unified()
.use(markdown)
.use(remark2rehype)
.use(format)
.use(html)
.process(post.body_markdown, function (err, file) {
console.error(report(err || file))
// console.log(String(file))
parsedMD = String(file)
})
// const highlightedHTML = hljs.highlightAuto(post.body_html)
// console.log('Highlighes', highlightedHTML.value)
return {
parsedMD,
post,
// highlightedHTML,
}
}
})
</script>
<style scoped>
</style>