• Stars
    star
    269
  • Rank 151,801 (Top 4 %)
  • Language Svelte
  • License
    BSD 3-Clause "New...
  • Created over 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SvelteKit MDX starter blog with MDsveX (Svelte in markdown)

Rodney Lab sveltekit-blog-mdx Github banner

Rodney Lab logo

SvelteKit MDsvex Blog Starter

Netlify Status

sveltekit-blog-mdx

Open in Visual Studio Code

SvelteKit blog starter to help you get going on your next Svelte blog site. The project creates a Progressive Web App (PWA) out of the box. You just need to customise with your logos etc.

Rodney Lab sveltekit-blog-mdx Github banner

See the Sveltekit Blog Starter blog post on the Rodney Lab site for some explanation of what's inside and how to customise. Please drop questions into a comment at the bottom of that page.

Here's the quick start:

Everything you need to build a Svelte blog site, powered by sveltekit-blog-mdx.

Creating your Own MDsveX Blog Site

If you're seeing this, you've probably already done this step. Congrats!

git clone https://github.com/rodneylab/sveltekit-blog-mdx.git my-new-mdsvex-blog
cd my-new-mdsvex-blog
pnpm install # or npm install
npm run dev

Responsive Images

The starter creates and caches responsive images using the vite-imagetools plugin. This is straightforward to use when you know ahead of time which image you want to include. You just import it on the page you want to use it on:

import featuredImageSrc from '$lib/assets/home/home.jpg';

The vite-imagetools plugin will then generate and hash the image. See examples in src/routes/index.svelte.

The example where you want to have a different featured image for each blog post is a little more complicated, though manageable. In this case, you can run a script (see generate-responsive-image-data.js) to iterate though all blog posts, taking the featured image from the blog post front matter. This script can then output the necessary imports into a generated JavaScript file, one for each blog post (see src/lib/generated directory). Finally you can dynamically import that JavaScript file in the blog template load function.

To run the included script at the command like type:

pnpm run gen:images

This should be done each time you add new blog posts. It also generates a low resolution placeholder, to minimise Content Layout shift during page load.

For the script to find your blog post images, add them under the src/lib/assets/blog folder. In that folder, create a new folder whose name matches the post slug and add the images to the new folder. The name of the file needs to match the name you use is the post frontmatter (for featuredImage, for example).

The script may need some tweaking for your use case. Let me know how it can be improved.

XML Sitemap

  • The XML sitemap gets generated in the server route src/routes/sitemap.xml/+server.js. Tweak this file to adjust output.

Make sure your site's URL is defined in .env as the PUBLIC_SITE_URL variable so the correct URLs are output to the site map.

Progressive Web App (PWA)

The starter mostly generates PWA config automatically, including service worker for offline availability and adding meta to the HTML head section. A PWA needs a manifest file detailing logos (for favicons) in different sizes, compatible with various devices. You will need to generate a set of icons in assets/:

  • apple-touch-icon.png
  • favicon.ico
  • icon.svg
  • icon-192.png
  • icon-512.png

You can use free open source tools to generate and optimise these from an input SVG. That resource includes a shell script you can run to automate generation.

The HTML meta for PWAs is added in the component at src/lib/components/PWA.svelte.

You can customise the manifest (including icon file path) by editing src/lib/config/website.js. The following variables feed into the generated manifest.json file:

  • siteTitle,
  • siteShortTitle,
  • siteUrl,
  • backgroundColor,
  • themeColor.

See article on Progressive Web Apps in SvelteKit for more.

Building

npm run build

You can preview the built app with npm run preview, regardless of whether you installed an adapter. This should not be used to serve your app in production.

What's inside?

.
├── README.md
├── generate-responsive-image-data.js
├── jsconfig.json
├── netlify.toml
├── package.json
├── src
│   ├── app.html
│   ├── content
│   │   └── blog
│   │       ├── best-medium-format-camera-for-starting-out
│   │       ├── folding-camera
│   │       └── twin-lens-reflex-camera
│   ├── global.d.ts
│   ├── hooks.server.js
│   ├── lib
│   │   ├── assets
│   │   │   ├── blog
│   │   │   └── home
│   │   ├── components
│   │   │   ├── BannerImage.svelte
│   │   │   └── ...
│   │   ├── config
│   │   │   └── website.js
│   │   ├── constants
│   │   │   └── entities.js
│   │   ├── generated
│   │   │   └── posts
│   │   ├── styles
│   │   └── utilities
│   │       ├── blog.js
│   │       ├── file.js
│   │       └── image.js
│   ├── routes
│   │   ├── +error.svelte
│   │   ├── +layout.js
│   │   ├── +layout.svelte
│   │   ├── +page.js
│   │   ├── +page.svelte
│   │   ├── [slug]
│   │   │   ├── +layout.svelte
│   │   │   ├── +page.js
│   │   │   └── +page.svelte
│   │   ├── contact
│   │   │   └── +page.svelte
│   │   ├── manifest.webmanifest
│   │   │   └── +server.js
│   │   └── sitemap.xml
│   │       └── +server.js
│   └── service-worker.js
├── static
│   ├── assets
│   ├── favicon.png
│   ├── icon.svg
│   ├── robots.txt
│   └── sitemap.xml
└── svelte.config.js

src/content

  • The src/content/blog is where we need to put our blog posts. Just clean out the sample content and replace it with your views on the world! There is a separate folder for each post, which allows you to keep images, video and other related media specific to a post better organised. We set the browser path from this folder name, so keep that in mind when naming the folders. Write the actual post in a file called index.md within post's folder. Although the file has an .md extension, you can write Svelte in it.

src

  • hooks.server.js we define Content Security Policy (CSP) and other HTTP security headers in here, effective for server side rendered apps. See post on SvelteKit static site HTTP headers to see how to set up CSP etc for static sites.

src/components

  • src/lib/components these are the components we use in pages.

src/lib

  • src/lib/config/website.js for convenience we define properties for the site here such as the site title, contact email addresses and social media accounts. Some properties feed from environment variables. See a post on getting started with SvelteKit for more on environment variables in SvelteKit.

  • src/lib/styles does what you expect! We use SCSS for styling and source self-hosted fonts in the layouts.

src/utilities

  • src/utilities/blog.js this file contains some code for helping us transform the markdown in blog posts to Svelte. As well as that they help extract fields in the frontmatter (this is the metadata we include at the top of the blog post index.md files).

src/routes

  • src/routes/[slug]/+page.js this is essentially a template for blog post data. One of these files is generated at build for each blog post. It is used to extract data needed in the Svelte file used to generate the post's HTML.

  • src/routes/[slug]/+page.svelte similarly to the previous file, one of these is generated for each blog post. This time it is the Svelte code which SvelteKit uses to generate the HTML and JavaScript for our blog posts.

I mention most of the other files in the Getting Started with SvelteKit blog post, but let me know if I have missed anything which needs more explanation.

Feel free to jump into the Rodney Lab matrix chat room.

More Repositories

1

sveltekit-components

Handy components for building sites in SvelteKit
Svelte
59
star
2

sveltekit-seo

Demo site for SvelteKit SEO showing how to set up meta tags in a SvelteKit blog site.
Svelte
48
star
3

astro-blog-markdown

Starter for a fast Astro blog using Markdown and a spot of Svelte
Svelte
30
star
4

sveltekit-image-plugin

SvelteKit demo code for using vite-imagetools to add cached, responsive, Next-Gen images to a SvelteKit site with no cumulative layout shift.
Svelte
29
star
5

parsedown

WASM code for parsing Markdown into HTML with light output tweaking
Rust
17
star
6

sveltekit-graphql-fetch

SvelteKit GraphQL queries using fetch only: how you can drop Apollo client and urql dependencies altogether to make your Svelte app leaner.
TypeScript
16
star
7

astro

Code to accompany Astro articles.
JavaScript
15
star
8

narcissus

API using PostgREST to query and update supabase database.
Rust
12
star
9

sveltekit-graphql-github

Use Apollo Client with SvelteKit to Query a GraphQL API: we use the GitHub API to query our repos and learn a bit of SvelteKit along the way.
Svelte
12
star
10

svelte-social-icons

Beautiful, easy SVG social icons in Svelte
TypeScript
11
star
11

svelte-ecommerce-site-start

SvelteKit eCommerce site: how to build a fast, SEO friendly, static eCommerce site using Svelte, Snipcart and Directus.
Svelte
10
star
12

sveltekit-shiki-code-highlighting

SvelteKit Shiki syntax highlighting: use any VSCode colour theme to accessibly syntax highlight code on your SvelteKit app with line numbers.
JavaScript
9
star
13

sveltekit-instagram-infinite-scroll

SvelteKit infinite scroll: see how you can use Svelte stores and a reactive function to implement an infinite scrolling Instagram feed.
Svelte
9
star
14

sveltekit-s3-multipart-upload

