Crash Course Into Astro, Kontent.ai and Portable Text

Rate this content
Bookmark

During this crash course, we’ll create a new project in the headless CMS, create the content model and data using the Kontent.ai CLI. Then, we’ll use the content to build an Astro website including front-end components and rich text resolution using Portable Text.


This will be hands-on workshop, you’ll need VS Code, Git, NPM and basic knowledge of JavaScript. Don’t worry, I will explain all the steps as we advance through the workshop and you will be able to directly ask any questions.

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

FAQ

The workshop aims to provide an overview of integrating various technologies with a headless CMS using Astro, including importing content, creating components, and implementing rich text resolutions. It is designed for participants to follow along and apply the concepts in real-time.

The workshop covers frontend development using Astro, TypeScript, and the headless CMS from Content.ai. It includes hands-on exercises with Visual Studio Code, Git, and integration of these technologies to build a sample airline website.

A headless CMS, like Content.ai used in the workshop, is a back-end only content management system that provides content as data over APIs without a built-in presentation layer. It allows developers to use their own tools and technologies to present content, which in the workshop is demonstrated by integrating with an Astro project.

Astro is presented as a modern web development framework that focuses on delivering efficient, performant websites by shipping less JavaScript. It allows developers to build websites using UI components and supports multiple rendering strategies, making it suitable for various web projects.

Portable text is a standard for representing rich text data independently of the underlying CMS. In the workshop, Andrej demonstrates how to convert rich text from Content.ai into portable text format, enabling easier integration and manipulation within the Astro framework.

Participants in the workshop undertake tasks such as setting up a project environment, importing content into Content.ai, creating and running an Astro project, and implementing features like rich text resolution and type-safe data fetching with TypeScript models.

The final output of the workshop is a fully functional sample website for an airline, named Contenare, built using Astro and Content.ai. The website demonstrates the integration of various technologies and the practical application of headless CMS in frontend development.

Ondrej Polesny
Ondrej Polesny
91 min
22 May, 2023

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Today's workshop covers the basics of various topics, with a focus on Rich Text Resolution in Headless CMS. Participants will learn how to import content, create pages and components, generate TypeScript models, and resolve rich text. The workshop also discusses portable text and its benefits. The use of Astro as a front-end framework is highlighted, along with its compatibility with React, Vue.js, and vanilla JavaScript. Participants will also learn about working with environments, fetching data, and adding custom components in Astro.

1. Introduction and Agenda

Short description:

Hello everyone, I'm Andrej. Today, we'll cover the basics of various topics and focus on Rich Text Resolution in Headless CMS. We'll import content, run a blank Astro project, create pages and components, generate TypeScript models, implement a listing page, and resolve rich text on the homepage. We'll also discuss portable text. You can find all the necessary links in the repository. You have the option to register for content.ai or use my project ID. Let's clone the repository and get started!

So hello, everyone. I'm Andrej. Thank you for being here. This should be a fun evening. I'm saying hello from the Czech Republic. These are all quite wide topics. So I'll try to cover at least the basics. I don't want to tell you everything about each of these topics but just give you an overview of how it all works together. Then of course if you're at the conference we can talk about it more there or you can find resources for all these online as well. My aim is to just have a good time for the next hour or two and we'll see hopefully you'll take something from it.

So I'm Andrej, I'm a developer evangelist here at Content.ai. We're a headless CMS vendor, so we are quite a bit in the field of websites, frontend development, Javascript and so on. My personal passion used to be.NET because I started as a.NET developer. These days I do pretty much everything, whatever is expected. So Astro is one of these projects where this was just the Nuke hit on the block and it was fun to do. That's me. I'll share the content details right after the workshop.

