<?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: Wesley Mutwiri</title>
    <description>The latest articles on DEV Community by Wesley Mutwiri (@wesleymutwiri).</description>
    <link>https://dev.to/wesleymutwiri</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%2F133937%2F78a5d35c-1615-4a4f-befe-42f5240535cc.jpg</url>
      <title>DEV Community: Wesley Mutwiri</title>
      <link>https://dev.to/wesleymutwiri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wesleymutwiri"/>
    <language>en</language>
    <item>
      <title>Create a blog with Contentful and Sveltekit</title>
      <dc:creator>Wesley Mutwiri</dc:creator>
      <pubDate>Wed, 16 Mar 2022 14:28:28 +0000</pubDate>
      <link>https://dev.to/wesleymutwiri/create-a-blog-with-contentful-and-sveltekit-3bd6</link>
      <guid>https://dev.to/wesleymutwiri/create-a-blog-with-contentful-and-sveltekit-3bd6</guid>
      <description>&lt;p&gt;I know you're wondering why another "create a blog tutorial" but that's the simplest project I could come up with for this tutorial. I also needed another excuse to spread the svelte gospel to everyone out there. Since there is currently no other Contentful and sveltekit tutorial out there (at time of writing of course), I am here to save the day, with my poor writing skills.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.contentful.com/" rel="noopener noreferrer"&gt;Contentful&lt;/a&gt; is an API first content platform to build digital experiences (according to their site description of course). If you only need to check out the code, without the hustle of reading this entire blog, you can find the &lt;a href="https://brave-perlman-af48a0.netlify.app/" rel="noopener noreferrer"&gt;live deployed site here&lt;/a&gt; and the &lt;a href="https://github.com/wesleymutwiri/content-kit" rel="noopener noreferrer"&gt;repo for reference here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Other Content Management Systems
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://strapi.io/" rel="noopener noreferrer"&gt;Strapi&lt;/a&gt; - an open source Nodejs Headless CMS that provides both REST or GraphQL.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://wordpress.org/" rel="noopener noreferrer"&gt;Wordpress&lt;/a&gt; - One of the most popular CMS and website builder.]&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.optimizely.com/" rel="noopener noreferrer"&gt;Optimizely&lt;/a&gt; - Not a clue what it does but the company showed up as I did my research.&lt;/li&gt;
&lt;li&gt;Obviously &lt;a href="https://www.contentful.com/" rel="noopener noreferrer"&gt;Contentful&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I went with contentful because it was the first one I could find after a few searches and seemed the simplest to use at the time. &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Contentful account, API key and secret key&lt;/li&gt;
&lt;li&gt;Text editor or JavaScript coding environment&lt;/li&gt;
&lt;li&gt;Time&lt;/li&gt;
&lt;li&gt;Familiarity with HTML, CSS and JavaScript(ES6+),&lt;/li&gt;
&lt;li&gt;Node.js and npm installed on your development machine.&lt;/li&gt;
&lt;li&gt;Basic knowledge of svelte and svelte kit&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Initial Setup
&lt;/h2&gt;

&lt;p&gt;You could use &lt;a href="https://codesandbox.io" rel="noopener noreferrer"&gt;codesandbox&lt;/a&gt; or &lt;a href="https://svelte.dev/repl/" rel="noopener noreferrer"&gt;svelte playground&lt;/a&gt; for a plain svelte application to play around with Contentful (Without routing of course) or create a local svelte kit application, for dynamic routes. Open a new terminal 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;    npm init svelte@next content-kit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Accept the prompt to proceed and afterwards select the skeleton project since we don't want to have a lot of demo data. Choose no when prompted whether to use TypeScript, enable ESLint, enable Prettier and disable testing since we won't be covering testing.&lt;/p&gt;

&lt;p&gt;Navigate into the newly created project folder and install the dependencies locally using:&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;content-kit
    npm i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll also need to install &lt;a href="https://www.contentful.com/developers/docs/extensibility/app-framework/sdk/" rel="noopener noreferrer"&gt;Contentful SDK&lt;/a&gt; using:&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;contentful
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the development server using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    npm run dev 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dev server will be listening from the &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; address. Any changes made to the application will be automatically rebuilt and reloaded using &lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;Vite&lt;/a&gt; into the running app as long as the dev server is still running.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contentful Setup
&lt;/h2&gt;

