41
loading...
This website collects cookies to deliver better user experience
git clone https://github.com/rodneylab/sveltekit-blog-mdx.git sveltekit-tutorial
cd sveltekit-tutorial
pnpm install
cp .env.EXAMPLE .env
pnpm run dev
src/lib/styles/styles.scss
and src/lib/styles/variables.scss
. Styles propagate globally from there. This makes it easy to update the site's styling. Let's start by changing the colours up. Edit src/lib/styles/variables.scss
:// Colours
$color-theme-1: #e63946; // imperial red
$color-theme-2: #a8dadc; // powder blue
$color-theme-3: #457b9d; // celadon blue
$color-theme-4: #1d3557; // prussian blue
$color-primary: #005b99;
$color-text: #0d1821; // rich black FOGRA 29
$color-heading: $color-theme-4;
$color-heading-black: $color-theme-4;
$color-accent: #f1faee; // honeydew
$color-success: #2ec4b6; // tiffany blue
$color-danger: #e71d36; // rose madder
src/lib/styles/styles.scss
ends up looking like this:h1 {
margin-top: 0;
font-weight: $font-weight-black;
font-size: $font-size-6;
color: $color-heading-black;
}
BlogPostSummary
and Card
components:...
<span id={idString} aria-hidden="true" class="read-more-text">Read more {H_ELLIPSIS_ENTITY}</span>
</div>
</div>
.content {
width: 100%;
border-radius: $spacing-2;
margin: $spacing-0 auto;
padding: $spacing-4 $spacing-0;
h3 {
margin: $spacing-0 $spacing-2;
}
p {
color: $color-theme-3;
font-size: $mobile-font-size-2;
margin: $spacing-2;
}
.read-more-text {
margin: $spacing-2;
}
}
.content:hover {
h3 {
color: $color-accent;
}
p {
color: $color-theme-2;
}
.content {
width: 100%;
background-color: $color-theme-2;
border-radius: $spacing-1;
margin: $spacing-0 auto;
padding: $spacing-4;
}
src/routes/index.svelte
. We're changing up the title and restyling the “About Me” card:<header>
<h1>My Film Photography Blog</h1>
</header>
<Card>
<div class="card">
<h2><span>About me</span></h2>
<p>
I live and breathe analogue photography. I show you my favourite analogue film cameras on this
site. Hopefully if you are not into analogue photography yet, some of my enthusiasm will rub off
onto you.
</p>
</div>
</Card>
<BlogRoll {posts} />
<style lang="scss">
.card h2 { margin-top: $spacing-0; }
</style>
pnpm uninstall @fontsource/lora @fontsource/source-sans-pro
pnpm install @fontsource/slabo-27px
// Fonts
$font-family-serif: 'Lato', 'Lustria', 'Noto Serif', 'Merriweather', 'Georgia', 'Cambria',
'Times New Roman', 'Times', serif;
$font-body: $font-family-serif;
$font-heading: 'Slabo 27px', $font-family-serif;
src/routes/__layout.svelte
), we will import fonts there removing the original import:<script>
// Lato - supported variants:
// weights: [100, 300, 400, 700, 900]
// styles: [italic, normal]
import '@fontsource/lato/400.css';
// Slabo 27px - supported variants:
// weights: [400]
// styles: [normal]
import '@fontsource/slabo-27px/400.css'
...
Heading
component. Make a new file at src/lib/components/Heading.svelte
:<script>
import LinkIcon from '$lib/components/Icons/Link.svelte';
export let id;
$: showLink = false;
const handleMouseEnter = (event) => {
showLink = true;
}
const handleMouseLeave = (event) => {
showLink = false;
}
</script>
<h2
{id}
on:mouseenter={handleMouseEnter}
on:mouseleave={handleMouseLeave}
>
<slot />
{#if showLink}
<a href={\`#\${id}\`}>
<LinkIcon />
</a>
{/if}
</h2>
id
will be supplied by the component consumer. We label out heading with that id
. Because of that, the browser knows where to scroll when we specify that id
in the anchor element.src/lib/components/Icons/Link.svelte
and give it the following content to import the corresponding Feather icons icon:<script>
import { DEFAULT_ICON_SIZE } from './index.js';
import LinkIcon from 'svelte-feather-icons/src/icons/LinkIcon.svelte';
export let size = DEFAULT_ICON_SIZE;
</script>
<LinkIcon {size} />
src/routes/best-medium-format-camera-for-starting-out/index.md
. The file is a little messy, with a lot of front matter because of a temporary workaround for the Netlify adapter. That aside, let's import and use the Heading element:<script>
import ExternalLink from '$lib/components/ExternalLink.svelte';
import Heading from '$lib/components/Heading.svelte';
import Link from '$lib/components/Link.svelte';
</script>
<Heading id="whatIsAMediumFormatCamera">What is a Medium Format Camera? </Heading>
...