But let's take a look at what we're going to cover today. I want to make it brief. Nobody wants to be here for four hours. This is what we're gonna do. This is the website that we will finish at the end of the workshop. It's just a sample site for an airline. We call it Contenare because we are Content.ai. So it's quite a nice pun here. What we're going to focus on is the Rich Text Resolution because that's the biggest task of any website that is using Headless CMS. Now the agenda for today is first, this is gonna be a hands-on workshop. If you have your Visual Studio Code installed and ready to use, if you have Git, that's perfect. I'll just always give you a few minutes to do what I'm doing. But there's not gonna be a 15 minutes block where you will be working on your own. We don't have that much time for that. So what we're gonna do is import content into the CMS project. Then we're gonna run a blank Astro project. Now I've already created one for you so I'm just gonna give you the Git repository so you can clone that. So we don't have to waste time on that. We'll create two pages and a few components in Astro, so that you can see how easy it is to create these components. We'll generate strongly typed TypeScript models. It's… I call them models because as I said, I used to be a.NET developer, but these are actually types in TypeScript. But there's a script for those so that should be also quick. We're gonna implement a listing page that will list all the data that we have in the headless CMS. We'll implement rich text resolution on the homepage. And that's the end of it. We're then gonna turn the rich text resolution to portable text. I'm also gonna tell you what portable text is, if you're interested in that. So that's the agenda for today. That was I said, for every part of that I'll give you time to work on that. Let me see. Okay, here we go. So just to share quite a few important links. This is the repository that we will be working with. It's actually under my GitHub. I'm going to copy that link in the chat in a second so you don't have to write it from the slide. There is a links.txt file within that repository that contains all the other links. No need to write anything on your own, you can just do a copy-paste. Now as I mentioned, we're going to be using content.ai as the headless CMS as a content storage. Now, there are two options for you. Either you can register for a free plan or a free trial and do everything on your own. So I'm going to give you the import scripts and everything, it's quite easy to set up. Or I'm going to give you a project ID of my project and you can use that. Depends on what you're after. It's easier if you register on your own and import your own data and you can play around with it. You can click around the UI. But both options are possible. If you don't want to register. So now will be the time to clone the repository. So let me just copy the URL in the chat window. If I figure out how to open Firefox when zoom is here. Let me see. There's the linux.txt file. And there is the content.ai registration.

Read also

2. Register, Import Data, and Set Up Environment

Short description:

To get started, register and log in to the CMS. Then, import data into your project using the content.aicli. Make sure you have the necessary API keys and project ID. Clone the CLI repository and set up the environment. Refer to the Workshopx.pdf for detailed instructions.

If you want to register on your own, it's gonna take just a couple of seconds. So you can just copy that link is right here. And paste there. Obviously I'm already logged in. So I would just use sign in. But for joining, just put your email down and pick a password and get in there. I'm gonna give you a few seconds to do that while I fight my Firefox and other extensions.

Okay, now when you're registered, you should be seeing this but completely blank. So let's see if we can get through that. And of course, when you're starting with a blank project, the first step would be to actually import some data into the project so that we have something to work with. There are a couple of ways we can do that. The first one is a backup manager. So if you have your project, you then back it up into a zip package. You can use the backup manager to then import the zip package into another instance or another project. Today, we're going to use a better solution, and that is the content.aicli. Now, there is the next link below the registration is for the repository that contains all the data. So once you're done with the registration, this will be the next step to get to the CLI project. I'm going to clone that as well, if you can. I have both of these already cloned on my local so I'll just give you a few seconds to do the same. So just take the URL and clone it into your local.

All right, I'm going to open the project in Visual Studio Code. Now, just let me know in the chat when you're seeing the same thing as I am, so I know we can continue. Actually, this is the main project. This is the one I'm working on. There's another one. This is the CLI. Now, in the meantime, I'm going to create a new project for me too so that I can run the import with you. I can actually delete all of these and we have a blank project just like that. So just close this and delete all of these and remove the content apps as well. This is a pretty much empty project, so I can work with that. Let me know in the chat if you need more time. If you already have the project set up and the second repository cloned so that we can move on. Just to be sure, I'm going to put the second URL in the chat as well. But I hope that you are all finished by now. If not, let me know in the chat, yeah? I can wait or I can explain something further. Let's see that we are all here in the Content-Aware CLI. That's the second repository that I showed you. If you cloned that, that's perfect. Now, in order to import the data into the system, we're going to need two things. We'll need the delivery API ID. Every project that you create in the CMS has a project ID. There's this URL here. That's this part of the URL. It's also in the settings under Environment, ID. So if you go to Environment, Settings, General, then the project ID is right here. So I'm just going to copy that. I put it somewhere. Could be here or anywhere else, doesn't matter. I'm just going to create a new text file. Just put it here. This is the project ID. And there's another thing that we'll need. If you go back into the CMS, there is an API key section in the Environment, Settings, and we're also going to need the Management API. Now the Management API is an API that lets you edit content in the CMS. Now, the use cases we need to import data into the CMS. So we definitely need a management API to do that. So if you don't have that enabled, if it's a blank project, you first need to enable it with the toggle here and then generate your API key. First, it's not going to be here, you have to define the validity of the API key and then you'll be able to copy that. So copy that into the text file as well. So two API keys, right? One is for delivery API, one is for management API. And what we're going to do is we're going to create a new environment for the CLI. So let me show you the GitHub repository of the CLI where we have the examples. So let's go into repositories and look for CLI. It's this one. So for the setup, you're going to need to add environment, right? That's this part right here. It's also, by the way in the presentation that I've shared. So if you look at the main project, the first repository that I showed you there is a file called Workshopx.pdf. So in here, you're going to see the whole presentation that I'm showing, which also contains all the important commands, right? So feel free to use that as well. But right now, I'm just going to copy the command from the repository. So that's the content environment add-in.