&lt;p&gt;I would go into the details of how to create an account and setup your contentful API but that would be free marketing for them and we don't do that here. However, I'll try my best to explain how to easily do so with screenshots.&lt;/p&gt;

&lt;p&gt;On the content model page of your dashboard, create a new content model that will host the structure of how your blog will look like and name it blog.&lt;/p&gt;

&lt;p&gt;Add the fields as shown below, making them mandatory and configuring the dateField to only include the date. Also, make sure the slugField is auto-generated from the title for SEO purposes.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo59wcvkthgys8y7wq0av.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo59wcvkthgys8y7wq0av.png" alt="Contentful Content Model Screenshot"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;On the content page is where you'll add sample blog posts so that we can have data to play around with. So add one post and another one.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb0vi3a8an5qik3ah6062.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb0vi3a8an5qik3ah6062.gif" alt="Another one image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the settings page, copy the API key and space ID and paste them somewhere safe, we'll add them to the sveltekit project in a moment.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Sveltekit project
&lt;/h2&gt;

&lt;p&gt;Since this isn't a styling tutorial, we'll create a very basic UI or if you'd like, you can use the layout from &lt;a href="https://github.com/wesleymutwiri/wm-blog-template" rel="noopener noreferrer"&gt;this repo&lt;/a&gt;, (yes, I'm shamelessly advertising my own repos), and tweak it to your liking.&lt;/p&gt;

&lt;p&gt;Create a .env file in the root of your project and add your API key and space ID as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VITE_CONTENTFUL_DELIVERY_API_TOKEN=&amp;lt;insert_contentful_api_key_here&amp;gt;
VITE_CONTENTFUL_SPACE_ID=&amp;lt;insert_contentful_space_id_here&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need a quick explanation of what all folders and files represent or if you're new to svelte kit, you can checkout &lt;a href="https://kit.svelte.dev/docs/introduction" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;We'll create a lib folder inside the src folder that will contain all the components and library files that we'll require.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is a simple alias to src/lib, or whatever directory is specified as config.kit.files.lib. It allows you to access common components and utility modules without ../../../../ nonsense.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Create a &lt;code&gt;contentfulClient.js&lt;/code&gt; inside the &lt;code&gt;lib&lt;/code&gt; folder to intialize the contentful SDK.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;contentful&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;contentful&lt;/span&gt;&lt;span class="dl"&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;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;contentful&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;space&lt;/span&gt;&lt;span class="p"&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;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VITE_CONTENTFUL_SPACE_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;accessToken&lt;/span&gt;&lt;span class="p"&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;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VITE_CONTENTFUL_DELIVERY_API_TOKEN&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an &lt;code&gt;data.json.js&lt;/code&gt; file in the routes folder. This file will include the logic that gets data from the contentful CMS. The retrieved blogs are then passed onto the body of the index.svelte file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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;$lib/contentfulClient&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&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;get&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// get all blogs from Contentful&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;blogs&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;getEntries&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;content_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;blog&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blogs&lt;/span&gt;&lt;span class="p"&gt;)&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="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;blogs&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;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;404&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;The &lt;code&gt;content_type&lt;/code&gt; can be found from the content model sidebar on the right labeled as CONTENT TYPE ID. This will be used to return all entries in the content type model you created. &lt;/p&gt;

&lt;p&gt;The routes folder contains the routes, hence the index.svelte site represents the root path. &lt;/p&gt;

&lt;p&gt;Delete everything in the index.svelte file and add the following.&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="nt"&gt;&amp;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;load&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;fetch&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;blogs&lt;/span&gt; &lt;span class="p"&gt;}]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/data.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;blogs&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="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&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;base&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;$app/paths&lt;/span&gt;&lt;span class="dl"&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;blogs&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    {#each blogs.items as blog}
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"column"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;{`${base}/${blog.fields.slugField}`}&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            {blog.fields.title}
        &lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{blog.fields.datePublished}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    {/each}

&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;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;In the module script, we fetch the blogs variable we had instantiated from the &lt;code&gt;data.json.js&lt;/code&gt; file. The &lt;code&gt;&amp;lt;script context="module"&amp;gt;&lt;/code&gt; is necessary because load runs before the component is rendered. Code that is per-component instance should go into a second &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;{base}&lt;/code&gt; is a string that matches config.kit.paths.base. It must begin, but not end, with a /. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The slugField will be used to uniquely identify a specific blog post while maintaining SEO for the entire site. We now need a way to access a specific blog post and have the content retrieved from the API as markdown to be rendered as HTML.&lt;/p&gt;

