Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop

Rate this content
Bookmark

This SvelteKit workshop explores the integration of 3rd party services, such as Storyblok, in a SvelteKit project. Participants will learn how to create a SvelteKit project, leverage Svelte components, and connect to external APIs. The workshop covers important concepts including SSR, CSR, static site generation, and deploying the application using adapters. By the end of the workshop, attendees will have a solid understanding of building SvelteKit applications with API integrations and be prepared for deployment.

This workshop has been presented at JSNation 2023, check out the latest edition of this JavaScript Conference.

FAQ

Storyblock is a content management system (CMS) used for creating and managing website content. It allows users to manage content through a backend system and integrate this content with various frontend technologies via APIs, making it adaptable for headless CMS architectures.

SvelteKit integrates with Storyblock through APIs that Storyblock provides. Developers can use SvelteKit to build the frontend of a website, fetching and displaying content managed in Storyblock by making API calls and using SDKs provided by Storyblock for easier integration.

Using a headless CMS like Storyblock offers flexibility in choosing frontend technologies, facilitates content reusability across different platforms, improves performance through efficient content delivery networks, and enhances scalability and security by serving content through APIs.

Yes, Storyblock allows customization of content delivery. Users can manage how content is structured and delivered through Storyblock's admin interface and can define custom content types and components to fit their specific project requirements.

To deploy a SvelteKit application integrated with Storyblock, developers need to configure the build settings to generate a static site if preferred, set up environment variables for API keys, and potentially use services like Netlify for continuous deployment. Changes in the Storyblock content can trigger rebuilds of the static site through webhooks.

Storyblock supports internationalization by allowing users to create and manage content in multiple languages. Content can be created for different locales, and the CMS can serve the appropriate language version of the content based on the user's preferences or settings.

In SvelteKit, adapters are used to configure how the application is built and deployed. For example, the static adapter can be used to generate a fully static site that can be hosted on any static web hosting service. This is particularly useful for optimizing performance and scalability.

Alba Silvente Fuentes
Alba Silvente Fuentes
Roberto Butti
Roberto Butti
174 min
15 Jun, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Today's workshop focused on creating a website using SvelteKit and Storyblock CMS. It covered topics such as installing SvelteKit and integrating Storyblock, configuring SSL for localhost, connecting Storyblock SDK with a space, retrieving data and setting up preprocess, creating components and styling with Tailwind, compiling components and troubleshooting, creating dynamic pages and adding fields to the schema, working with the image service, and deploying and internationalization. The workshop also touched on advanced topics like multilingual support and emphasized the importance of being familiar with a good CMS and framework for job opportunities.

1. Introduction to Gemstack and Headless CMS

Short description:

Today we are going to see how to create a Gemstack site or in general a website using Svelkit and Storyblock. Storyblock is a CMS that allows you to create and manage content. There are different types of CMS, including traditional CMS and headless CMS. Traditional CMS allows you to build and manage websites without coding, but customization is limited. Headless CMS separates the backend for managing content from the frontend, giving you more flexibility to choose your frontend stack. Today, we will focus on creating and structuring content with Storyblock and building the frontend with Svelkit.

Today we are going to see how to create a Gemstack site or in general a website using Svelkit and Storyblock. Storyblock is a CMS, so is a tool where you can use for creating the content and for managing the content, but on the market, we have different kinds of CMS of content management system. We have traditional CMS and headless CMS, right.

In the past, we have monolithic CMS or traditional CMS and use a software application that allows the user or the content creator to build and manage website without having to code and so it was quite easy. But at the end, you can create the content and you can deliver the content or the website only for the website. Right. And you can start quickly to create a website with a traditional CMS, with a monolithic CMS.

But at the end, if you want to customize something, for example, in the frontend, you have to follow some best practice provided by the CMS, because the CMS provides the Udate template updating system. And so you have to follow their rules. Right. Some examples are, for example, WordPress, Drupal, Sikore, and so on. Right. And typically, if you want to manage the content and you want to deliver also the frontend, you have to deploy the whole system. Right. So even if you are changing a little bit in the CMS, you have to deploy all the CMS. Because, the frontend is as strictly related with the backend. The backend is used for managing the content.

We have on the market a different approach. Another approach is, for example, using a headless CMS. In this case, you have split two parts. One is the backend for just managing the content. And indeed the headless content management system is a software application that allows the user and team to manage the content, not to create the website. So, to manage the content and the process. For example, creating the content, reviewing the content, previewing the content, and deploy the content. So, you have multiple tools for managing the content. And then, on the other side, you can create your own frontend. And obviously, in this case, because the frontend is totally the couple with the content, you have to integrate it, right?

Typically, the headless CMS allow you to create the content and then expose this kind of content, the APIs. So, you, as a frontend developer, you have the freedom to choose your own framework, SvelteKit or Svelte or Next React or Nuxt and Vue. So, you have the freedom to choose your stack, frontend technology stack, and you have to integrate via API. So, what is provided by the headless CMS? Typically, it is an admin interface for managing the content, storing the content, and then providing the content via the API. In this case, today, we are going to create and structure the content with Storyblock, so for the part of the content editors. Then, Storyblock exposes the content delivery API. So, this is out of the box. So, today, as a frontend developer, we can focus on the part that we like and we love, so the frontend part. So, we can choose our frontend framework and today, obviously, Svelkit and we can build our frontend. When we need the frontend and the content, we can integrate the APIs provided by the Storyblock. We will use an SDK provided by Storyblock to integrate in an easy way the APIs. So, we will see what we need from the frontend perspective for integrating with Storyblock. And then we can create our applications in a SvelteKit way, right, and we can deploy also the applications somewhere on the cloud. For example, if we will have time, we are going to deploy on Netlify, and then we can allow the end-user to consume our applications that we are going to build.

I explained a little bit the past traditional CMS and monolithic CMS. Today, we are going to use headless CMS. But why headless is better than traditional CMS? Because you have more flexibility and freedom because you can choose your front-end stack Probably if someone of you come from WordPress, probably you know that you are stuck in with some technology stack and you have to use their templating system, right? So, probably as a front-end developer, you are not happy because you can't use your own tool. Another reason for using the Endless CMS is because of the content reusability, right? We will see how we can structure the content and reuse the component that blocks across the pages. Improved performance because the APIs are provided by a system, in the case of Storyblock, by CloudFront, so by a CDN. And then you can focus on optimizing the performance of the frontend, right? Scalability, because, at the end, the endpoints are managed by the CMS, because, typically, the CMS are a SaaS application, right? So it's deployed on the cloud, so you can scale it up in an easy way. Future-proofing, because sometimes in the past, if you used WordPress, and you want to update WordPress, probably you have to rebuild the website, mainly when you have to switch for the major release. In this case, you can focus mainly on the frontend. And security and maintenance, because, at the end, the interface between the end user and the backend system is limited by the APIs, right? So, in this case, you can consume the API. The APIs are mainly read-only, so you can have more security. And, typically, enterprise CMS like Storyblock are following some certification, some rules, OWASP rules. They are ISO 27001. So, what I'm trying to say is that they are enterprise level, so they are taking care about the security. Someone else checks the security, and so on, right? Good.

So, now we can start. So, a brief introduction, but now we can start. And we prepared some exercises. Probably, we can copy and paste the URL of this document that we already prepared, right Alba? Yes. Okay, then here, you can, if you click, Alba brought a URL in the chat, if you open the chat, and also you open the URL, you will access to some of our exercises. Yes. Please let us know if you have access, to double check with you. But I am pretty sure you will have access. Okay. I will publish it just in case. Just to guide you in this kind of exercise, let me explain a little bit. So now we are going to start to create a SvelteKit project. We can start for creating an empty SvelteKit project. So because, as far as understood, someone of you didn't use SvelteKit, so we can start creating Svelte, for example, a Svelte application. Do you agree? For installing a Svelte application, I think we can use npm. So now I'm going to create a name Total Empty SvelteKit application. As you can see, you can use npm, create Svelte, and then you can use the latest version. Then you can create MyApp. MyApp is the folder where we are going to create the application. If you want, you can use your terminal and then you can follow these kind of instruction to do the same on your local computer. If you have some doubt or you don't know, please raise your hands or write in the chat. Now I try to go slow, just to be sure that you can follow us. With this kind of command, we can create an empty application so we can answer to some question if we want a Svelte demo app, or a skeleton project, or a library project. In this case, skeleton project. Then you can decide to use JavaScript JSDoc, or TypeScript, or normal. For now, we want to see how to create a empty SvelteKit application so we can select JavaScript with JSDoc commands. Then we can add some nice tools. For example, Slink, Prettier, Playwright, and VTest. First two are about linking and formatting. Then we have also the opportunity to install some testing tool, for example, like Playwright and VTest. But for now, personally, typically I choose Prettier. You can choose more than one, but now we can choose only one. Then we can click Enter. Then we can enter into the new directory. The new directory, as you can see, we have some files created by the command, and then we can go via npm install. We are installing the packages.

2. Installing SvelteKit and Integrating Storyblock

Short description:

In this part, we learn how to install SvelteKit and understand its structure. We also explore the integration of Storyblock CMS using the Create Demo tool. The tool creates an empty SvelteKit application with Storyblock integration in place. We can launch the tool using MPX and provide the necessary details. The tool sets up the project with the required dependencies and instructions for the integration. We can then execute the server and see the simple page with content from Storyblock. The package.json file includes additional dependencies for the integration. We have the Story Block component in the routes directory. Now, we can proceed to create a project from scratch with Storyblock configuration and retrieve data from Storyblock.

