Table of Contents
1. Sveltkit project setup
Create a project
npm create svelte@latest app
Change adapter1 to adapter-static2.
To use SveltKit as a static site generator(SSG)3, use adapter-static.
Install with
npm i -D @sveltejs/adapter-static
Then add the adapter to your svelte.config.js:
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config {
kit: {
adapter: adapter({strict: false})
}
}
export default config
By default, adapter-static checks that either all pages and endpoints (if any) of your app were prerendered, or you have the fallback option set. This check exists to prevent you from accidentally publishing an app where some parts of it are not accessible, because they are not contained in the final output. If you know this is ok (for example, when a certain page only exists conditionally), you can set strict to false to turn off this check.
Install Mdsvex and configure.
Install with
npm i -D mdsvex
Add configuration file for mdsvex4. Name it mdsvex.config.js
import { defineMDSveXConfig as defineConfig } from 'mdsvex';
const config = defineConfig({
extensions: ['.svelte.md', '.md', '.svx'],
smartypants: {
dashes: 'oldschool'
},
remarkPlugins: [],
rehypePlugins: []
});
export default config;
Then add the mdsvex preprocessor to svelte.config.js with the configuration defined above.
import { mdsvex } from 'mdsvex';
import mdsvexConfig from './mdsvex.config.js';
const config = {
extensions: ['.svelte', ...mdsvexConfig.extensions],
preprocessors: [mdsvex(mdsvexConfig)]
};
export default config;
2. Github Pages setup.
Create a repository.
Create a repository and name it username.github.io, where username is your username(or organization name) on Github. If the first part of the repository doesn’t exactly match your username, it won’t work, so make sure to get it right.
Set git remote in the sveltkit application you made in the previous step.
git remote add origin https://github.com/username/username.github.io
Install gh-pages.
npm i -d gh-pages
Add deploy command in package.json file.
{
"scripts": {
"deploy": "vite build & gh-pages -d build -t true"
}
}
Run the deploy command
npm run deploy
References
- https://github.com/mvasigh/sveltekit-mdsvex-blog
- https://mdsvex.pngwn.io/docs#highlight
- https://kit.svelte.dev/docs/adapters#using-adapters
- https://github.com/sveltejs/kit/tree/main/packages/adapter-static
- https://mdsvex.pngwn.io/docs
- Before you can deploy your SvelteKit App, you need to adapt it for your deployment target. Adapters are small plugins that take the built app as input and generate output for deployment.↩
- Adapter for svelteKit apps that prerenders your entire site as a collection of static files. It’s also possible to create an SPA with it by specifying a fallback page which renders an empty shell. If you’d like to prerender only some pages and not create an SPA for those left out, you will need to use a diffrent adapter together with the prerender option.↩
- Static site generators(SSGs) are software engines that use text input files (such as Markdown, reStructuredText, AsciiDoc and JSON) to generate static web pages. Static sites generated by static sites generators do not require a backend after site generation, making them first-class citizens on content delivery networks(CDN). Some of the most popular static site generators are JeKyll, Hugo, NextJS. SSGs are typically for rarely-changing, informative content, such as product pages, new articles, software documentations and blogs.↩
- mdsvex is a markdown preprocessor for Svelte components. Basically MDX for Svelte. This preprocessor allows you to use Svelte components in your markdown, or markdown in your Svelte components. mdsvex supports all Svelte syntax and almost all markdown syntax.↩