&lt;p&gt;For the rendering, we'll need to install an extra package. We'll need &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;marked&lt;/code&gt; - a low-level markdown compiler for parsing markdown without caching or blocking for long periods of time.**
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i marked
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a folder called &lt;code&gt;components&lt;/code&gt; inside the &lt;code&gt;lib&lt;/code&gt; folder which will contain different components. Afterwards, create a file &lt;code&gt;RichContent.svelte&lt;/code&gt; that will contain the code necessary to convert rich text to HTML.&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&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;marked&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;marked&lt;/span&gt;&lt;span class="dl"&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;richContent&lt;/span&gt; &lt;span class="o"&gt;=&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;renderer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;marked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Renderer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nl"&gt;$&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;pageContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;marked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;richContent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;renderer&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;div&amp;gt;&lt;/span&gt;{@html pageContent}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll need a way for svelte kit to fetch dynamic content based on the route. We'll create a &lt;code&gt;[slug].json.js&lt;/code&gt; file inside the routes folder that will allow us to fetch dynamic content based on the route visited.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Dynamic parameters are encoded using [brackets]. For example, a blog post might be defined by src/routes/blog/[slug].svelte. These parameters can be accessed in a load function or via the page store.&lt;/p&gt;

&lt;p&gt;A file or directory can have multiple dynamic parts, like [id]-[category].svelte. (Parameters are 'non-greedy'; in an ambiguous case like x-y-z, id would be x and category would be y-z.)&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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;$lib/contentfulClient&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&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;get&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// the `slug` parameter is available because this file&lt;/span&gt;
    &lt;span class="c1"&gt;// is called [slug].json.js&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;blog&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;getEntries&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fields.slugField&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;params&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="na"&gt;content_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;blog&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blog&lt;/span&gt;&lt;span class="p"&gt;)&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="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;blog&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;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;404&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;The code is almost similar to the one in the &lt;code&gt;data.json.js&lt;/code&gt; file but only one post is retrieved since we're matching posts with the slugField that is similar to the url visited. We'll create a &lt;code&gt;[slug].svelte&lt;/code&gt; file that will be used to define how the page will be rendered and to be able to use the content retrieved from the Contentful CMS.&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="nt"&gt;&amp;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;load&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;params&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;params&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="s2"&gt;.json`&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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&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;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&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;blog&lt;/span&gt; &lt;span class="p"&gt;}&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="na"&gt;blog&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;blog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&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;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="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Could not load &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;url&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="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;RichContent&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;$lib/components/RichContent.svelte&lt;/span&gt;&lt;span class="dl"&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;blog&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container application-form"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"col-lg-12"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Course: {blog.fields.title}&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Date From: {blog.fields.datePublished}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

            &lt;span class="nt"&gt;&amp;lt;RichContent&lt;/span&gt; &lt;span class="na"&gt;richContent=&lt;/span&gt;&lt;span class="s"&gt;{blog.fields.content}&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;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;We import our &lt;code&gt;RichContent.svelte&lt;/code&gt; component and use it to convert rich text to html. The site is now ready for testing and deployment.&lt;/p&gt;

&lt;p&gt;Deployment will be done on &lt;a href="https://www.netlify.com/" rel="noopener noreferrer"&gt;netlify&lt;/a&gt; since it is one of the easiest and simplest to use. You can deploy the site on Github, Gitlab and/or Bitbucket which will allow for automatic deployments anytime you push to your hosted repository. You'll need an account, a &lt;code&gt;netlify.toml&lt;/code&gt; file in your root folder and the svelte kit netlify adapter in order to deploy the site. Extra instructions can be found on the &lt;a href="https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify" rel="noopener noreferrer"&gt;netlify-adapter GitHub README&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's install the svelte kit netlify adapter first and tweak the svelte config file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; @sveltejs/adapter-netlify@next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change the &lt;code&gt;svelte.config.js&lt;/code&gt; file to use the netlify adapter instead of the default adapter-auto. The &lt;code&gt;svelte.config.js&lt;/code&gt; should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;adapter&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;@sveltejs/adapter-netlify&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&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;join&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;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&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;readFileSync&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;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&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;cwd&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;process&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;pkg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cwd&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;package.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;

&lt;span class="cm"&gt;/** @type {import('@sveltejs/kit').Config} */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;kit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;split&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
        &lt;span class="p"&gt;}),&lt;/span&gt;
        &lt;span class="na"&gt;vite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;ssr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;noExternal&lt;/span&gt;&lt;span class="p"&gt;:&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;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pkg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dependencies&lt;/span&gt; &lt;span class="o"&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;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Afterwards, create a &lt;code&gt;netlify.toml&lt;/code&gt; file in the root folder of your application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This will determine where to write static assets based on the build.publish settings.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[build]&lt;/span&gt;
  &lt;span class="py"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"npm run build"&lt;/span&gt;
  &lt;span class="py"&gt;publish&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"build/"&lt;/span&gt;
  &lt;span class="py"&gt;functions&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"functions/"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember to add your environment variables in the environment sub section inside the build and deploy section on Netlify in order to secure your API token while ensuring your app has access to the environment variables.&lt;/p&gt;

&lt;p&gt;And voilà, we are ready to connect to netlify and deploy this application. All you need is to follow the instructions on the netlify site and you'll have your site up and running after the build is complete. &lt;/p&gt;

&lt;p&gt;Thank you very much for your time, any comments, reviews, news and critics will be highly appreciated. Till next time.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>svelte</category>
      <category>programming</category>
    </item>
    <item>
      <title>Free design resources you probably didn't know about Part 1</title>
      <dc:creator>Wesley Mutwiri</dc:creator>
      <pubDate>Mon, 14 Feb 2022 09:05:34 +0000</pubDate>
      <link>https://dev.to/wesleymutwiri/free-design-resources-you-probably-didnt-know-about-part-1-468n</link>
      <guid>https://dev.to/wesleymutwiri/free-design-resources-you-probably-didnt-know-about-part-1-468n</guid>
      <description>&lt;p&gt;Recently, I started on the &lt;a href="https://www.dailyui.co/"&gt;Daily UI 100 days of design&lt;/a&gt; challenge and the biggest challenge I've faced so far, obviously not counting consistency and procrastination issues, is finding inspiration and design resources.&lt;/p&gt;

&lt;p&gt;This post is mainly for me to bookmark different design resources so that I'll be able to come back to them every time I need to create a new design. Most resources fall in various categories such as illustrations, icons, images, videos, inspiration, fonts, colors or animations.&lt;/p&gt;