SvelteKit S3 Multipart Upload: how you can upload large files, such as video to your S3 compatible storage provider using presigned URLs.
JavaScript
9
star
15

cmessless

A markdown parser to output Astro markup
Rust
8
star
16

sveltekit-simple-image-gallery

Simple Svelte responsive image gallery: create a ribbon gallery, using Svelte dimension bindings to maintain the aspect ratio of all images.
JavaScript
7
star
17

open-source-favicon-generation

Open source favicon generation: create your favicon from scratch then optimise it for modern and legacy browsers using free apps in 2022.
Shell
7
star
18

sveltekit-hcaptcha-form

SvelteKit hCaptcha contact form: see how you can scare bots away from your Svelte site using a privacy focussed captcha service.
Svelte
7
star
19

sveltekit-json-import

SvelteKit JSON import: how you can use data provided from business apps and ther sources directly in your Svelte site, thanks to Vite.
Svelte
6
star
20

sveltekit-vanilla-extract

Using vanilla-extract with SvelteKit: how you can make zero-runtime stylesheets with the new TypeScript friendly preprocessor in Svelte.
TypeScript
6
star
21

sveltekit-session-cookies

SvelteKit session cookies: accessing user-specific data in your SvelteKit app use session and HttpOnly cookies for added security.
Svelte
5
star
22

narcissus-blog

Demo static Svelte site for narcissus backendless blog
Svelte
5
star
23

fastify-mercurius-nexus-graphql-api

GraphQL API demo using Fastify, Mercurius and Nexus
TypeScript
5
star
24

svelte-chartjs

Svelte Charts: how quickly and easily you can add customised charts to your SvelteKit, Astro or other Svelte apps with Chart.js.
Svelte
5
star
25

sveltekit-faq-page-seo

SvelteKit FAQ Page SEO: how you can use ❤️ Svelte's SEO friendliness to create a FAQ page with JSON-LD SchemaOrg SEO meta loved by Google.
Svelte
5
star
26

blocklists

A simple repo for analysis of online firewall block lists and combining them efficiently into a block list for use in a firewall
Python
5
star
27

sveltekit-content-security-policy

SvelteKit Content Security Policy: how you can add CSP to reduce your Svelte site's cross-site scripting (XSS) attack surface.
Svelte
5
star
28

sveltekit-accessibility-testing

Demo code for adding axe accessibility testing to SvelteKit using Playwright and pa11y
Svelte
4
star
29

cistercian-clock

Rust
4
star
30

sveltekit-intersection-observer

Demo code to show how to use the Intersection Observer API in Sveltekit to help track page views
Svelte
4
star
31

sveltekit-iconify

Demo showing how to add SVG icons from just about any library to your Svelte app using a single extra dependency
Svelte
4
star
32

sveltekit-map-component

Handy components for building sites in SvelteKit
Svelte
4
star
33

sveltekit-session-storage

SvelteKit Session Storage: how you can improve UX by temporarily caching user form entries then repopulating fields on browser refreshes.
Svelte
4
star
34

sveltekit-local-storage

Using Local Storage in SvelteKit: taking the example of setting a site theme, explore how to combine the Local Storage and Svelte Store APIs.
TypeScript
4
star
35

rodneylab

Rodney Lab Git Hub profile
3
star
36

hcaptcha-serverless-rust-worker

Demo code for creating an hCaptcha verify endpoint using Cloudflare Workers written in Rust
Rust
3
star
37

gatsby-starter-climate

Gatsby 3 MDX blog starter for an accessible, fast and secure blog site
JavaScript
3
star
38

raylib-flecs-imgui-introspection

Using Jolt with Flecs & Dear ImGui 👀 to add game physics introspection to a raylib game, with pause and stepping for dev tools debugging 🐜.
CMake
3
star
39

decisive

front end for site admin
Svelte
3
star
40

upstash-astro

Get Started with Astro and Redis Tutorial Starter Code
Svelte
3
star
41

svelte-login-form

Svelte login form example 📝 signup and login forms for your Svelte app with password strength meter 🔐 and strong password auto generation.
Svelte
3
star
42

jolt-raylib-hello-world

Jolt Physics raylib ⚡️ trying Jolt C++ game development physics library with raylib in a 3D hello world 🎱 bouncing sphere example.
CMake
3
star
43

deno

Code to accompany Deno & Deno Fresh articles.
3
star
44

svelte-each

Using Svelte each blocks: how to loop on array-like objects in Svelte + simplify your code using const & style directives and destructuring.
Svelte
3
star
45

