Create a blog with Sapper & Markdown Joshua Nussbaum on March 28, 2020 Sapper is a toolkit for creating Svelte apps. It comes with a bunch of conventions baked in to help you get your project up and running quickly. I... Read full post Submit Preview Dismiss Collapse Expand Joshua Nussbaum Joshua Nussbaum Joshua Nussbaum Follow Human debugging the machines. Location Montreal, Canada Joined Mar 6, 2019 • Mar 28 '20 • Edited on May 1 • Edited Dropdown menu Copy link Hide Bonus: I've added a few branches to the repo Syntax highlighting: sample-blog#code-highlighting Tags: sample-blog#tags Collapse Expand Johan Johan Johan Follow Joined Apr 23, 2020 • Apr 28 '20 Dropdown menu Copy link Hide This helped me! Do you know a way to wrap images from markdown in figure, not p? Collapse Expand Joshua Nussbaum Joshua Nussbaum Joshua Nussbaum Follow Human debugging the machines. Location Montreal, Canada Joined Mar 6, 2019 • May 1 '20 Dropdown menu Copy link Hide Glad it helped :) I think the p tag comes from having an empty line before defining the image. It's not the image that causes the p tag. One workaround is to <figure> tag inside markdown. HTML tags are allowed in markdown. Otherwise you'll have to look at modifying the markdown parser, or finding one that has a configurable option for this. Collapse Expand Johan Johan Johan Follow Joined Apr 23, 2020 • May 1 '20 Dropdown menu Copy link Hide Well the p tag will wrap either only the image, or the image and other inline elements. Thanks. I was guessing I had to find another parser. markdown-it seems like the most active -- plugin wise ... Joshua Nussbaum Joshua Nussbaum Joshua Nussbaum Follow Human debugging the machines. Location Montreal, Canada Joined Mar 6, 2019 • May 1 '20 Dropdown menu Copy link Hide Welcome. Try forking the markdown rollup plugin and switching showdown to markdown-it. That should do it. Collapse Expand renato ricco renato ricco renato ricco Follow Graphic designer & front-end developer. Location São Paulo - Brasil Joined Jan 12, 2018 • Mar 28 '20 Dropdown menu Copy link Hide Any suggestion for pagination? Its one of most basic features of a Blog. Collapse Expand Joshua Nussbaum Joshua Nussbaum Joshua Nussbaum Follow Human debugging the machines. Location Montreal, Canada Joined Mar 6, 2019 • Mar 28 '20 • Edited on Mar 28 • Edited Dropdown menu Copy link Hide That is true, pagination is important. Here's one way to do it: 1) Group posts into pages/chunks inside src/posts.js // 10 posts per page export const pages = _.chunk(posts, 10) Enter fullscreen mode Exit fullscreen mode 2) Inside routes/index.svelte, define a preload function that looks at the query params: <script context="module"> import {pages} from '../posts' export function preload(page) { const index = +(page.query.page || 1) return { posts: pages[index-1], hasMore: pages.length > index + 1, page: index } } </script> <script> export let posts, hasMore, page </script> Enter fullscreen mode Exit fullscreen mode 3) Add conditional next & previous links {#if page > 1} <a href="/?page={page-1}">Previous</a> {/if} {#if hasMore} <a href="/?page={page+1}">Next</a> {/if} Enter fullscreen mode Exit fullscreen mode Hope that helps! Collapse Expand renato ricco renato ricco renato ricco Follow Graphic designer & front-end developer. Location São Paulo - Brasil Joined Jan 12, 2018 • Mar 28 '20 Dropdown menu Copy link Hide Nice! Thank you, Collapse Expand Arsalan Ahmed Yaldram Arsalan Ahmed Yaldram Arsalan Ahmed Yaldram Follow 🚀 Full Stack JavaScript Developer passionate about crafting solutions with React, Node, TypeScript, and GraphQL. Let's innovate together! 👨💻✨ Email arsalanyaldram0211@outlook.com Location Pune, Maharashtra, India Work Tech Lead at Publicis Sapients Joined Sep 13, 2019 • Mar 28 '20 Dropdown menu Copy link Hide Thanks subscribed. Collapse Expand Irshad Ali Irshad Ali Irshad Ali Follow Hello! 👨💻 I am Irshad Ali Developer Based on Hyderabad,India Location Hyderabad Education Electronic Communication Engineering Work Full Stack Developer Joined Oct 12, 2019 • Jan 28 '21 Dropdown menu Copy link Hide Can we do this same without sapper. Collapse Expand Joshua Nussbaum Joshua Nussbaum Joshua Nussbaum Follow Human debugging the machines. Location Montreal, Canada Joined Mar 6, 2019 • Jan 29 '21 Dropdown menu Copy link Hide Yes. Though sapper and it's replacement svelte-kit make it easier. One way is to create a vanilla svelte project with a router (tinro?). Then make sure your hosting rewrites routes like /posts/... to /index.html. Code of Conduct • Report abuse
Bonus: I've added a few branches to the repo
This helped me! Do you know a way to wrap images from markdown in
figure, notp?Glad it helped :)
I think the
ptag comes from having an empty line before defining the image. It's not the image that causes theptag.One workaround is to
<figure>tag inside markdown. HTML tags are allowed in markdown.Otherwise you'll have to look at modifying the markdown parser, or finding one that has a configurable option for this.
Well the
ptag will wrap either only the image, or the image and other inline elements.Thanks. I was guessing I had to find another parser. markdown-it seems like the most active -- plugin wise ...
Welcome.
Try forking the markdown rollup plugin and switching
showdowntomarkdown-it. That should do it.Any suggestion for pagination? Its one of most basic features of a Blog.
That is true, pagination is important.
Here's one way to do it:
1) Group posts into pages/chunks inside
src/posts.js2) Inside
routes/index.svelte, define apreloadfunction that looks at the query params:3) Add conditional next & previous links
Hope that helps!
Nice! Thank you,
Thanks subscribed.
Can we do this same without sapper.
Yes. Though sapper and it's replacement svelte-kit make it easier.
One way is to create a vanilla svelte project with a router (tinro?). Then make sure your hosting rewrites routes like
/posts/...to/index.html.