&lt;p&gt;I should probably mention that I am not being paid to advertise these resources, so this is an unbiased opinion(it is biased but let's pretend it is not for now). The listing is also random and is not a ranking of any kind.&lt;/p&gt;

&lt;p&gt;Without further ado, let's get started on the different resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Typography Resources
&lt;/h2&gt;

&lt;p&gt;A good font pairing, especially for a website can be what determines whether your design looks professional, creative or just plain when designing. They include:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Google fonts
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Google Fonts (formerly known as Google Web Fonts) is a font embedding service library. This includes free and open source font families, an interactive web directory for browsing the library, and APIs for using the fonts via CSS and Android.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Quoted from&lt;/em&gt; &lt;a href="https://en.wikipedia.org/wiki/Google_Fonts"&gt;&lt;em&gt;Wikipedia&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As the description says, Google fonts' catalog places typography front and center. All fonts on the site are free and open-source, making their fonts available to everyone.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://fonts.google.com/"&gt;Google Fonts&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Font Joy
&lt;/h3&gt;

&lt;p&gt;Getting font pairs is a very difficult task, but with font joy, you can easily pair different fonts and see how they would look in real-time.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://fontjoy.com/"&gt;Font joy&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Font squirrel
&lt;/h3&gt;

&lt;p&gt;If all the fonts on google fonts are not tickling your fancy, this is what we might call, the boss level of font resources. All fonts hosted are free for commercial use.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.fontsquirrel.com/"&gt;Font squirrel&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Font pair
&lt;/h3&gt;

&lt;p&gt;Don't have the time and energy to generate different font pairings and only need to get a simple pair, or maybe you need inspiration on which font pairs you can use. This is the site that helps you do all that. Find font pairings as well as how they've been used together.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.fontpair.co/"&gt;Font pair&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Typio
&lt;/h3&gt;

&lt;p&gt;Another font inspiration site where you can find out how to use different font pairs. You can also easily find font pairs for different categories of work such as travel, hotels etc.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://typ.io/"&gt;Typ&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Color resources
&lt;/h2&gt;

&lt;p&gt;Is it color or colour, that all depends on whether you use American or British English, either way, color(using this spelling because of auto correct nothing serious) has a huge impact on design. Decades of work has gone into researching how different people passive color and the impact it has on businesses in general.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Coolors
&lt;/h3&gt;

&lt;p&gt;A color palette generator that helps you visually see how different colors will look when used together.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://coolors.co/"&gt;Coolors&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Happy hues
&lt;/h3&gt;

&lt;p&gt;A simple color palette inspiration site that shows you a real world example of how to combine different colors in your design project. The colors used here, however, might backfire as I've painfully come to see, so use with caution.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.happyhues.co/"&gt;Happy Hues&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Color Wise
&lt;/h3&gt;

&lt;p&gt;Another color palette generator where one can get different colors that can easily be used together.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://colorwise.io/"&gt;ColorWise&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Palettable
&lt;/h3&gt;

&lt;p&gt;This is basically just tinder but for colors. Like if you want to continue with the color and dislike otherwise, it then automatically suggests the next color that can be used with the current color liked.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.palettable.io/"&gt;Palettable&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Picular
&lt;/h3&gt;

&lt;p&gt;If palettable is a tindr for colors, then picular is a google for colors. Just search for any word and it will automatically provide you with different colors associated with the word you've searched.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://picular.co/"&gt;Picular&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6. 99 Designs
&lt;/h3&gt;

&lt;p&gt;I'll add blog resources on how to choose colors and a short blog on the psychology of color which is very important when deciding which palette one should use.&lt;/p&gt;

&lt;p&gt;Link for psychology of colors: &lt;a href="https://99designs.com/blog/creative-inspiration/psychology-color-web-design/"&gt;Psychology of colors&lt;/a&gt;&lt;br&gt;
Link for color generator: &lt;a href="https://99designs.com/logo-design/psychology-of-color"&gt;99Designs color Generator&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Icon Resources
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Feather icons
&lt;/h3&gt;

&lt;p&gt;One of my favorite go to places for getting icon resources. Free SVG icons that can easily be copied and pasted in your website code or UI designs without much stress.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://feathericons.com/"&gt;Feather Icons&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Font Awesome
&lt;/h3&gt;

&lt;p&gt;If, you're a web developer you've definitely come across this resource, if you haven't then it's definitely worth your time&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://fontawesome.com/"&gt;Font Awesome&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Flaticon
&lt;/h3&gt;

&lt;p&gt;If you ever see an icon and have no idea where to find it? This is probably the place to look for it.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.flaticon.com/"&gt;Flaticon&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Icons8
&lt;/h3&gt;

&lt;p&gt;Another one . This site also includes images, illustrations and even music.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://icons8.com/"&gt;Icons8&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Streamline
&lt;/h3&gt;

&lt;p&gt;Just like Icons8, they also do almost everything from illustrations, icons and emojis&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://app.streamlinehq.com/illustrations"&gt;Streamline&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Ionicons
&lt;/h3&gt;

&lt;p&gt;Font awesome alternative that contains only free and open source icons&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://ionic.io/ionicons"&gt;Ionic&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Illustrations
&lt;/h2&gt;

&lt;p&gt;Need drawings and animated characters, look no further.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Undraw
&lt;/h3&gt;

&lt;p&gt;Get free illustrations for anything you want. Change the colors and click to download whichever illustration fits you best. With a search powered by &lt;a href="https://www.algolia.com/"&gt;algolia&lt;/a&gt; you can be assured you'll find things easily.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://undraw.co/illustrations"&gt;Undraw&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Open doodles
&lt;/h3&gt;

&lt;p&gt;A free set of illustrations. The illustration's design is quite unique and interesting. You can either download the image or use a link to the resource.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://opendoodles.com/"&gt;Open Doodles&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Icons8
&lt;/h3&gt;

&lt;p&gt;Seems like the only thing they don't offer is financial aid&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://icons8.com/"&gt;Icons8&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Illustrations co
&lt;/h3&gt;

&lt;p&gt;Download either SVG or PNG illustrations for free, all with unique designs.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://illlustrations.co/"&gt;Illustrations co&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. IRA design
&lt;/h3&gt;

&lt;p&gt;Create and customize your illustrations with this free site. Change the background, the characters, colors etc and create your own custom illustration&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://iradesign.io/"&gt;IRA Design&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Blush
&lt;/h3&gt;

&lt;p&gt;Small PNGs are the only illustrations you can download but that is more than plenty.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://blush.design/"&gt;Blush Design&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Streamline
&lt;/h3&gt;

&lt;p&gt;Not quite sure, how this might help when you can't customize the colors without an upgrade but at least it's a resource that one can download either SVG, PDF or PNG formats&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://app.streamlinehq.com/illustrations"&gt;Streamline&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's take a break
&lt;/h2&gt;

&lt;p&gt;The list is not exhausted but I believe in short blog posts and not 30 minute reads so I'll break this into two parts. Part two coming soon, so stay tuned.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/LFEjnqmVmbKk8/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/LFEjnqmVmbKk8/giphy.gif" alt="I'll be back gif" width="500" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>design</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Create Beautiful Charts with Svelte and Chart js</title>
      <dc:creator>Wesley Mutwiri</dc:creator>
      <pubDate>Thu, 10 Feb 2022 15:33:31 +0000</pubDate>
      <link>https://dev.to/wesleymutwiri/create-beautiful-charts-with-svelte-and-chart-js-512n</link>
      <guid>https://dev.to/wesleymutwiri/create-beautiful-charts-with-svelte-and-chart-js-512n</guid>
      <description>&lt;p&gt;&lt;a href="https://svelte.dev"&gt;&lt;em&gt;Svelte&lt;/em&gt;&lt;/a&gt; is a &lt;strong&gt;JavaScript compiler&lt;/strong&gt; that compiles its code to HTML, CSS and vanilla JavaScript hence creating a very performant website. On the official website, there is a &lt;a href="https://svelte.dev/tutorial/basics"&gt;&lt;strong&gt;tutorial&lt;/strong&gt;&lt;/a&gt; that explains Svelte step-by-step. If you just want to see the completed code and figure it out by yourself, go to the &lt;a href="https://codesandbox.io/s/svelte-chart-js-tutorial-5gr4o"&gt;&lt;strong&gt;code&lt;/strong&gt;&lt;/a&gt; for this article.&lt;/p&gt;

&lt;p&gt;Now that the introduction and pleasantries are out of the way, it is time for the main event. I'll be assuming that the desktop environment being used in this tutorial is Linux based for the initial setup of a svelte application and you already have node and npm installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;So as to be able to fully work on the application at hand, you'll need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Familiarity with HTML, CSS and JavaScript(ES6+),&lt;/li&gt;
&lt;li&gt;Node.js and npm installed on your development machine.&lt;/li&gt;
&lt;li&gt;Working machine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this tutorial, we shall be using the &lt;a href="https://www.chartjs.org/"&gt;Chart js&lt;/a&gt; library for creating basic charts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Chart.js
&lt;/h2&gt;

&lt;p&gt;That's a pretty good question actually, why would anyone decide to use chart JS whereas there are very many other charting libraries out there that are more performant? The simple answer is that Chart JS(According to sources called "this is my opinion") is easier to use. Some of the alternative charting libraries include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://pancake-charts.surge.sh/"&gt;pancake&lt;/a&gt; which has very scarce documentation and is in thorough experimentation(at the time of writing). Since it has been created by Rich Harris, you can rest assured that it might probably never get documentation or a stable release just like our fallen soldier &lt;a href="https://sapper.svelte.dev/"&gt;sapper&lt;/a&gt; (a moment of silence in remembrance)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gionkunz.github.io/chartist-js/"&gt;Chartist&lt;/a&gt; -  Really impressive charting library that is only 10KB (Gzip) with no dependencies. Round of applause for this awesome library that should play nice with svelte since it does not have any dependencies. I honestly can't remember why I didn't go with this for this tutorial but there's always time for another tutorial, am I right 😉?&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://d3js.org/"&gt;d3.js&lt;/a&gt; - Great library, but it would take me to long to explain whereas I'm trying to write a super simple tutorial. I would also recommend this library, though those examples they present are thoroughly intimidating, like this example where you create a &lt;a href="https://observablehq.com/@mbostock/voronoi-stippling"&gt;chart of Obama's face&lt;/a&gt; using Voronoi Stippling(not a clue what that is and my furniture just started floating around once I spoke those words out loud)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;You could use &lt;a href="https://codesandbox.io"&gt;codesandbox&lt;/a&gt; for your initial setup or create a local svelte application using the &lt;a href="https://github.com/Rich-Harris/degit"&gt;degit&lt;/a&gt; tool. Open a new terminal 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;    npx degit sveltejs/template standard-charter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate into the newly created project folder and install the dependencies locally using:&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;standard-charter
    npm &lt;span class="nb"&gt;install&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the development server using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    npm run dev 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dev server will be listening from the &lt;a href="http://localhost:5000"&gt;http://localhost:5000&lt;/a&gt; address. Any changes made to the application will be automatically rebuilt and reloaded into the running app as long as the dev server is still running.&lt;/p&gt;

&lt;p&gt;You'll also need to install &lt;a href="https://www.chartjs.org/"&gt;Chart js&lt;/a&gt; using:&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;chart.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the App.svelte file, delete everything leaving only the script tags. Since this is a relatively simple app, this is where all our code will reside in.&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&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;onMount&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;svelte&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Chart&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;chart.js/auto/auto.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;portfolio&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Expenses&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Savings&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Investments&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="na"&gt;datasets&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;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My First Dataset&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#7000e1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#fc8800&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#00b0e8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="c1"&gt;// hoverOffset: 4,&lt;/span&gt;
                    &lt;span class="na"&gt;borderWidth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&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;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;doughnut&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&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;borderRadius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;30&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;responsive&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="na"&gt;cutout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;95%&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;spacing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="na"&gt;legend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="na"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bottom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="na"&gt;display&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="na"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                            &lt;span class="na"&gt;usePointStyle&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="na"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="na"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                                &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;14&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;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="na"&gt;display&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="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My Personal Portfolio&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="p"&gt;};&lt;/span&gt;
      &lt;span class="nx"&gt;onMount&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;portfolio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;// Initialize chart using default config set&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myChart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Chart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;config&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;canvas&lt;/span&gt; &lt;span class="na"&gt;bind:this=&lt;/span&gt;&lt;span class="s"&gt;{portfolio}&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;{400}&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;{400}&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it folks, a very good looking doughnut chart that showcases your "sample budget".&lt;/p&gt;

&lt;p&gt;We add the creation of the chart on the svelte &lt;code&gt;onMount&lt;/code&gt; function so that the chart is created and added to the layout before it is mounted on the page. Note that the value of &lt;code&gt;canvas&lt;/code&gt; will be &lt;code&gt;undefined&lt;/code&gt; until the component has mounted, so we put the logic inside the &lt;code&gt;onMount&lt;/code&gt; &lt;a href="https://svelte.dev/tutorial/onmount"&gt;lifecycle function&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The read-only &lt;code&gt;this&lt;/code&gt; binding applies to every element (and component) and allows you to obtain a reference to rendered elements. For example, we can get a reference to a &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; element:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://svelte.dev/tutorial/bind-this"&gt;&lt;em&gt;svelte bind example&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Chart JS receives the data from the &lt;code&gt;data&lt;/code&gt; variable we created. We have customized the labels as well as the background color of the doughnut lines.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;config&lt;/code&gt; variable is what we've used to define the type of chart and to style the chart we've created. The &lt;code&gt;type&lt;/code&gt; can be either bar, line, pie, radar etc etc depending on the type of chart you want to render. You can play around with the sample data we've provided to see what kind of chart will be formed.&lt;/p&gt;

&lt;p&gt;In a real life situation, the data to be displayed would be provided from an external service such as an API rather than have it hard coded as a variable.&lt;/p&gt;

&lt;p&gt;Reducing the &lt;code&gt;cutout&lt;/code&gt; percentage will make the doughnut chart slightly less hollow and a 0% cutout will make it a pie chart.&lt;/p&gt;

&lt;p&gt;If you need to make multiple charts on the same page then it would be simpler and easier to copy the code and convert it into a component where you export defaults. But that is all the time I have for this week folks, stay tuned for more next week.&lt;/p&gt;

&lt;p&gt;PS. Shameless plug - Visit my blog at &lt;a href="https://wesleyblog.netlify.app/"&gt;Wesley's Blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>chartjs</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
