Created
October 31, 2021 11:21
-
-
Save Ladvace/75464773534c4a7be1b4f67ec3f1ce75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script context="module"> | |
export async function load({ fetch, page }) { | |
let article; | |
try { | |
// here we are gonna fetch the single article by id | |
article = await fetch(`https://dev.to/api/articles/${page.params.slug}`); | |
article = await article.json(); | |
} catch (e) { | |
console.log(e); | |
} | |
return { | |
props: { | |
article | |
} | |
}; | |
} | |
</script> | |
<script> | |
export let article; | |
</script> | |
<div class="articleContainer"> | |
<div class="article"> | |
<h1>{article.title}</h1> | |
// you can "parse" HTML with svelte like that | |
// https://svelte.dev/docs#html | |
{@html article.body_html} | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment