<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jacob Stordahl</title>
    <description>The latest articles on DEV Community by Jacob Stordahl (@stordahl_).</description>
    <link>https://dev.to/stordahl_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F381701%2F1402927e-b992-47be-948c-29aa7834c63a.jpg</url>
      <title>DEV Community: Jacob Stordahl</title>
      <link>https://dev.to/stordahl_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stordahl_"/>
    <language>en</language>
    <item>
      <title>Svelte Tutorial: Make a blog with Sapper</title>
      <dc:creator>Jacob Stordahl</dc:creator>
      <pubDate>Wed, 10 Mar 2021 19:23:35 +0000</pubDate>
      <link>https://dev.to/sanity-io/svelte-tutorial-make-a-blog-with-sapper-5po</link>
      <guid>https://dev.to/sanity-io/svelte-tutorial-make-a-blog-with-sapper-5po</guid>
      <description>&lt;h1&gt;
  
  
  Svelte Tutorial: Make a Blog with Sapper
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;How to build a markdown blog with Svelte, Sapper, &amp;amp; Sanity&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction to Svelte, Sapper &amp;amp; Sanity
&lt;/h2&gt;

&lt;p&gt;Within the vast landscape of Javascript frameworks, Svelte has transformed from the new kid on the block to a serious competitor to other frameworks. This is largely due to Svelte's bold approach to front-end Javascript development &amp;amp; it's community-driven nature. Originally released in 2016 by its original author Rich Harris, Svelte's primary difference from other Javascript frameworks is that Svelte includes a build step where any unused HTML, CSS, &amp;amp; JS is striped away. The release of Svelte version 3 in early 2019 brought an entire rebuild of reactivity which, in turn, reduced the complexities of component state &amp;amp; overall made Svelte's syntax even more approachable. &lt;/p&gt;

&lt;p&gt;The characteristic that sets Svelte apart from its peers is how accessible the code is. As Rich will frequently mention, this "Javascript" framework is technically a compiler that transforms a superset of HTML into HTML, CSS, &amp;amp; Javascript we can run in the browser, no runtime library needed. This allows the syntax to read &amp;amp; feel just like a vanilla web stack, with just a dash of framework. If we compare Svelte syntax to other frameworks like React or Vue, you'll see the latter two are undeniably Javascript. They both render components with JS functions unlike Svelte. Don't get me wrong, I love Javascript, but when we're building UIs for the web it's far more intuitive to think first of the structure, or HTML. Because Svelte is a compiler, we can build with components that are syntactically different than the Javascript output; giving us the ideal developer experience while outputting an app that is pure HTML, CSS, and Javascript. This syntax is very quick to learn for both seasoned Javascript developers and people who only know HTML &amp;amp; CSS, making it great for teams working in production or those still learning Javascript.&lt;/p&gt;

&lt;p&gt;The last advantage I will mention is this - because Svelte compiles away any unused code &amp;amp; doesn't utilize a client rendered library, the performance gains are astounding. Svelte apps are so small, some of Svelte's earliest adopters were companies building small IoT products, POS systems &amp;amp; other low power computing electronics that require user interfaces. Other companies currently using Svelte in production include The New York Times, Spotify, Ikea, Bloomberg, &amp;amp; Alaska Airlines. If you're not sold yet, you should also know that Svelte ranked highest for Satisfaction &amp;amp; Interest in the 2020 State of JS survey. &lt;/p&gt;

&lt;p&gt;If you've heard of Svelte you've likely also heard of Sapper, the application framework for Svelte. Sapper is to Svelte what Next.js is to React - even modeled in part after Next. Sapper brings features like file-based routing &amp;amp; static export to Svelte apps. This makes Sapper not only a great way to build web apps, but also websites; in our case, a blog. &lt;/p&gt;

&lt;p&gt;The data source for our blog will obviously be a Sanity back end connected through the Javascript Client provided by Sanity. Sanity's approach to content - treating it as data and allowing the end user to manipulate said data - makes Svelte a wonderful framework to pair with Sanity; especially in data-light use cases like a blog where all of our data fetching can happen in the browser. The other great things about structured content is that our entire CMS backend is built around Javascript object schemas. This means we can scaffold custom data types &amp;amp; CMS configurations in minutes, something I used to spend hours doing in other CMS solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building our Blog
&lt;/h2&gt;

&lt;p&gt;Before we get started, some prerequisites for following this tutorial are: you're comfortable using the command line, you have a solid understanding of HTML, CSS &amp;amp; Javascript, and have experience with node/npm. I'll do my best to explain everything that Svelte is handling in our app, but if you find yourself wanting to dig deeper, please consult the excellent tutorial at &lt;a href="http://svelte.dev" rel="noopener noreferrer"&gt;svelte.dev&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;This tutorial also assumes you have the latest versions of Node.js &amp;amp; npm installed, and that you have a Sanity account created.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Creating our Sanity Project
&lt;/h3&gt;