Watch more workshops on topic

Fetch, useEffect, React Query, SWR, what else?
React Advanced 2023React Advanced 2023
102 min
Fetch, useEffect, React Query, SWR, what else?
Top Content
WorkshopFree
Ondrej Polesny
Ondrej Polesny
In this workshop, first, we’ll go over the different ways you can consume APIs in React. Then, we’ll test each one by fetching content from a headless CMS (with both REST and GraphQL) and checking in detail how they work.
While there is no advanced React knowledge required, this is going to be a hands-on session, so you’ll need to clone a preconfigured GitHub repository and utilize your preferred React programming editor, like VS Code.
You will learn:- What diverse data fetching options there are in React- What are advantages and disadvantages of each- What are the typical use cases and when each strategy is more beneficial than others
Building Blazing-Fast Websites with Next.js and Sanity.io
React Summit 2023React Summit 2023
71 min
Building Blazing-Fast Websites with Next.js and Sanity.io
WorkshopFree
Nancy Du
Nataliya Ioffe
2 authors
Join us for a hands-on workshop where we'll show you how to level up your React skills to build a high-performance headless website using Next.js, Sanity, and the JAMstack architecture. No prior knowledge of Next.js or Sanity is required, making this workshop ideal for anyone familiar with React who wants to learn more about building dynamic, responsive websites.
In this workshop, we'll explore how Next.js, a React-based framework, can be used to build a static website with server-side rendering and dynamic routing. You'll learn how to use Sanity as a headless CMS to manage your website’s content, create custom page templates with Next.js, use APIs to integrate with the CMS, and deploy your website to production with Vercel.
By the end of this workshop, you will have a solid understanding of how Next.js and Sanity.io can be used together to create a high-performance, scalable, and flexible website.
Crash course into Astro and Storyblok
React Day Berlin 2023React Day Berlin 2023
119 min
Crash course into Astro and Storyblok
WorkshopFree
Arisa Fukuzaki
Arisa Fukuzaki
Headless architecture has gained immense popularity in recent years for its ability to decouple the frontend and backend, empowering developers to create engaging, interactive, and scalable web applications. 
In this workshop, we will quickly take a dive into the Headless World and Architecture. 
Additionally, we will build a blog website super quickly using Storyblok, a headless CMS that offers a real-time preview feature with nestable component approach, and Astro (3.0) which is already creating a buzz with the new app directory. 
- Master headless CMS fundamentals- Master an Astro & headless CMS approach- Use Atomic design in your Astro & Storyblok application- Creating pages, adding content and understanding how the dynamic routing works with headless
Crash Course into Remix & Storyblok
Remix Conf Europe 2022Remix Conf Europe 2022
162 min
Crash Course into Remix & Storyblok
WorkshopFree
Facundo Giuliani
Arisa Fukuzaki
2 authors
You may read already about Remix. You probably already used it, and recently you may hear a lot about the headless CMSs. In this quick course, we will put all the pieces together, and I will show you why Storyblok in combination with Remix is the best combo for your next project. Stop by and try it yourself!
Table of content: - Introduction to Remix, atomic design & the headless world- Environment setup- Creating pages and understanding how the dynamic routing splat routes works- Future tips and Q&A
Prerequisite(s): Node.js installed, GitHub account.
Localizing Your Remix Website
React Summit 2023React Summit 2023
154 min
Localizing Your Remix Website
WorkshopFree
Harshil Agrawal
Harshil Agrawal
Localized content helps you connect with your audience in their preferred language. It not only helps you grow your business but helps your audience understand your offerings better. In this workshop, you will get an introduction to localization and will learn how to implement localization to your Contentful-powered Remix website.
Table of contents:- Introduction to Localization- Introduction to Contentful- Localization in Contentful- Introduction to Remix- Setting up a new Remix project- Rendering content on the website- Implementing Localization in Remix Website- Recap- Next Steps
Deploying a decoupled restaurant review site to production with Strapi and Platform.sh
Node Congress 2022Node Congress 2022
134 min
Deploying a decoupled restaurant review site to production with Strapi and Platform.sh
WorkshopFree
Shedrack Akintayo
Chad Carlson
2 authors
Node.js has become an increasingly popular language to build and deploy backend APIs. In a world of legacy CMSs adopting decoupled implementations, plenty of frameworks have sprung up to classify themselves as "headless" CMSs, designed from the start to provide an easy way to personalize content models, administer permissions and authentication, and serve a content API quickly.
Strapi, one of the leaders in this space, has recently released their v4 version of the framework, and with Platform.sh it can be deployed alongside a number of frontends within the same project, giving a drastically simplified development experience working with decoupled sites. In this workshop, we'll deploy a Strapi demo application, which has been configured to serve a restaurant review site.
Piece piece you will add database services, tests, and frontends, all within the safety of isolated development environments. At the end, each user will have a functioning decoupled site, and some greater understanding of working with decoupled sites in production.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Opt in Design – The New Era of React Frameworks
React Advanced 2023React Advanced 2023
23 min
Opt in Design – The New Era of React Frameworks
Watch video: Opt in Design – The New Era of React Frameworks
This Talk discusses opt-in design in web development, focusing on API design and understanding good defaults. Opt-in design allows developers to start with minimal tools and gradually add complexity as needed. The principles of opt-in design include finding the lowest common denominator, making complexity easy to add, and prioritizing the user experience. The Talk also explores the concept of opt-in design in React and Astro, as well as the comparison between React and Solid frameworks. Server rendering and streaming in React are highlighted, along with the importance of suspense boundaries for a better user experience.
You Don’t Know How to SSR
DevOps.js Conf 2024DevOps.js Conf 2024
23 min
You Don’t Know How to SSR
The Talk covers the speaker's personal journey into server-side rendering (SSR) and the evolution of web development frameworks. It explores the use of jQuery for animations in SSR, the challenges faced in integrating React with Umbraco, and the creation of a custom SSR framework. The Talk also discusses the benefits of Next.js and the use of serverless artifacts for deployment. Finally, it highlights the features of Astro, including its function per route capability.
All Things Astro
React Day Berlin 2023React Day Berlin 2023
28 min
All Things Astro
Watch video: All Things Astro
Astro is a powerful framework for content-driven websites, with its own syntax and the ability to use favorite front-end libraries. It has seen significant improvements in Astro 2 and Astro 3, including view transitions and improved performance. Astro 4 introduces features like a powerful dev toolbar, content caching, and internationalization support. The Astro community is highly regarded, and Astro is being used for production websites. Astro also supports migrating legacy websites and integrating with headless CMSs.
How to properly handle URL slug changes in Next.js
TypeScript Congress 2022TypeScript Congress 2022
10 min
How to properly handle URL slug changes in Next.js
Top Content
This Talk explains how to handle URL slug changes in Next.js by using the getStaticPaths and getStaticProps methods. It covers implementing redirects and provides a solution to eliminate the need for editors to perform additional steps. The approach involves tracking URL slug changes and issuing proper redirects. The speaker encourages the audience to reach out with any questions or experiences with handling URL slugs.
Remixing WordPress: Building a Headless Site with Remix, WPGraphQL, and Web Fundamentals
React Summit 2022React Summit 2022
21 min
Remixing WordPress: Building a Headless Site with Remix, WPGraphQL, and Web Fundamentals
In this Talk, the concept of headless WordPress and its benefits for developers are discussed. The use of front-end frameworks like Remix, Nuxt, Next, or SvelteKit to interact with WordPress through REST or GraphQL APIs is highlighted. The process of creating content models, adding data, and querying the GraphQL schema is explained. The setup of a basic Remix app with Apollo Client and the loading of data into route components using Remix are covered. The handling of dynamic routing with Remix and WordPress is also explored.
Large scale projects challenges (NextJS - Contentful)
React Summit 2022React Summit 2022
20 min
Large scale projects challenges (NextJS - Contentful)
This Talk discusses the challenges faced when implementing or migrating a legacy stack to Next.js and Contentful in large-scale projects. It emphasizes the need for careful analysis and estimation of time and resources. The Talk also highlights the benefits of Next.js in facilitating collaboration with isolated teams and integrating with other frameworks. It addresses the challenges of using a headless CMS in large-scale projects and suggests strategies for handling unavailability and crashes. The importance of using global state wisely and promoting code reusability is also emphasized, along with techniques for overcoming challenges in large-scale projects.