sveltekit-form-example

SvelteKit form example 📝 code to get a contact form working with SvelteKit actions, and 10 tips to avoid common pitfalls 🍀
CSS
2
star
46

gatsby-cloud-functions-recaptcha

Example site showing how Gatsby Cloud Functions can be used with an accessible reCAPTCHA.
JavaScript
2
star
47

stylelint-sveltekit

Stylelint for SvelteKit: keep you Svelte code consistent and make sure your CSS and SCSS code follows your team's style guide to the letter!
Svelte
2
star
48

raylib-imgui

Using raylib with Dear ImGui: how you can use Dear ImGui to create an immediate mode 🐜 debugging interface for your CMake raylib game 🎮
CMake
2
star
49

upstash-redis-deno-perf

Upstash for Redis and the Performance API: measuring performance gains with Web APIs to deploy the database optimally in your Deno app.
TypeScript
2
star
50

sveltekit-share-buttons

Svelte share buttons: adding social share buttons to your Svelte app for mobiles and Safari using the native Web Share API with fallbacks.
Svelte
2
star
51

sveltekit-css-hover-image-slider

SvelteKit CSS only :hover image slider
Svelte
2
star
52

knights-to-see-you

Godot Rust 2D Platform game
Rust
2
star
53

sveltekit-fido-u2f-login

SvelteKit FIDO U2F login: how you can add multi factor authentication (MFA) to the front end of your Svelte app for added login security.
Svelte
2
star
54

sveltekit-fontaine

SvelteKit Fontaine ✍🏽 how to eliminate or reduce font swap cumulative layout shift working with custom, self-hosted fonts in ❤️ SvelteKit.
CSS
2
star
55

sveltekit-graphql-client

SvelteKit demo for running ApolloClient
JavaScript
1
star
56

gatsby-site-search

Fast JS Search on Gatsby: Roll Your Own Site Search: Demo site
JavaScript
1
star
57

sveltekit-lint-css

SvelteKit CSS stylelint: how you can lint vanilla CSS within your Svelte source files using stylelint accessibility and best practice rules.
Svelte
1
star
58

sveltekit-netlify-functions

Demo site showing how to use Netlify functions with SvelteKit
Svelte
1
star
59

moment

Back end app using Fastify and Mercurius to create a GraphQL API. Uses PostgreSQL db with Prisma.
TypeScript
1
star
60

gatsby-functions-fauna

A demo site to show how the Fauna data API can be used with Gatsby Cloud Functions.
JavaScript
1
star
61

astro-server-side-rendering

Astro Server-side Rendering: getting started with Astro SSR building a productivity search app with Vitest and Edge geolocation data
Astro
1
star
62

rainbow

Rainbow — Accessibility Contrast Tool for Text on Images
JavaScript
1
star
63

sveltekit-lazyload-iframe

SvelteKit demo code for responsive lazy loading iframes.
Svelte
1
star
64

markwrite

Markdown writing CLI tool
Rust
1
star
65

sveltekit-typescript-vanilla-extract-starter

SvelteKit TypeScript vanilla-extract starter: create a markdown blog site with responsive, Next-Gen images, PWA and vanilla-extract styles.
Svelte
1
star
66

mux-webhook-worker

Cloudflare Rust Worker which listens for mux video upload events
Rust
1
star
67

serverless-rust

Code to accompany Serverless Rust articles.
JavaScript
1
star
68

arkanoid-clone

Arkanoid clone built in C++ with Raylib and flecs
C++
1
star
69

sveltekit-s3-compatible-storage

SvelteKit S3 compatible storage: how you can upload files to your cloud storage provider from your Svelte app using presigned URLs.
Svelte
1
star
70

learn-web-gpu

C++
1
star
71

macroquad-egui

Macroquad egui DevTools: adding a visual 🐞 debugging user interface for developers to Rust Macroquad game using ⚡️ egui.
Rust
1
star
72

sveltekit-ably-realtime-game

SvelteKit Ably: introduction to using Svelte with Ably and building a real-time ♟️ game or instant 💬 chat with serverless WebSockets.
Svelte
1
star
73

dungeoncrawl

Rust dungeon crawler game using Bevy ECS
Rust
1
star
74

sveltekit-tooling

SvelteKit tooling: we look at 7 tools you can add to streamline your Svelte continuous integration (CI) and development processes.
Svelte
1
star
75

rodneylab-100-days-of-gatsby

Gatsby 100 Days of Code 2021
JavaScript
1
star