&lt;p&gt;The first step in building our Sanity powered blog is to get our Sanity project created. For this we will use the Sanity CLI. To install the CLI globally, run the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @sanity/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're then quickly going to scaffold the folder structure we need for our project. It will look something like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sanity-md
    &lt;span class="nt"&gt;--&lt;/span&gt; content
        our Sanity project lives here
    &lt;span class="nt"&gt;--&lt;/span&gt; web
        our Svelte/Sapper project lives here
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To achieve this structure, we'll first create our parent directory, and then our content directory. Feel free to name the parent directory anything you'd like. In your command line, run this command to create the parent directory and change into said directory...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;sanity-md &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;sanity-md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we'll create our content directory and change into it as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;content &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;content
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we're in the content directory we can run our first command with the Sanity CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sanity init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command does a few things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you aren't logged in to Sanity, you will be prompted to do so&lt;/li&gt;
&lt;li&gt;Creates a new Sanity project in your account&lt;/li&gt;
&lt;li&gt;Create sa dataset for said project&lt;/li&gt;
&lt;li&gt;Installs everything needed to run Sanity Studio locally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the purposes fo this tutorial, we're going to select the default blog schema offered to us in the CLI prompt. Once the Sanity project is created, let's open it up in our code editor to take a look at the blog schema Sanity gives us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--&lt;/span&gt; sanity-md
    &lt;span class="nt"&gt;--&lt;/span&gt; content
        &lt;span class="nt"&gt;--&lt;/span&gt; config
        &lt;span class="nt"&gt;--&lt;/span&gt; node_modules
        &lt;span class="nt"&gt;--&lt;/span&gt; plugins
        &lt;span class="nt"&gt;--&lt;/span&gt; schemas
        &lt;span class="nt"&gt;--&lt;/span&gt; static
        package.json
        README.md
        sanity.json
        tsconfig.json
        yarn.lock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only directory we're concerned with in our Sanity project right now is our schemas directory. Let's open it up...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--&lt;/span&gt; schemas
    author.js
    blockContent.js
    category.js
    post.js
    schema.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a Sanity project, each content type needs a schema defined. These schemas are then all imported by &lt;code&gt;schema.js&lt;/code&gt;, which is used to build the Sanity Studio. The main schema we're going to be concerned with in this tutorial is &lt;code&gt;post.js&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;document&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;slug&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Slug&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;slug&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;maxLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;96&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;author&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Author&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;reference&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;author&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mainImage&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Main image&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;hotspot&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;categories&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Categories&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;array&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;reference&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;category&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}}],&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;publishedAt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Published at&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;datetime&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blockContent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;

  &lt;span class="na"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;author.name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;media&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mainImage&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;selection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;selection&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assign&lt;/span&gt;&lt;span class="p"&gt;({},&lt;/span&gt; &lt;span class="nx"&gt;selection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;subtitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;author&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="s2"&gt;`by &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this schema we are defining the post content type and its fields, including a title, image, body, and a few other pieces of data, like the preview. The preview definition in our schema is how Sanity knows how to construct content previews. This isn't entirely pertinent to this article, but if you'd like to learn more, check the Sanity docs. Later on we'll look at using a Markdown input instead of the locally defined blockContent that comes with this predefined schema, but for now let's fire up our Sanity Studio and create a sample blog post! To run the sanity studio locally, just navigate back into the content directory and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sanity start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will compile our Sanity Studio and serve it locally at localhost:3333. Opening the studio, we can see we have three content types - Author, Post &amp;amp; Category. For now, we're just going to make a single sample post to build out our Sapper app with. Enter whatever content you like for this post and make sure to include data for every field except 'Author' &amp;amp; 'Category'. Since both of these need to be declared elsewhere in the studio first, we are going to leave them empty to keep it simple.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.sanity.io%2Fimages%2F81pocpw8%2Fproduction%2F71f3dc2ba3a65b2ff9d5b3a84238266ef18148a4-1454x949.png%3Fw%3D1280%26h%3D835%26fit%3Dclip%26auto%3Dformat" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.sanity.io%2Fimages%2F81pocpw8%2Fproduction%2F71f3dc2ba3a65b2ff9d5b3a84238266ef18148a4-1454x949.png%3Fw%3D1280%26h%3D835%26fit%3Dclip%26auto%3Dformat" alt="A look at the studio"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once your post is created, simply hit publish and then we can move onto the last step of our backend configuration. In order for our Sapper front end to be able to query our Sanity data source from the browser, we need to declare which URL is going to be making the requests or Sanity will throw a CORS error. This architecture allows us to create front end-first applications without worrying about bad actors getting our Sanity data. If the request isn't coming from a declared origin, an error will be thrown. To declare these allowed origins, navigate to &lt;a href="http://manage.sanity.io/" rel="noopener noreferrer"&gt;manage.sanity.io&lt;/a&gt; , open up the project you've created for this tutorial, and then navigate to Settings &amp;gt; API and then click "Add New Origin". Our Sapper app will be running locally at &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; so that's the URL we want to insert here. If and when you deploy your Sapper app, you'll need to add another origin for the URL where the app is deployed. &lt;/p&gt;

&lt;h3&gt;
  
  
  Part 2: Svelte &amp;amp; Sapper
&lt;/h3&gt;

&lt;p&gt;We've already covered the WHY of Svelte, so now let's dig into some code and see the HOW. A Svelte app consists of Svelte components in the form of .svelte files. The app will also have a root App.svelte which will be rendered by a &lt;code&gt;main.js&lt;/code&gt; file using the Svelte compiler. Here is the basic Structure of a Svelte component...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Component.svelte --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;world&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;{ hello }&lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;{ world }&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Tip: Svelte requires that all .svelte files are named with the first letter uppercase eg. MyComponent.svelte &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Svelte, the Javascript, HTML (template), and Styles are all handled at the component level &amp;amp; thus are scoped to that component. In the above example, we're defining two variables; 'hello' &amp;amp; 'world'. The &lt;code&gt;export&lt;/code&gt; in front of 'hello' defines this variable as a prop which will be passed down from a parent component. If no prop is passed when the component is rendered, it will use the default value we've defined to be 'hello'. We're then including these variables in our template, which is just regular HTML markup. To add dynamic data to our template, we just need to use single curly braces, like it is shown above. Due to Svelte's approach to reactivity, any time a value referenced in the template changes, this causes a re-render of the component. So if we wanted to create a button that can update the state variable world, we can do this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Component.svelte --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;!--&lt;/span&gt; &lt;span class="nx"&gt;Change&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;world&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;updateWorld&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;world&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;world&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;there&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;world&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;{ hello }&lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;{ world }&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;on:click=&lt;/span&gt;&lt;span class="s"&gt;{()&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; updateWorld()}&amp;gt; Update World &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when we click our button, our 'world' variable is updated based on the current value. The on:click directive runs the updateWorld function whenever we click the button and then our template will re-render when the 'world' variable changes. This is a very birds eye view of Svelte, so feel free to check the tutorial, docs &amp;amp; &lt;a href="[https://svelte.dev/repl/5d022b4697f5421c9d239c400a2761b1?version=3.32.0](https://svelte.dev/repl/5d022b4697f5421c9d239c400a2761b1?version=3.32.0)"&gt;REPL&lt;/a&gt; at &lt;a href="http://svelte.dev" rel="noopener noreferrer"&gt;svelte.dev&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Like I mentioned above, Sapper is an application framework that uses Svelte. The quickest way to get a Sapper project up and running is to use degit to clone the template repository to your local dev environment. In a new terminal tab (leave your Sanity Studio running), navigate back to the parent directory for our project and run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx degit &lt;span class="s2"&gt;"sveltejs/sapper-template#rollup"&lt;/span&gt; web
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will clone the template in a directory named "web" next to our "content" directory. Let's change into the 'web' directory and install our Node dependancies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;web &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also need to bring in the Sanity Javascript Client so we can connect to our Sanity backend. To do so, run this command inside the Sapper project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; @sanity/client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once dependancies are installed, we're are going to convert our Sapper project to use TypeScript. TypeScript brings a lot of great features to Javascript that allow you to catch bugs before they run and write cleaner JS code in general. If you're unfamiliar with TS don't fret; any valid Javascript is valid TS so you can learn it bit by bit. To convert our Sapper to TS, run the following command in the web directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node scripts/setupTypeScript.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will then receive this prompt from the command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Next:
1. run &lt;span class="s1"&gt;'npm install'&lt;/span&gt; again to &lt;span class="nb"&gt;install &lt;/span&gt;TypeScript dependencies
2. run &lt;span class="s1"&gt;'npm run build'&lt;/span&gt; &lt;span class="k"&gt;for &lt;/span&gt;the @sapper imports &lt;span class="k"&gt;in &lt;/span&gt;your project to work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Complete these steps and then we're ready to rock! To get started building, we just need to startup our development server using &lt;code&gt;npm run dev&lt;/code&gt; which will serve our Sapper app at &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;localhost:3000&lt;/a&gt; .&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Connecting Sanity &amp;amp; Sapper
&lt;/h3&gt;

&lt;p&gt;*Note: I find it easiest to open the parent directory in your code editor so you can see the front end code as well as the Sanity Studio code. I'm going to be using Visual Studio Code because it has the official Svelte extension, which supports syntax highlighting in Svelte components. I highly suggest you use this extension when writing Svelte code!&lt;/p&gt;

&lt;p&gt;Let's open up our project in our code editor and take a look at the folder structure of a Sapper app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--&lt;/span&gt; sanity-md
    &lt;span class="nt"&gt;--&lt;/span&gt; content
    &lt;span class="nt"&gt;--&lt;/span&gt; web
        &lt;span class="nt"&gt;--&lt;/span&gt; __sapper__
        &lt;span class="nt"&gt;--&lt;/span&gt; .vscode
        &lt;span class="nt"&gt;--&lt;/span&gt; node_modules
        &lt;span class="nt"&gt;--&lt;/span&gt; src
        &lt;span class="nt"&gt;--&lt;/span&gt; static
        .gitignore
        package-lock.json
        package.json
        README.md
        rollup.config.js
        tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of our work is going to be within the src directory...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--&lt;/span&gt; src
    &lt;span class="nt"&gt;--&lt;/span&gt; components
    &lt;span class="nt"&gt;--&lt;/span&gt; node_modules
    &lt;span class="nt"&gt;--&lt;/span&gt; routes
    ambient.d.ts
    client.ts
    server.ts
    service-worker.ts
    template.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you might expect, our Svelte components live inside the components directory &amp;amp; our routes live within the routes directory. Sapper uses a file based routing system similar to Next.js, where every route in the app is represented by a .svelte file in the routes directory. Additionally, a directory within the routes directory will also represent a route as long as it contains an &lt;code&gt;index.svelte&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--routes&lt;/span&gt;
    &lt;span class="nt"&gt;--blog&lt;/span&gt;
    &lt;span class="c"&gt;# these file prepended with an underscore won't be rendered as pages&lt;/span&gt;
    _error.svelte
    _layout.svelte 
    about.svelte
    index.svelte
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this template project, our blog directory contains an &lt;code&gt;index.svelte&lt;/code&gt; file, a &lt;code&gt;[slug].svelte&lt;/code&gt; file, and some other Javascript files that are currently just placeholder content. Since this &lt;code&gt;index.svelte&lt;/code&gt; file is in the blog directory, it will represent the /blog route of our site. Likewise, the &lt;code&gt;[slug].svelte&lt;/code&gt; file is a dynamic route for all of our single blog posts. The square brackets indicate to Sapper that this is a dynamic route; but more on that later! First, we need to make a Sanity Client module that can be reused throughout our app. &lt;/p&gt;

&lt;p&gt;In the components directory, create a file named &lt;code&gt;SanityClient.ts&lt;/code&gt;. This will act as a module we can import into our Svelte components to easily query our Sanity data source. The module will look like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;sanityClient&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@sanity/client&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// create Client interface to type check options&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;useCdn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// create instance of sanityClient&lt;/span&gt;
&lt;span class="c1"&gt;// this is how you connect your frontend to your sanity studio&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;Client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//your project ID&lt;/span&gt;
  &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PROJECT-ID&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;//your dataset; defaults to production&lt;/span&gt;
  &lt;span class="na"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;useCdn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sanityClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This little module imports the sanityClient we installed earlier, creates a Client &lt;a href="https://www.typescriptlang.org/docs/handbook/interfaces.html" rel="noopener noreferrer"&gt;interface&lt;/a&gt;, defines an options variable that contains all the information we need to give Sanity, and, lastly, creates a client variable, which calls the sanityClient with our given options. The client variable is then exported so we can bring it into any part of our app. &lt;/p&gt;

&lt;p&gt;Now let's hop into routes/blog and start to build out the meat of our application. First, we can delete all files in the blog directory except for the two svelte files. Then let's open up the index.svelte file in the blog directory.&lt;/p&gt;

&lt;p&gt;*Note: As we look at these Svelte components, know that I'm omitting any styles or &lt;a&gt;svelte:head&lt;/a&gt; tags to keep code blocks short. The styles that come with the template are adequate for our purposes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;context=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"ts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../../components/sanityClient&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;preload&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*[_type == 'post']{_id, slug, title}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"ts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Slug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;_type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;current&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Slug&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Recent posts&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    {#each posts as post}
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"prefetch"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"blog/{post.slug.current}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{post.title}&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    {/each}
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the final code for our new blog index page; let's break it down into pieces. First, you'll notice that we actually have two script tags in this component. What gives?! Svelte gives us a really handy way to fetch data almost outside of the component life cycle. The explanation for context='module' in the docs is "A  tag with a context=&amp;amp;#39;module&amp;amp;#39; attribute runs once when the module first evaluates, rather than for each component instance.&amp;amp;quot; We could just as easily move our &amp;lt;code&amp;gt;client.fetch()&amp;lt;/code&amp;gt; call into our normal script tag; however, this would cause the page to load before our list of blog posts has been fetched. The user would then see an empty page for a moment while that data is being fetched. By using context=&amp;amp;#39;module&amp;amp;#39; the data has already been fetched by the time the component renders in the DOM. Thanks, Svelte!&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Let&amp;amp;#39;s now break the module down line by line. &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;First we import our client module using ESM syntax, then we exporting an async function which defines a groq query, and then awaits the &amp;lt;code&amp;gt;client.fetch()&amp;lt;/code&amp;gt; call using the query we&amp;amp;#39;ve just defined. The function then returns our &amp;amp;#39;posts&amp;amp;#39; state variable with all of our blog posts included; this return value is passed as props to the normal script tag in our Svelte component. Because this is just a list of the blog titles and links to their respective routes, our groq query includes a Projection. This projection allows the query to only return the values we explicitly ask for, meaning we don&amp;amp;#39;t have to fetch all of the post content, just the _id, slug &amp;amp;amp; title.&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Moving on to our normal script tag, the first definition is again a TypeScript interface. Interfaces are a way for us to tell TypeScript what any one piece of data should look like. In our case, the Sanity content type &amp;amp;#39;slug&amp;amp;#39; returns a &amp;amp;#39;_type&amp;amp;#39; property &amp;amp;amp; a &amp;amp;#39;current&amp;amp;#39; property. By creating this interface, we can now explicitly tell TypeScript how the slug we get from Sanity should look. We&amp;amp;#39;re then creating our posts prop, which itself has type definitions along side it describing what shape it should have. This prop is receiving the returned posts array from the module mentioned earlier because they share the same name. &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Lastly, is our template, which is just an h1 &amp;amp;amp; and unordered list. The list contains a Svelte &amp;lt;code&amp;gt;{#each}&amp;lt;/code&amp;gt; block, which is one of the many array methods built into Svelte templates. An &amp;amp;#39;each&amp;amp;#39; block takes in an array as a parameter and renders a copy of any code in the &amp;amp;#39;each&amp;amp;#39; block for each item in the given array. Although the syntax is rather readable, I&amp;amp;#39;ll spell it out - for each item in the posts array, we will create a list item containing a link to the blog post using slug.current and the title. The second argument of the &amp;amp;#39;each&amp;amp;#39; block, &amp;lt;code&amp;gt;as post&amp;lt;/code&amp;gt;, defines how the array item will be referenced inside the block; this can be anything, but if the array is in a plural form (like posts), it&amp;amp;#39;s usually best practice to use the singular form here. This makes the templates read almost like plain English! &amp;lt;/p&amp;gt;
&amp;lt;h3&amp;gt;
  &amp;lt;a name="step-3-markdown" href="#step-3-markdown" class="anchor"&amp;gt;
  &amp;lt;/a&amp;gt;
  Step 3: Markdown!
&amp;lt;/h3&amp;gt;

&amp;lt;p&amp;gt;&amp;lt;img src="https://cdn.sanity.io/images/81pocpw8/production/3c6787a8794a665f4e9338aca20c415185dba7c7-1140x676.png?w=960&amp;amp;h=569&amp;amp;fit=clip&amp;amp;auto=format" alt="The main blog page"/&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Wow, that was a lot to take in. Luckily, the [slug].svelte file looks very similar to this and essentially functions in the same way! But before we get to that, we need to talk about our blog content. &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;By default, the main body of our blog is blockContent in our Sanity Studio, otherwise known as Portable Text. Portable Text is a JSON based rich text specification created and maintained by Sanity. As is stated in the README, &amp;amp;quot;Portable Text is an agnostic abstraction of rich text that can be serialized into pretty much any markup language&amp;amp;quot;. &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;However, in this tutorial we are using Markdown as the main blog content. A personal blog like this is likely the only case I would choose Markdown over Portable Text for a few reasons. First, I&amp;amp;#39;ve found I can write a lot faster using Markdown over any form of rich text including Portable Text. The second reason being that this blog content will only ever be used within this blog. In any other case I would stick with portable text since you can mix rich text with data and it&amp;amp;#39;s extremely flexible across different platforms, and it fits with the &amp;lt;a href="https://www.sanity.io/structured-content"&amp;gt;Structured Content&amp;lt;/a&amp;gt; model of Sanity much better than Markdown. We need to bring in additional packages to write &amp;amp;amp; render Markdown, making it much less flexible than Portable Text. &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Let&amp;amp;#39;s bring the first of these packages into Sanity. First, let&amp;amp;#39;s navigate to the content directory via a terminal and run this command:&amp;lt;br&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;div class="highlight"&amp;gt;&amp;lt;pre class="highlight shell"&amp;gt;&amp;lt;code&amp;gt;sanity &amp;lt;span class="nb"&amp;gt;install &amp;lt;/span&amp;gt;markdown
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;This will install the markdown input in our Sanity Studio; all we need to do now is open our post.js schema in vscode and make a quick edit to the body field.&amp;lt;br&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;div class="highlight"&amp;gt;&amp;lt;pre class="highlight jsx"&amp;gt;&amp;lt;code&amp;gt;&amp;lt;span class="k"&amp;gt;export&amp;lt;/span&amp;gt; &amp;lt;span class="k"&amp;gt;default&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;{&amp;lt;/span&amp;gt;
      &amp;lt;span class="na"&amp;gt;name&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="s1"&amp;gt;post&amp;lt;/span&amp;gt;&amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt;
      &amp;lt;span class="na"&amp;gt;title&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="s1"&amp;gt;Post&amp;lt;/span&amp;gt;&amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt;
      &amp;lt;span class="na"&amp;gt;type&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="s1"&amp;gt;document&amp;lt;/span&amp;gt;&amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt;
      &amp;lt;span class="na"&amp;gt;fields&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;[...&amp;lt;/span&amp;gt;      

            &amp;lt;span class="p"&amp;gt;{&amp;lt;/span&amp;gt;
          &amp;lt;span class="na"&amp;gt;name&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="s1"&amp;gt;body&amp;lt;/span&amp;gt;&amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt;
          &amp;lt;span class="na"&amp;gt;title&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="s1"&amp;gt;Body&amp;lt;/span&amp;gt;&amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt;
          &amp;lt;span class="na"&amp;gt;type&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="s1"&amp;gt;markdown&amp;lt;/span&amp;gt;&amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt;
          &amp;lt;span class="na"&amp;gt;options&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;{&amp;lt;/span&amp;gt;
            &amp;lt;span class="na"&amp;gt;minRows&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="mi"&amp;gt;20&amp;lt;/span&amp;gt;
          &amp;lt;span class="p"&amp;gt;}&amp;lt;/span&amp;gt;
        &amp;lt;span class="p"&amp;gt;},&amp;lt;/span&amp;gt;

        &amp;lt;span class="p"&amp;gt;...]&amp;lt;/span&amp;gt;
&amp;lt;span class="p"&amp;gt;}&amp;lt;/span&amp;gt;
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Now, if we restart our Sanity Studio, the body input will be replaced with a markdown editor. Enter in a bit of markdown that we can use to make our last Sapper page - our dynamic single blog post page. But before we do that, we need a way to render the string of markdown that will be returned from Sanity. To do this, we just need to install Snarkdown; my favorite markdown parser for Svelte apps. To install this package, just run this command in the web directory containing our Sapper app:&amp;lt;br&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;div class="highlight"&amp;gt;&amp;lt;pre class="highlight shell"&amp;gt;&amp;lt;code&amp;gt;npm i &amp;lt;span class="nt"&amp;gt;--save&amp;lt;/span&amp;gt; snarkdown
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Now that we have a markdown parser, let&amp;amp;#39;s take a look at [slug].svelte...&amp;lt;br&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;div class="highlight"&amp;gt;&amp;lt;pre class="highlight html"&amp;gt;&amp;lt;code&amp;gt;&amp;lt;span class="nt"&amp;gt;&amp;amp;lt;script &amp;lt;/span&amp;gt;&amp;lt;span class="na"&amp;gt;context=&amp;lt;/span&amp;gt;&amp;lt;span class="s"&amp;gt;"module"&amp;lt;/span&amp;gt; &amp;lt;span class="na"&amp;gt;lang=&amp;lt;/span&amp;gt;&amp;lt;span class="s"&amp;gt;"ts"&amp;lt;/span&amp;gt;&amp;lt;span class="nt"&amp;gt;&amp;amp;gt;&amp;lt;/span&amp;gt;
    &amp;lt;span class="k"&amp;gt;import&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;{&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;client&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;}&amp;lt;/span&amp;gt; &amp;lt;span class="k"&amp;gt;from&amp;lt;/span&amp;gt; &amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="s1"&amp;gt;../../components/sanityClient&amp;lt;/span&amp;gt;&amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;
    &amp;lt;span class="kd"&amp;gt;let&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;post&amp;lt;/span&amp;gt;
    &amp;lt;span class="k"&amp;gt;export&amp;lt;/span&amp;gt; &amp;lt;span class="k"&amp;gt;async&amp;lt;/span&amp;gt; &amp;lt;span class="kd"&amp;gt;function&amp;lt;/span&amp;gt; &amp;lt;span class="nf"&amp;gt;preload&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;({&amp;lt;/span&amp;gt; &amp;lt;span class="na"&amp;gt;params&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;{&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;slug&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;}&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;})&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;{&amp;lt;/span&amp;gt;
        &amp;lt;span class="kd"&amp;gt;const&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;query&amp;lt;/span&amp;gt; &amp;lt;span class="o"&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class="s2"&amp;gt;`*[slug.current == "&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;${&amp;lt;/span&amp;gt;&amp;lt;span class="nx"&amp;gt;slug&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;}&amp;lt;/span&amp;gt;&amp;lt;span class="s2"&amp;gt;"]`&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;;&amp;lt;/span&amp;gt;

        &amp;lt;span class="kd"&amp;gt;const&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;res&amp;lt;/span&amp;gt; &amp;lt;span class="o"&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class="k"&amp;gt;await&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;client&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class="nf"&amp;gt;fetch&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class="nx"&amp;gt;query&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;)&amp;lt;/span&amp;gt;
        &amp;lt;span class="kd"&amp;gt;const&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;post&amp;lt;/span&amp;gt; &amp;lt;span class="o"&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class="k"&amp;gt;await&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;res&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class="nf"&amp;gt;shift&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;();&amp;lt;/span&amp;gt;
        &amp;lt;span class="k"&amp;gt;return&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;{&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;post&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;}&amp;lt;/span&amp;gt; 
    &amp;lt;span class="p"&amp;gt;}&amp;lt;/span&amp;gt;
&amp;lt;span class="nt"&amp;gt;&amp;amp;lt;/script&amp;amp;gt;&amp;lt;/span&amp;gt;

&amp;lt;span class="nt"&amp;gt;&amp;amp;lt;script &amp;lt;/span&amp;gt;&amp;lt;span class="na"&amp;gt;lang=&amp;lt;/span&amp;gt;&amp;lt;span class="s"&amp;gt;"ts"&amp;lt;/span&amp;gt;&amp;lt;span class="nt"&amp;gt;&amp;amp;gt;&amp;lt;/span&amp;gt;
    &amp;lt;span class="k"&amp;gt;import&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;snarkdown&amp;lt;/span&amp;gt; &amp;lt;span class="k"&amp;gt;from&amp;lt;/span&amp;gt; &amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="s1"&amp;gt;snarkdown&amp;lt;/span&amp;gt;&amp;lt;span class="dl"&amp;gt;'&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;;&amp;lt;/span&amp;gt;
    &amp;lt;span class="k"&amp;gt;export&amp;lt;/span&amp;gt; &amp;lt;span class="kd"&amp;gt;let&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;post&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;{&amp;lt;/span&amp;gt; &amp;lt;span class="nl"&amp;gt;slug&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;string&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;;&amp;lt;/span&amp;gt; &amp;lt;span class="nl"&amp;gt;title&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;string&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;body&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class="nx"&amp;gt;string&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;};&amp;lt;/span&amp;gt;
&amp;lt;span class="nt"&amp;gt;&amp;amp;lt;/script&amp;amp;gt;&amp;lt;/span&amp;gt;

&amp;lt;span class="nt"&amp;gt;&amp;amp;lt;h1&amp;amp;gt;&amp;lt;/span&amp;gt;{post.title}&amp;lt;span class="nt"&amp;gt;&amp;amp;lt;/h1&amp;amp;gt;&amp;lt;/span&amp;gt;

&amp;lt;span class="nt"&amp;gt;&amp;amp;lt;div&amp;lt;/span&amp;gt; &amp;lt;span class="na"&amp;gt;class=&amp;lt;/span&amp;gt;&amp;lt;span class="s"&amp;gt;"content"&amp;lt;/span&amp;gt;&amp;lt;span class="nt"&amp;gt;&amp;amp;gt;&amp;lt;/span&amp;gt;
    {@html snarkdown(post.body)}
&amp;lt;span class="nt"&amp;gt;&amp;amp;lt;/div&amp;amp;gt;&amp;lt;/span&amp;gt;
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;You&amp;amp;#39;ll notice that the same basic structure applies here - we have a module script tag that is using our sanityClient to fetch data from Sanity; however, there is one difference here. Because this Sapper route is dynamic (hence the square brackets in the file name), we have access to               &amp;lt;code&amp;gt;{ params }&amp;lt;/code&amp;gt; in our async preload function. We can then de-structure those params to get access to the slug being passed to this page. Then we can employ a template literal to use that slug in our groq query. Lastly, instead of just returning the array we receive from client.fetch, we can use &amp;lt;code&amp;gt;.shift()&amp;lt;/code&amp;gt; to pull the first object (in our case the only object) out of the array. This will help keep our markup clean &amp;amp;amp; readable. Moving down to the normal script tag, the only change here is that we&amp;amp;#39;re importing Snarkdown &amp;amp;amp; our prop has a different type definition. Instead of an array of objects, this post prop is a single object with a slug, title, &amp;amp;amp; body. Moving to the template, we&amp;amp;#39;re rendering the blog post title in an &amp;lt;code&amp;gt;&amp;amp;lt;h1&amp;amp;gt;&amp;lt;/code&amp;gt; before rendering the post content. Svelte provides a handy &amp;lt;code&amp;gt;{@html }&amp;lt;/code&amp;gt; renderer for us to use. The &amp;lt;code&amp;gt;snarkdown()&amp;lt;/code&amp;gt; function returns html raw, so all we have to do is pass our post&amp;amp;#39;s body sting to Snarkdown inside the &amp;lt;code&amp;gt;{@html }&amp;lt;/code&amp;gt; renderer and - boom! We&amp;amp;#39;re parsing our markdown from Sanity! If your Sapper dev server is still running, just save this file and then navigate back to your browser to see our new blog working better than ever. &amp;lt;/p&amp;gt;
&amp;lt;h3&amp;gt;
  &amp;lt;a name="step-4-review" href="#step-4-review" class="anchor"&amp;gt;
  &amp;lt;/a&amp;gt;
  Step 4: Review
&amp;lt;/h3&amp;gt;

&amp;lt;p&amp;gt;&amp;lt;img src="https://cdn.sanity.io/images/81pocpw8/production/ddb7a91883a46d545bf90e0743e7af88ec0d2f37-2550x1314.png?rect=1,0,2548,1314&amp;amp;w=1280&amp;amp;h=660&amp;amp;fit=clip&amp;amp;auto=format" alt="The single post page"/&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;We now have the bones for a Sanity powered Markdown blog with a Sapper front-end, just add other pages/routes you may want, tweak the styling &amp;amp;amp; voila! Also remember we still have other data that can be managed in Sanity and displayed in our Sapper site, like post categories and post authors. The possibilities are endless! Deploy your studio to Sanity by running &amp;lt;code&amp;gt;sanity deploy&amp;lt;/code&amp;gt; in the content folder and then you can deploy your Sapper app just about anywhere. &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Check the Sapper &amp;lt;a href="[https://sapper.svelte.dev/docs#Deployment](https://sapper.svelte.dev/docs#Deployment)"&amp;gt;docs&amp;lt;/a&amp;gt; for more info on deploying. &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;You can view the source code for this blog on my &amp;lt;a href="[https://github.com/stordahl/sanity-sapper-md](https://github.com/stordahl/sanity-sapper-md)"&amp;gt;Github&amp;lt;/a&amp;gt; &amp;amp;amp; make sure to checkout my Learning Svelte series at &amp;lt;a href="https://stordahl.dev/blog"&amp;gt;stordahl.dev&amp;lt;/a&amp;gt; if you&amp;amp;#39;re new to Svelte.&amp;lt;/p&amp;gt;
&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>sapper</category>
      <category>sanity</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Learning Svelte 4 | props &amp; data flow</title>
      <dc:creator>Jacob Stordahl</dc:creator>
      <pubDate>Wed, 07 Oct 2020 05:17:47 +0000</pubDate>
      <link>https://dev.to/stordahl_/learning-svelte-4-props-data-flow-k0h</link>
      <guid>https://dev.to/stordahl_/learning-svelte-4-props-data-flow-k0h</guid>
      <description>&lt;p&gt;Props or &lt;em&gt;properties&lt;/em&gt; are how we pass data from our parent components to any children components. Props are critical to making reusable components &amp;amp; creating efficient data flow. Let's take a look at a simple example where we'll see how to declare props in a child component, &amp;amp; pass some data down to it from the parent component...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// parent component
&amp;lt;script&amp;gt;
    import Nested from './Nested.svelte';
&amp;lt;/script&amp;gt;

&amp;lt;Nested answer={42}/&amp;gt;

// child component
&amp;lt;script&amp;gt;
    export let answer;
&amp;lt;/script&amp;gt;

&amp;lt;p&amp;gt;The answer is {answer}&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;First lets look at the child component where our props are declared. In Svelte we declare props by creating a variable &amp;amp; then exporting that variable outside of the component. This is how Svelte knows which data to pipe where. We create our prop by declaring&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;export let propName&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
. If you want to provide a default value incase one isn't passed down, simply provide a value for that variable:&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;export let propName = defaultValue&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 Then we're just displaying the 'answer' variable in our template. &lt;/p&gt;

&lt;p&gt;Second, take a look at how we pass our data down to our child component. After importing the child into the parent &amp;amp; displaying it in the template, use the&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;propName={ propValue }&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 syntax. You can pass as many values this way, however if you want to pass many values down, it will likely be more efficient to use the spread operator to pass an object to our child. &lt;/p&gt;

&lt;p&gt;Let's take a look at a real world example from a svelte project I've built! On &lt;a href="https://www.blkcatstudio.com/team"&gt;this&lt;/a&gt; page each row in the content area is a component being reused for each team member. First lets take a look at the Page (or parent component) &amp;amp; how we format our data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// team.svelte (parent component)
&amp;lt;script&amp;gt;
    import Member from '../components/Member.svelte';

    const members = [
        {
            name: "Jacob Stordahl",
            pronouns: "he/him",
            desc: "Jake is a front-end developer, who is deeply passionate about building intuitive User Interfaces using Javascript, HTML, and CSS. His main goal in creating BCS is to help small businesses make their creative goals a tangible reality using digital technologies. When Jake isn't writing code he's probably cruising on his roller skates or cuddling his two kittens. ",
            image: "/jake.jpg"
        },
        {
            name: "Nick Quandt",
            pronouns: "he/him",
            desc: "Nick is a software engineer with a passion for writing scalable solutions in Javascript, TypeScript, and Node.js. Seattle dog dad &amp;amp; outdoor enthusiast. Ask me anything about programming, data, bbq, or cowboy boots!",
            image: "/nick.jpg"
        },
        {
            name: "Taelor Hill",
            pronouns: "they/them",
            desc: "Taelor is an illustrator and graphic designer, focusing primarily in creating and sharing educational content digitally. Their passions include using social media as a vehicle for social change, supporting marginalized communities, and using art as a form of activism. You can usually find them playing with their cats, worrying about all their plants, or baking something sweet.",
            image: "/tae.jpg"
        }
    ];
&amp;lt;/script&amp;gt;

&amp;lt;div id="content"&amp;gt;
    &amp;lt;h1&amp;gt;meet our team!&amp;lt;/h1&amp;gt;
    {#each members as member}
        &amp;lt;Member {...member}&amp;gt;
    {/each}
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this example, we have an array of objects ('members'), which we can loop over using an&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;{#each}&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 block. For each member object, we'll create an instance of our&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;&amp;lt;Member /&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 component, and then pass that member object down to said&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;&amp;lt;Member /&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 component. Now, let's peak inside the Member component to see how we recieve our data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // Member.svelte (child component)
    &amp;lt;script&amp;gt;
    export let name;
    export let pronouns;
    export let desc;
    export let image;
    &amp;lt;/script&amp;gt;

    &amp;lt;div class="member-row"&amp;gt;
        &amp;lt;div class="frame"&amp;gt;
            &amp;lt;img src="{ image }" alt="portrait of { name }"&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="text-inner"&amp;gt;
            &amp;lt;h2&amp;gt;{ name }&amp;lt;/h2&amp;gt;
            &amp;lt;h4&amp;gt;{ pronouns }&amp;lt;/h4&amp;gt;
            &amp;lt;p&amp;gt;{ desc }&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt; 
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Within the child component, we create and export a variable for each value in our member object that is being passed down. Then we simply display those variables in our template. &lt;/p&gt;

&lt;p&gt;Well, that's pretty much it for props in Svelte. You can see how props makes component based development even more appealing.  Next time we'll talk about reactivity &amp;amp; state in Svelte; stay tuned!&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>props</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Learning Svelte 3 | component-ize all the things</title>
      <dc:creator>Jacob Stordahl</dc:creator>
      <pubDate>Sun, 04 Oct 2020 03:59:19 +0000</pubDate>
      <link>https://dev.to/stordahl_/learning-svelte-3-component-ize-all-the-things-2092</link>
      <guid>https://dev.to/stordahl_/learning-svelte-3-component-ize-all-the-things-2092</guid>
      <description>&lt;p&gt;Dang it's been a minute! I'm happy to be back writing about Svelte; today I'd like to talk about components, why component based development is efficient, and how to create &amp;amp; use a Svelte component. &lt;/p&gt;

&lt;p&gt;Back in the old days, the file structure of a web site may have looked something like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public/
    html/
        index.html
        blog.html
        contact.html
    css/
        style.css
        blog.css
    js/
        index.js
        contact.js
assets/
    img/
            portrait.jpeg
            favicon.png
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This structure for a web frontend aimed to "separate your concerns", meaning that the markup (HTML), styling (CSS), and logic (Javascript) should exist in there own files. This worked for a while because this is very much how the &lt;em&gt;browser&lt;/em&gt; sees our code. However, the development experience created by this scenario creates some problems. Let's look at a nav bar for example. If you were creating a website using this file structure, you would write some HTML like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;nav&amp;gt;
    &amp;lt;ul&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href="index.html"&amp;gt; Home &amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href="blog.html"&amp;gt; Blog &amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href="contact.html"&amp;gt; Contact &amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
&amp;lt;/nav&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You would then need to copy + paste this nav bar into every page on the site, while also referencing the appropriate CSS &amp;amp; JS files. This may be an okay experience when you're starting a new project, but what about 3 years down the line when you have 50+ pages and the client wants to add something new to the navigation? You can imagine the work required to accomplish an arguably simple task. This is where component based development becomes critical; we make our code reusable through out the site/ app. You'll see this pattern appear a lot in development (especially for the web) where we want to write code in one place and reuse or reference it throughout the project. &lt;/p&gt;

&lt;p&gt;For our nav bar example, we would simply have a navigation component that gets imported into each page it is needed on. Then if I make a change to this component, that change is reflected throughout the code base. Brilliant! Now that we see the advent of using components, let's take a look at how we can make and use components in Svelte.&lt;/p&gt;

&lt;p&gt;Here is the example provided to us in the &lt;a href="https://svelte.dev/tutorial/nested-components"&gt;Svelte tutorial&lt;/a&gt; regarding 'Nested Components'...&lt;/p&gt;

&lt;p&gt;Here we have our main App component named 'App.svelte'...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    import Nested from './Nested.svelte';
&amp;lt;/script&amp;gt;
&amp;lt;style&amp;gt;
    p {
        color: purple;
        font-family: 'Comic Sans MS', cursive;
        font-size: 2em;
    }
&amp;lt;/style&amp;gt;

&amp;lt;p&amp;gt;This is a paragraph.&amp;lt;/p&amp;gt;
&amp;lt;Nested /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;note that we're using EMS syntax to import our Svelte component. You can learn more about ESM &lt;a href="https://flaviocopes.com/es-modules/"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you're using the &lt;a href="https://github.com/sveltejs/template"&gt;Svelte Template&lt;/a&gt;, App.svelte is the main file where our app lives. In the above example, we are importing a component called 'Nested' and then displaying it in our template below. Because Svelte scopes styling, the CSS we see in our App component &lt;em&gt;won't&lt;/em&gt; style the paragraph tag that is within our Nested component. Now when we edit the content of&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;&amp;lt;Nested /&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 , the content is changed everywhere that component is referenced. Great! We've eliminated the problem of repeating code. To return to our first example, we can now create a&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;&amp;lt;Nav /&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 component that can be efficiently reused throughout our Svelte app. &lt;/p&gt;

&lt;p&gt;Next time we'll talk about how we can use Svelte components in really creative ways while utilizing &lt;em&gt;props&lt;/em&gt; to share data between them.&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Learning Svelte 2 | data, templating &amp; styling</title>
      <dc:creator>Jacob Stordahl</dc:creator>
      <pubDate>Mon, 29 Jun 2020 21:08:09 +0000</pubDate>
      <link>https://dev.to/stordahl_/learning-svelte-2-data-templating-styling-2c7g</link>
      <guid>https://dev.to/stordahl_/learning-svelte-2-data-templating-styling-2c7g</guid>
      <description>&lt;p&gt;In this second article in a series on &lt;a href="https://svelte.dev"&gt;Svelte.js&lt;/a&gt; we're going to cover the very basics of dynamic data in svelte, how to populate our template with said data, and how to style it all. First, lets look at the basics of how our data interacts with our template.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;script&amp;gt;
        let name = 'world';
    &amp;lt;/script&amp;gt;

    &amp;lt;h1&amp;gt;Hello {name}!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this little Hello World example, we see that all we have to do is save our data to a variable ('name') and place that variable inside of curly braces within our HTML template. If you've seen JS templating frameworks like Handlebars, this may look familiar. Obviously, when you receive any sort of real data from an API or database, it will likely be an array or object. We can use the following syntax to pull values from an array or object...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;script&amp;gt;
        let names = {
            one: 'megan',
            two: 'jeff',
            three: 'muhammad'
        };
    &amp;lt;/script&amp;gt;

    &amp;lt;h1&amp;gt;Hello {names.one}!&amp;lt;/h1&amp;gt;
    &amp;lt;h1&amp;gt;Hello {names.two}!&amp;lt;/h1&amp;gt;
    &amp;lt;h1&amp;gt;Hello {names.three}!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can now see how you might populate a page with different values from a database. I find this syntax very intuitive if you're coming from vanilla HTML/CSS/Javascript and this is your first framework. Last thing I want to cover in this article is styling components. We'll get into the component structure next time, but just know to style in Svelte is very easy, &lt;em&gt;as styles are scoped to the component&lt;/em&gt;. You also have global styles available, but scoping the styles to the component removes a lot of code from the compiled app!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;script&amp;gt;
        let names = {
            one: 'megan',
            two: 'jeff',
            three: 'muhammad'
        };
    &amp;lt;/script&amp;gt;

    &amp;lt;h1 id="1"&amp;gt;Hello {names.one}!&amp;lt;/h1&amp;gt;
    &amp;lt;h1 id="2"&amp;gt;Hello {names.two}!&amp;lt;/h1&amp;gt;
    &amp;lt;h1 id="3"&amp;gt;Hello {names.three}!&amp;lt;/h1&amp;gt;

    &amp;lt;style&amp;gt;
        h1{
            color:red;
        }
        #2{
            color:green;
        }
        #3{
            color:blue;
        }
    &amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I've added style to our previous example. Even though our first selector is an element selector, it will only apply to the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; tags within this component, not throughout the whole app. &lt;/p&gt;

&lt;p&gt;If you're interested in Svelte, make sure to check back for more articles exploring Svelte with me! Make sure to check out the tutorials and REPL at &lt;a href="https://svelte.dev"&gt;svelte.dev&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>svelte</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Learning Svelte 1 | why you should too</title>
      <dc:creator>Jacob Stordahl</dc:creator>
      <pubDate>Mon, 22 Jun 2020 08:07:52 +0000</pubDate>
      <link>https://dev.to/stordahl_/learning-svelte-1-why-you-should-too-648</link>
      <guid>https://dev.to/stordahl_/learning-svelte-1-why-you-should-too-648</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A3YYiw0E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/ycm2eydumh3ly09vxio3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A3YYiw0E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/ycm2eydumh3ly09vxio3.png" alt="Svelte.js Logo" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After spending the last month scared of diving into a javascript framework, this week I found out about &lt;a href="https://svelte.dev"&gt;Svelte.js&lt;/a&gt;. I'd like to tell you why I think it's a great option for beginner javascript developers who are new to component/ module based javascript development. &lt;/p&gt;

&lt;p&gt;If you're not familiar with Svelte, it works a little differently than other frameworks like React. Library based frameworks like React do a lot of the heavy lifting in the clients browsers as they receive it. Svelte, however, is a &lt;em&gt;compiler&lt;/em&gt; &lt;strong&gt;not a library&lt;/strong&gt;. This means that when you build your app, Svelte will take the project and convert it to plain HTML &amp;amp; vanilla JS. This means that the client only sees optimized (and mostly static) code, in much smaller bundles than a library based framework. This blog for example is built using Svelte and its SSG counter part &lt;a href="//sapper.svelte.dev"&gt;Sapper&lt;/a&gt;. We'll get into Sapper in a later post, but just know, Sapper brings a lot to Svelte; things like routing, SSR, code splitting, and more! This blog is hosted on Github, which is then built and served on Netlify's CDN. This setup make continuous deployment a breeze, and lets me have a super fast personal site. &lt;/p&gt;

&lt;p&gt;Let's take a look at a basic Svelte component so we can ration with the syntax...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;script&amp;gt;
        let name = 'world';
    &amp;lt;/script&amp;gt;

    &amp;lt;h1&amp;gt;Hello { name }&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can already see the simplicity of Svelte. a typical component consists of three parts...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;script&amp;gt;
        javascript
    &amp;lt;/script&amp;gt;

    &amp;lt;h1&amp;gt; markup &amp;lt;/h1&amp;gt;

    &amp;lt;style&amp;gt;
        css
    &amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The order of these doesn't technically matter, however it's best practice to place your script at the top. This is where we'll do things like import other components, add our logic, pass props, etc. But more on that later! In our example Hello World component, we can also see how data from within our script is referenced in our markup. We simply add curly braces around the javascript we want to place within our markup. &lt;/p&gt;

&lt;p&gt;I want to save most of my examples for later posts where I can be more in-depth but I want to show you one example of how we can use forEach within our markup template to create a dynamic experience. &lt;/p&gt;

&lt;p&gt;Let's say you're building an online publishing app and you want to build a drop-down to filter posts by category. Obviously you want to make this dynamic so categories can be added or removed in the future. Here's how we'd accomplish this in Svelte.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    // example array or categories (likely from a database response)
        let cats = [
            politics,
            international, 
            sports,
            entertainment, 
            reviews,
            opinion
        ];
&amp;lt;/script&amp;gt;

&amp;lt;select&amp;gt;
    {#each cats as cat}
        &amp;lt;option value={ cat }&amp;gt;
                { cat }
        &amp;lt;/option&amp;gt;
    {/each}
&amp;lt;/select&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is really what sold me on Svelte. Here the {#each} loop is creating elements dynamically using the sample data from our 'database'. This makes building dynamic, data rich user interfaces so quick and painless with Svelte. I do a lot of work in wordpress and this feel like if the post loop had a smarter &amp;amp; sexier brother.&lt;/p&gt;

&lt;p&gt;Also, Svelte feels just like what beginners are already familiar with: HTML and Javascript. If you're like me and have been intimidated by JS frameworks, I highly recommend you give Svelte a try. The development experience is wonderful, the syntax is truely effortless, and the docs are some of the most accessible &amp;amp; well-crafted docs I've read yet. &lt;/p&gt;

&lt;p&gt;Bonus Points: Svelte is also built by the community and not by the hidious corp facebook so... 🙃&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Examples of Sass/ SCSS Mixins</title>
      <dc:creator>Jacob Stordahl</dc:creator>
      <pubDate>Mon, 25 May 2020 04:04:20 +0000</pubDate>
      <link>https://dev.to/stordahl_/examples-of-sass-scss-mixins-ce</link>
      <guid>https://dev.to/stordahl_/examples-of-sass-scss-mixins-ce</guid>
      <description>&lt;p&gt;when I first started learning Sass, I had a hard time conceptualizing what a mixin was and what their uses were in the css I was writing. &lt;/p&gt;

&lt;p&gt;Now that I've been using mixins for a while, I thought I'd write a post showing some examples of really nice use cases for mixins. &lt;/p&gt;

&lt;p&gt;The first time it really hit me was when I realized I could use a mixin to minimize my code for working with &lt;em&gt;flexbox&lt;/em&gt;...&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 1: Flexbox
&lt;/h3&gt;

&lt;p&gt;I found myself writing this multiple time throughout all of my projects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.element&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This made my code very WET and very hard to manage. This is where the advantage of mixins became clear! By declaring this mixin...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;flex&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$direction&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$justify&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$align&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nt"&gt;display&lt;/span&gt;&lt;span class="nd"&gt;:flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$direction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$justify&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$align&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;calling the four most common rules in flexbox becomes this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.element&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Example 2: Fade
&lt;/h3&gt;

&lt;p&gt;Another habit I found myself developing was importing all of jQuery only to find myself using just fadeIn and fadeOut in my projects. This mixin allows a modular way to fade in and out elements using only CSS...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;fade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fade&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$timing&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$length&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$count&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$fill&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; 
        &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$fade&lt;/span&gt; &lt;span class="nv"&gt;$timing&lt;/span&gt; &lt;span class="nv"&gt;$length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;animation-iteration-count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="nl"&gt;animation-fill-mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$fill&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="nt"&gt;fadeIn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="nt"&gt;0&lt;/span&gt;&lt;span class="nv"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="nt"&gt;100&lt;/span&gt;&lt;span class="nv"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="nt"&gt;fadeOut&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="nt"&gt;0&lt;/span&gt;&lt;span class="nv"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="nt"&gt;100&lt;/span&gt;&lt;span class="nv"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This approach relies heavily on the ability to pass params to mixins, making them super flexible and modular for code you repeat often! &lt;/p&gt;

&lt;p&gt;Now animating an element with fade in simply looks like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.element&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;fade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fadeIn&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5s&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;forward&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Example 3: Fonts
&lt;/h3&gt;

&lt;p&gt;I've found it useful to use the following mixin when I'm using a font in different areas across a project, but at a range of sizes, weights, and spacings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;font&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$style&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$weight&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$height&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$spacing&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Jost'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;font-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$style&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$weight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;letter-spacing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$spacing&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So calling a font with all of these specifications looks like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.element&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;font&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;italic&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;400&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This can even be expanded a little more if you're using multiple fonts...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;font&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$family&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$category&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$style&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$weight&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$height&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$spacing&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$family&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$category&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;font-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$style&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$weight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;letter-spacing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$spacing&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  remember,
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;I'll be updating this article often as I write new and even better mixins!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>sass</category>
      <category>css</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Tips for learning SCSS/ sass (as a beginner)</title>
      <dc:creator>Jacob Stordahl</dc:creator>
      <pubDate>Tue, 12 May 2020 21:13:35 +0000</pubDate>
      <link>https://dev.to/stordahl_/tips-for-learning-scss-sass-as-a-beginner-31h1</link>
      <guid>https://dev.to/stordahl_/tips-for-learning-scss-sass-as-a-beginner-31h1</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cguBfeyj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.iambacon.co.uk/blog/sass.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cguBfeyj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.iambacon.co.uk/blog/sass.png" alt="Sass Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've been learning and working with SCSS/ sass for about 3 months in personal and professional projects. If you're not familiar, SCSS and sass are CSS pre-processors; at a basic level these are languages that get compiled and formatted into regular CSS that can be read by a web browser. &lt;/p&gt;

&lt;p&gt;The advent of this technology took the very tedious task of writing CSS and made it a more modern and far more efficient process. Pre-processors allow things like variables, partials, nesting and mixins to be used in writing CSS styles. Not only does this cut down on code, it also enhances the developer experience a great deal (IMHO).&lt;/p&gt;

&lt;p&gt;As someone who is relatively new to this technology, I thought I'd share some things that I wish I would have known before I started. If you'd like a run down on all of the features of sass, look &lt;a href="https://sass-lang.com/guide"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Learn how to stay organized
&lt;/h2&gt;

&lt;p&gt;Before you even begin learning any CSS pre-processor, I recommend learning how to best structure and organize your CSS. With the module system that's built into sass, you're eventually going to be splitting your styles into different files all together. If you don't have organization conventions, I find it very easy to get lost in your file system. &lt;/p&gt;

&lt;h2&gt;
  
  
  Remember how the compiler works &amp;amp; break it down
&lt;/h2&gt;

&lt;p&gt;If I had to give you one piece of advice to help you learn sass, it would be this: remember that the sass compiler will not only compile sass; it also compiles regular css. When I was first looking through the documentation for sass, I was overwhelmed to say the least. The thing I found most helpful was to try and gain a good understand of one sass feature and then move onto the next one. I started with variables (IMHO the best place to start for beginners); then I wanted a way to store all of my variables in a separate file so I dove into partials, and so on...&lt;/p&gt;

&lt;h2&gt;
  
  
  Practice IRL
&lt;/h2&gt;

&lt;p&gt;As with anything code related, the best way to learn is to practice (duh); however I hate coding exercises. This is why I've found it far more helpful to throw sass into my projects. If you use the above approach, implementing sass into any of your current projects should be a breeze. Some other things I did to start off my initial learning was finding code pens I liked and attempting to convert parts of it to use sass. Most importantly, remember to practice on actual projects in the context you would normally be working in.&lt;/p&gt;

</description>
      <category>sass</category>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