Obviously, I'm using npm, you can use yarn or pmpm and so on. Then we can add the Git, but for now it's not important. Then we can run npm run dev, so the server. Running the server, we have the web server is running, so now, let me show you. This is the empty page of our SvelteKit application. It means that we are able to install SvelteKit. Why I want to create an empty application just to allow you to understand the structure of a typical empty SvelteTask application. In this case, we are not integrating the CMS, we are just installing the application. Probably you can see, put it, and then also the head. Probably you can see my editor, is correct. Then we can see that we have the directory with the source code, and then we have two files, app.d.ts and app.html. Then we have the routes directory mainly where we have the page. We will see a little bit later about the routing system, but for now, the page that we can see in the browser is in the pluspage.svelte. If we are going to change something here, and then we can switch, for example, to the browser. Too many screens. We can open it. Then as you can see, we have the Hello. It's very easy, but allow us to understand the structure of the empty application.

Now, what if we want to add the Storyblock integration? From the Storyblock side, let me start with using our tool named Create Demo. Create Demo is a tool provided by the Storyblock that allow you to create in the same way that we did before, an empty application with integration already in place with Storyblock. It means that we are going to launch a command. Now, we can see. Then we will see more or less the same structure, but with some integration with Storyblock. Storyblock is your CMS. Exactly, yes. Is the CMS that we are going to use. But today, we'll be mainly focused on the Svelki part. In this case, I can remove, for example, the empty application. Because we created an empty application just for example, and then we can use our created demo tool. To do that, we can do, we can launch more or less in the same way than before. We can use MPX and then we can create the demo. Storyblock create demo with the latter's version. Then we want to create a folder, MyDemo. Then we can define which framework we want to use, and today we are using Svelkit, so we are going to use Svelkit. Then we can define which kind of package manager we want to use, and optional thing, but just to allow you to understand, we are going to define the region, the AWS region that we can use for the CMS, not for the front end, for the CMS, for the part that you want to use and manage In this case, my expectation is to have a MyDemo folder. We does velgit application with some packages added and some instruction added for the integration with the Storyblock. More or less, similar, the same. We can execute the system, the tool asks us the access token because if you want to integrate your front-end with the Storyblock, you need to use an access token. For now, we can skip this part because we will use the full space. Then for this question, we can say, we will see later about the HTTPS and the tool create the demo. Take a while because under the hood, the command that takes a clone, better clone repository from GitHub, where we have already a Svelkit application, an empty Svelkit application with some packages for integrating Svelkit and Storyblock. Then we can jump into the directory and then execute npm install and then executing the server. Now the server is up and running. In this case, we have this kind of message because we have the configuration to serve the page via HTTPS even if we are in local, okay? It will be very important to serve the page via HTTPS because the configuration forстаrts using the 3G phone network. And the cuz we use the network via HTTPS. We will see why in a few minutes. So then we can accept the certificate because we are in local. So the Vita because under the hood we are using a Vita, create the certificate, self-assigned the certificate for running localhost. So it's okay because the machine is. And as you can see, we have already a very simple page. Okay, very simple page with some content. For example, this hello world, feature one, feature two and feature three. And a little spoiler, this kind of content come from Storyblock. So it means that we have already integration. We have already placed an integration. So let me do the same that I did before. So opening the editor and then see something about the structure, right? So in this case, we have more or less the same structure than before. But in this case, in the package.json, we have some dependency more. For example, this is the SDK that we provide for the integration with the Story Block. We have, for example, this plugin that allow us to start the local web server via HTTPS. And some other stuff, for example, because we are using a Tailwind CSS, but it's not mandatory. This is just an example, right. Then, we have in the routes directory, we have more files than before, but at the end, as you can see, we have page.swelt, where we have the Story Block component. Now, we're going to see every piece and commenting this. Just to let you know that via the Create Daemon application, you have the structure already in place, you have a minimal installation and you have some file already in place, but now we understand that we can start from Svelte kit application. We can add the integration with the Storyblock. Now with Alba, you can take the... we are going to create a project from scratch and with the configuration with Storyblock because we want to create the content in Storyblock and we want to create our Svelte kit application that uses and retrieves data from Storyblock. Exactly. Do you have some questions till now? No questions, okay. In general, if you have questions while we are explaining a little bit, you can write a message. Yeah, but now because we do a lot of magic using some commands, right? Now we can do the same thing like how you will be stepping step. So you can understand all the process, right? Exactly. So if you want, we can, you can share the screen Alba, you want or? Yeah, I can. Yeah, let's do that. So I can, okay, share the screen, the desktop too, that's the right one. Okay, perfect. Can you see properly the size of the screen is okay? Okay, nice. Well, yeah, the idea was I landed into the notion page that we have just to let you know that you have here all the resources we will be sharing and also the exercise that we will be making and also the versions that you need to have, for example, for node, because our SDK under the hood is using the fetch native API. So in order to support it, you need to use these kinds of versions or up, but as we are using SpellKit, and it's kind of modern, everyone will use this kind of node version. So I don't think it's a problem anymore. And here you have all the links to everything that we will explain. And also the boiler plate repositories we created for each of the exercises. You'll have a branch for each of the exercises. So in case you get lost, you can always on load the branch and get up to speed really fast. And here you have the repository that we will end up creating with all the exercise by branches, as I told you. And you can go one by one and check if you change something in your code or whatever. And the live version of the project we will be creating. That is just a basic stuff. I mean, nothing fancy, just an article inside a blog and yeah, some kind of text.