Skip to content

Instantly share code, notes, and snippets.

@Ladvace
Created October 31, 2021 11:21
Show Gist options
  • Save Ladvace/75464773534c4a7be1b4f67ec3f1ce75 to your computer and use it in GitHub Desktop.
Save Ladvace/75464773534c4a7be1b4f67ec3f1ce75 to your computer and use it in GitHub Desktop.
<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