This web was build with SvelteKit, Typescript and Tailwind CSS. The easiest choice was Tailwind CSS it is just awesome and easy to use CSS framework with really nice documentation. The choice of Typescript was based on that I am using Typescript on backend on my other project OpenRMM and I don’t like JS (who does?…right?…) but right now, during development of the personal web, Typescript in small mostly frontend project looks more like a chore.
Now, the hardest choice was the frontend framework. I chose SvelteKit. You asking why not React/Next.js or other bigger frameworks? Well, I am not a web dev I am just hobbyist, I did some research about the most popular frameworks, React and Vue.js come really often but they look huge and kinda complicated. Then I found Svelte and SvelteKit (check this if you want to know the difference). It has really nice enthusiastic community and it was often described as “easier” framework to work with. So I checked few tutorials on YT and I really liked it. So I started with instructions bellow.
In the terminal I did run there commands to create new project (you need to have node.js and NPM installed). Check this how to install & update Node.
npx degit sveltejs/template my-svelte-project
cd my-svelte-project
node scripts/setupTypeScript.js
npm install
npm run dev
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init tailwind.config.cjs -p
mv postcss.config.js postcss.config.cjs
module.exports = {
content: ['./src/**/*.{html,js,svelte,ts}'],
theme: {
extend: {}
},
plugins: []
};
Svelte Kit was simple to begin use, just update your index.svelte and create your components in src/lib/components/
folder.
There is a lot of tutorials and how to start with SvelteKit but also there are two big buts.
So SvelteKit is one awesome framework to build webpages in but is still in development. So be warned.
Typescript is JavaScript with types (well a little more but that is the important part). I like TS, it is somewhat familiar to C# that I used a lot for my “fun” projects in past and it doesn’t have the weird stuff from JS so it was must for me.
But then I found out, that for this little project, that has minimum of code, the strongly typed nature of TS is for frontend work is more burden than blessing. So yea, I am going stick with it but I am still questioning it’s usefulness.
My goal when building the blog for the web was to use Markdown for the posts so I won’t have to write all the time html or svelte code. So now I just create new .md file to create new blog post.
All of that is possible thanks to mdsvex, a preprocessor to automagically convert .md files to Svelte to be compiled by SvelteKit itself. It works flawlessly.
Disclaimer: code below is just quick overview. Not how this page is implemented. for a really nice (and updated) tutorial checkout Josh Collinsworth blog.
npm install -D mdsvex
import preprocess from 'svelte-preprocess';
import { mdsvex } from 'mdsvex';
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: ['.svelte', '.md'],
preprocess: [
preprocess(),
mdsvex({
extensions: ['.md'],
layout: {
blog: 'src/routes/blog/post.svelte'
}
})
],
kit: {
// hydrate the <div id="svelte"> element in src/app.html
prerender: {
crawl: true,
entries: ['*']
}
}
};
export default config;
This config will use post.svelte
as a template for our posts that have structure like this:
/src/blog/<name-of-the-first-post>/+post.md
/src/blog/<name-of-the-second-post>/+post.md
etc...
<script lang="ts">//variables filled in header part of .md file
export var title, date, img;
</script>
<svelte:head>
<title>{title}</title>
</svelte:head>
<div>
<!--use the metadata from .md header to build info about the blogpost (be creative here)-->
<img src="{img}" />
<!--little bit of Tailwind to arrange items under each other-->
<div class="flex flex-col">
<h1>{title}</h1>
<h3>{date}</h3>
<!--here our .md compiled to Svelte will go-->
<slot />
</div>
</div>
---
title: Title of you blog post
date: '2022-2-22'
img: /media/blog/interesting-image.jpg
---
## Main body
of the _blog post_
Now you have your blog ready.
Probably I would try to use some more established frontend framework. Don’t get me wrong Svelte and SvelteKit is awesome and is getting to be released somewhat soon (I am writing this for like 6 months so it will be probably out when I am finished…). But, so many hours I spend on build failures and I just don’t wan’t to any more.
Probably Next.js. I heard so much good about it and while it’s not the new hotness on the market, that means (or at lease I hope) it’s much more stable and not compatibility braking with each update.
Yes and No. Yes, for some bigger project with backend API to have everything safely typed. But no, not for something like this, this personal page.
I am running this page on Netlify. They have extremely generous free tier and implementation was cakewalk. Just quick note: when deploying from GitHub (use different branches…duh) wait for the build of your pull request by Netlify bot to verify that after you push changes your page will be correctly working after update. It is just nice workflow.