<?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: Matteo</title>
    <description>The latest articles on DEV Community by Matteo (@matfire).</description>
    <link>https://dev.to/matfire</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F39802%2F6b79d91e-812b-48ec-9abc-6176d66eaa25.png</url>
      <title>DEV Community: Matteo</title>
      <link>https://dev.to/matfire</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matfire"/>
    <language>en</language>
    <item>
      <title>T3Chat Cloneathon Postmortem</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Wed, 04 Nov 2026 17:59:55 +0000</pubDate>
      <link>https://dev.to/matfire/t3chat-cloneathon-postmortem-58ih</link>
      <guid>https://dev.to/matfire/t3chat-cloneathon-postmortem-58ih</guid>
      <description>&lt;h2&gt;
  
  
  T3-Chat Hackathon
&lt;/h2&gt;

&lt;p&gt;I decided to participate in the T3Chat cloneathon for two main reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I was bored and looking for something to do&lt;/li&gt;
&lt;li&gt;Money is always nice
Although I didn't end up winning this experience still taught me a lot - both in software architecture and on Nuxt - and so I would like to share all of this in this article; enjoy!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find all the code for my submission &lt;a href="https://github.com/matfire/m3-chat" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Stack
&lt;/h2&gt;

&lt;p&gt;Because I wanted to challenge myself - and because I wanted an excuse to learn more about this framework - I decided to built the whole thing using Nuxt. This would allow me to not only learn by reading the docs but also learn by building something with the framework - which is what I usually prefer.&lt;/p&gt;

&lt;p&gt;There are some other elements to this project that made it all possible:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://better-auth.com" rel="noopener noreferrer"&gt;Better Auth&lt;/a&gt;: to handle authentication&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://orm.drizzle.team/" rel="noopener noreferrer"&gt;Drizzle&lt;/a&gt;: the ORM I used&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://turso.tech/" rel="noopener noreferrer"&gt;Turso&lt;/a&gt;: the db provider I chose&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://zod.dev/" rel="noopener noreferrer"&gt;Zod&lt;/a&gt;: for validation&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://pusher.com/" rel="noopener noreferrer"&gt;Pusher&lt;/a&gt;: for realtime notifications&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://sockudo.app/" rel="noopener noreferrer"&gt;Sockudo&lt;/a&gt;: the webserver I used locally
If I had to justify them, here's what I would say. When learning something new, I usually try to only have to learn that thing - meaning I will try and use (where possible, obviously) tools I already know so that I don't have to split my attention too many ways. Amongst the tools I mentioned above, the only one I hadn't used in a "production" project yet were better-auth and sockudo; both of them were a breeze to setup and use, so no complaints there.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architecting the solution
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The different sections
&lt;/h3&gt;

&lt;p&gt;Let's take a look at the objectives I had when building my submission:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple providers and models (required)&lt;/li&gt;
&lt;li&gt;authentication and chat sync (required)&lt;/li&gt;
&lt;li&gt;syntax highlighting (nice to have)&lt;/li&gt;
&lt;li&gt;resumable stream (nice to have)&lt;/li&gt;
&lt;li&gt;bring your own key (nice to have)
Based on all of these requirements, here's what I came up with architecture-wise.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl8041sagejwajm9x3cma.webp" alt="architecture schema of m3chat with data flows in each direction" width="800" height="558"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's break this down; we have the two obvious sections that you would expect in this kind of scenario: the app and the database. But there was one issue that I couldn't (or wouldn't) solve with just these two elements; realtime and resumable streams. To achieve this I needed a way to decouple the data received by the client from the http request and response they would receive when hitting that endpoint - there needed to be a third service that would handle receiving data and transmitting it to the right user (or channel).&lt;/p&gt;

&lt;p&gt;This ended up being a pusher-compatible service called sockudo in development and Pusher Channels in production.&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens when a message is generated
&lt;/h3&gt;

&lt;p&gt;When a message is generated a few things happen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the message sent by the user is stored in the database&lt;/li&gt;
&lt;li&gt;we fire off the request to the select provider with all the data&lt;/li&gt;
&lt;li&gt;we return the status to the user immediately&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But I hear you asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;but how can you return immediately if the provider is not done generating the response?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is thanks to Nuxt's &lt;code&gt;waitUntil&lt;/code&gt; method that allows us to return earlier but continue executing in the background. This means the client can continue doing its thing (i.e. redirect to the chat page) while still doing it needs to do. This allows, in turn, to allow for resubscribing to the realtime events for a chat thread after navigation or a page reload.&lt;/p&gt;

&lt;h3&gt;
  
  
  Converting the markdown
&lt;/h3&gt;

&lt;p&gt;Honestly, this section should have been easy. As you might have already read on this blog, I really like the &lt;a href="https://unifiedjs.com/" rel="noopener noreferrer"&gt;unified&lt;/a&gt; ecosystem, so I though I'd just bring in my setup and call it a day. Unfortunately, there were some performance issues (probably due to the rate of change of the text) that caused me to spend way too long on this than initially planned. I even tried moving the whole rendering logic to a web worker but couldn't manage to make it work in a timely manner. Fortunately that was a problem &lt;em&gt;only&lt;/em&gt; when rendering new text, as when the new responses were done generating they were rendered to html and stored in the database - otherwise the app would have frozen for a lot longer than it ended up doing (silver lining, I guess?)&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do differently
&lt;/h2&gt;

&lt;p&gt;Honestly, I had a lot of fun doing this cloneathon! It forced me to solve problems I don't normally worry about in my day job - or my side projects for that matter - and to start learning new things. And because hindsight is always 20/20, I thought it might be interesting to recap some of the "lessons" I learnt while working on M3Chat&lt;/p&gt;

&lt;h3&gt;
  
  
  Too Much Too Young Too Fast
&lt;/h3&gt;

&lt;p&gt;While I'm happy with the solution I came up with for having multiple providers and models, it was way too overkill and I spent way too much time on it. While this point might not stick if I were making a product I'd take to market, the solution I came up with was way too complex and caused some issues with type safety when crossing from client to server and from server to client. I could have definitely used the time to work on something else&lt;/p&gt;

&lt;h3&gt;
  
  
  The Writing on The Wall
&lt;/h3&gt;

&lt;p&gt;The markdown rendering section is one of the things I'm less proud of in this project. While the markdown renders correctly - most of the time - it takes way too long on the client and causes the app to freeze during the parser initialization. I can see two ways in which I could have avoided this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;moving the parser to a separate process - a separate web worker&lt;/li&gt;
&lt;li&gt;initializing the parser on app load, where the freezing might not have been as apparent
If I had to do it again, I would definitely choose the first option&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Separate Ways (Worlds Apart)
&lt;/h3&gt;

&lt;p&gt;This point probably also stems from the time limit and - though I'm not using that as an excuse - I do hope I could have done this differently. When writing the code for generating the llm response I decided to put most of it - including broadcasting the data back to the user - inside the api handler. This is a &lt;strong&gt;bad&lt;/strong&gt; design decision that I regret to this day, because it made it way harder than it should have been to change this logic. If I had to redo this in Nuxt, I'd probably use their event system to isolate all these different behaviors (you can read more about it &lt;a href="https://nuxt.com/docs/guide/going-further/events" rel="noopener noreferrer"&gt;here&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>markdown</category>
      <category>vue</category>
      <category>nuxt</category>
    </item>
    <item>
      <title>React for Beginners: Build a To-Do List</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Wed, 04 Nov 2026 17:59:30 +0000</pubDate>
      <link>https://dev.to/matfire/react-for-beginners-build-a-to-do-list-112k</link>
      <guid>https://dev.to/matfire/react-for-beginners-build-a-to-do-list-112k</guid>
      <description>&lt;p&gt;So...&lt;br&gt;
You heard of this framework called React and want to know what all the fuss is about ? Well, wander no more ! Let's go for a spin with ReactJS and build a simple application that will let us see why everyone is talking about it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing React
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before installing React, make sure you have a correct development environment. I'm not talking about your IDE (Integrated Development Environment) - though I personally prefer Visual Studio Code, but whether or not you have NodeJS installed on your machine. If you do, that's great 👍! If you don't, I'd suggest using &lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;nvm&lt;/a&gt; to install the latest LTS (long term support) version; you shouldn't need anything else for this guide.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating a Project
&lt;/h2&gt;

&lt;p&gt;Now that we have a &lt;strong&gt;recent&lt;/strong&gt; version on NodeJS, and consequently npm, we can start bootstrapping our new React project. After you get to know better the framework you can have your own starter template, but for today's guide let's just use &lt;code&gt;create-react-app&lt;/code&gt;. To start a new react project, just open up a terminal and type: &lt;code&gt;npx create-react-app &amp;lt;folderName&amp;gt;&lt;/code&gt; where &lt;code&gt;&amp;lt;folderName&amp;gt;&lt;/code&gt; is the name of the folder that will be created with your react project in it.&lt;br&gt;
&lt;strong&gt;Here's a trick I found recently&lt;/strong&gt; : If you insert &lt;code&gt;.&lt;/code&gt; instead of a folder name (&lt;code&gt;.&lt;/code&gt; is the current directory), then the project will be instantiated in the current directory, without creating an addition subfolder.&lt;/p&gt;

&lt;p&gt;Once that is done, you can move to that folder and run &lt;code&gt;npm start&lt;/code&gt; to launch the development server. It should open a browser window to localhost:3000 and you should see the starter page.&lt;/p&gt;

&lt;p&gt;Congrats ! You have created your first React project&lt;/p&gt;
&lt;h2&gt;
  
  
  Folder Structure
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5ynkby47vnkwin4oc8h3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5ynkby47vnkwin4oc8h3.png" alt="FolderStructure.PNG" width="656" height="961"&gt;&lt;/a&gt;&lt;br&gt;
This is the usual folder structure generated by create-react-app&lt;/p&gt;

&lt;p&gt;Let's now take a look at some particular files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;src/App.js : this is the root component all your application will be rendered inside of. If you look at the code inside it, you will see that it's what you've seen when you launched your application&lt;/li&gt;
&lt;li&gt;src/index.js : this is the file that actually renders the &lt;code&gt;App&lt;/code&gt; component onto the page by attaching it to a &lt;code&gt;div&lt;/code&gt; with an id of "root".&lt;/li&gt;
&lt;li&gt;public/index.html : the scheleton of the page your React component will live in: in here you can see the &lt;code&gt;div&lt;/code&gt; I mentioned above&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  To Do
&lt;/h3&gt;

&lt;p&gt;Now that we have had a look at how a React project is structured, we can start creating our To Do app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NB: for the sake of brevity, we will have everything happen inside one component. Perhaps in a following article we will advance this project to make it resemble more a real life use case&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Task list
&lt;/h4&gt;

&lt;p&gt;The first step is to create a list of tasks. This list will be updated every time a new items gets added or an item is removed. It will composed of a simple unordered list, with each list item corresponding to a task.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating a component
&lt;/h2&gt;

&lt;p&gt;For this guide, we will be using functional components and the latest addition to the React arsenal, hooks. To create a functional component you must first import React at the top of the file and create a function that returns some &lt;code&gt;JSX&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is JSX ?
&lt;/h3&gt;

&lt;p&gt;From React's official documentation&lt;/p&gt;

&lt;p&gt;Consider this variable declaration:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;world&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This funny tag syntax is neither a string nor HTML.&lt;/p&gt;

&lt;p&gt;It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI should look like. JSX may remind you of a template language, but it comes with the full power of JavaScript.&lt;/p&gt;

&lt;p&gt;You can learn more &lt;a href="https://reactjs.org/docs/introducing-jsx.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's get back to the 'task' 🤣 at hand
&lt;/h3&gt;

&lt;p&gt;Let's remove all the code inside the return of the &lt;code&gt;App&lt;/code&gt; component. It should now look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqhinaps84fexu96hof1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqhinaps84fexu96hof1p.png" alt="empty app component" width="800" height="774"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;let's begin by adding a &lt;code&gt;div&lt;/code&gt; as the root of our component: &lt;strong&gt;All React element must have only one root element&lt;/strong&gt; and inside of it let's add our unordered list&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8kogg53m49qrhu3quh8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8kogg53m49qrhu3quh8p.png" alt="app with div and ul tag" width="800" height="921"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Let's display some taks
&lt;/h4&gt;

&lt;p&gt;Now that we have a list element, we need to add elements inside of it. We could add them one by one, but that is not the point of using React. Let's instead declare an array with some data in it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flsutimpma8o7jqp2wupk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flsutimpma8o7jqp2wupk.png" alt="ul with data no state" width="800" height="867"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have some data, all that is left is to display them to the user. Let me introduce you to one of your Javascript bestfriends: &lt;strong&gt;the map function&lt;/strong&gt;. It allows us to iterate over an array and return a value for each element (keeping it brief, of course). So, can you guess what we're going to use it for ?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3lcq24yhfrd95p44j0r5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3lcq24yhfrd95p44j0r5.gif" alt="right you are" width="360" height="360"&gt;&lt;/a&gt; We'll use &lt;code&gt;map&lt;/code&gt; to display our list items !&lt;/p&gt;

&lt;p&gt;so why don't we do just that ?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7pekixdcmbuiz7jy6zjy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7pekixdcmbuiz7jy6zjy.png" alt="app with items no state" width="800" height="795"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If everything went well, then you should see 2 elements appear on your page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpc4ths8cllc4i665owdj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpc4ths8cllc4i665owdj.gif" alt="congrats" width="320" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Adding a task
&lt;/h4&gt;

&lt;p&gt;In order to add a task, we need to introduce a &lt;code&gt;Form&lt;/code&gt; tag. Within the form we'll have an &lt;code&gt;input&lt;/code&gt; and a &lt;code&gt;button&lt;/code&gt;. Clicking the button will submit the form.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj5etbntmxvqv7yr2b6it.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj5etbntmxvqv7yr2b6it.png" alt="adding form input" width="800" height="786"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you try typing in something and then submitting the form you'll notice something strange... The page reloads! This is because the &lt;code&gt;form&lt;/code&gt; is acting like a form, in that it sends a post request while reloading the page. But we don't want that, do we?&lt;/p&gt;

&lt;p&gt;What we need to do is provide a substitute function that will run when the form gets submitted. We can do this with the &lt;code&gt;onSubmit&lt;/code&gt; prop (think of props as passing values to another component from their parent).&lt;/p&gt;

&lt;p&gt;The first thing we want to do is prevent the form from actually submitting (i.e. reloading the page). For that, we need to prevent the default behaviour associated with the event originating from the form. If this last sentence seems a bit complicated, it's not; we're simply doing this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frwde3x2u8d4t51ethoc9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frwde3x2u8d4t51ethoc9.png" alt="onSubmit preventDefault" width="800" height="871"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you try this out, you'll see that the form doesn't reload the page!&lt;/p&gt;

&lt;h5&gt;
  
  
  Getting the task's name
&lt;/h5&gt;

&lt;p&gt;Now we need to get the input's value in order to add it to the list. And it's in this section that you'll get to meet the &lt;strong&gt;one&lt;/strong&gt; thing that I love about React: state!&lt;/p&gt;

&lt;h5&gt;
  
  
  React State
&lt;/h5&gt;

&lt;p&gt;React state is a collection of variables that you define on a component basis, that forces the component showing them to the screen to re-render itself. It means that for example we can dynamically add rows to a table and it will update automatically (without us needing to manipulate the dom direclty). In order to do so, we'll also get to know a "new" concept in React, called hooks (more info &lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;). In this paricular guide, we'll only use the &lt;code&gt;useState&lt;/code&gt; hook, which allows us to define a variable and a function to update said variable. The syntax is as follows:&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nf"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// updates the variable value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can also pass as an argument to &lt;code&gt;useState&lt;/code&gt; the default value of the variable&lt;/p&gt;

&lt;p&gt;In our case, we need to keep track of the input's value, and then add it to our table. For the task's id, I'll increment the length of task array by 1.&lt;/p&gt;

&lt;p&gt;Our component should look like this, now:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjvuxpuubr0d2g27mk7bm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjvuxpuubr0d2g27mk7bm.png" alt="App with onChange input" width="800" height="786"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All that is left is add the &lt;code&gt;taskValue&lt;/code&gt; variable to our tasks array when the form is submitted:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fel7jtgpaabx9p0fj34eu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fel7jtgpaabx9p0fj34eu.png" alt="image.png" width="800" height="786"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you try and run this code, you'll notice that it doesn't really update the table the user sees. Can you guess why ? (hint: the table doesn't really &lt;em&gt;react&lt;/em&gt; to changes)&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Thanks for reading this article! If you have any questions, feel free to ask them in the comments below.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>introduction</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Appwrite Hackaton: MoviePlay</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Wed, 04 Nov 2026 17:58:57 +0000</pubDate>
      <link>https://dev.to/matfire/appwrite-hackaton-movieplay-1ok9</link>
      <guid>https://dev.to/matfire/appwrite-hackaton-movieplay-1ok9</guid>
      <description>&lt;p&gt;Well, I recently quit my job so I got free time and this hackathon between &lt;a href="https://hashnode.com" rel="noopener noreferrer"&gt;Hashnode&lt;/a&gt; and &lt;a href="https://appwrite.io" rel="noopener noreferrer"&gt;Appwrite&lt;/a&gt; is announced. This is clearly a sign. So I decided to build &lt;a href="https://appwrite.io" rel="noopener noreferrer"&gt;MoviePlay&lt;/a&gt;. Before we get into the trials and tribulations of this project, let's get all the technical stuff out of the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Idea
&lt;/h2&gt;

&lt;p&gt;Have you ever had a debate with someone as to what is the correct order to watch Star Wars? There's the chronological order, the release order, the machete order&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F22y2shjphiic8q0tczw2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F22y2shjphiic8q0tczw2.gif" alt="enough already" width="399" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Team
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Me&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ReactJS &amp;amp; Typescript (ViteJS)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TailwindCSS &amp;amp; DaisyUI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://cloud.appwrite.io" rel="noopener noreferrer"&gt;Appwrite Cloud&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database&lt;/li&gt;
&lt;li&gt;Account&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;NodeJS&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Vercel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.npmjs.com/package/@matfire/the_movie_wrapper" rel="noopener noreferrer"&gt;The-Movie-Wrapper&lt;/a&gt; (I made this one, but still...)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Look at the code
&lt;/h2&gt;

&lt;p&gt;You can see the code &lt;a href="https://github.com/matfire/movieplay" rel="noopener noreferrer"&gt;here&lt;/a&gt; and see it live &lt;a href="https://movieplay.nirah.tech" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=8GJyqRNkZrA" rel="noopener noreferrer"&gt;Watch the video&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  On the using of Appwrite
&lt;/h2&gt;

&lt;p&gt;I had already used a self-hosted version of Appwrite and have been tinkering with the closed cloud beta for a bit, so I was already familiar with the tool and will not really talk about onboarding.&lt;/p&gt;

&lt;h3&gt;
  
  
  Database
&lt;/h3&gt;

&lt;p&gt;I was a bit disappointed relationships (as of 06/04/2023) are not yet supported on Cloud, so you still need to do all the foreign key constraints by hand, which makes fetching client-side a bit of a hassle.&lt;/p&gt;

&lt;h3&gt;
  
  
  Account
&lt;/h3&gt;

&lt;p&gt;I really like how accounts are handled, especially oauth2 stuff; the fact that you can connect multiple providers for the same account seamlessly is pretty cool&lt;/p&gt;

&lt;h3&gt;
  
  
  Functions
&lt;/h3&gt;

&lt;p&gt;I needed to use functions to store the number of views a playlist could get. I would have loved a trigger on &lt;strong&gt;database read operations&lt;/strong&gt;, but I can see it would probably be too much performance overhead; the way I solved this is when navigating to a page, the page loader function triggers the function to increment the views number.&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>tailwindcss</category>
      <category>appwrite</category>
    </item>
    <item>
      <title>Better Release PRs with brel</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Wed, 04 Nov 2026 17:56:35 +0000</pubDate>
      <link>https://dev.to/matfire/better-release-prs-with-brel-2ab6</link>
      <guid>https://dev.to/matfire/better-release-prs-with-brel-2ab6</guid>
      <description>&lt;p&gt;I really like &lt;a href="https://release-plz.dev/" rel="noopener noreferrer"&gt;release-plz&lt;/a&gt; for my Rust projects (&lt;a href="https://balzac.rs" rel="noopener noreferrer"&gt;balzac&lt;/a&gt; uses it); it's easy to configure, it automatically updates the relevant version fields (in cargo.toml) and can even update the &lt;code&gt;CHANGELOG.md&lt;/code&gt; of your repo. There's only one problem: it only works with Rust. So I decided to make my own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Better Releases
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://better-releases.com" rel="noopener noreferrer"&gt;better releases&lt;/a&gt; is a tool that works on any Github repo, with any language and any stack. It uses a simple-ysh &lt;code&gt;brel.toml&lt;/code&gt; file and:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reads the commit from the previous tag (if it exists)&lt;/li&gt;
&lt;li&gt;figures out the next tag based on conventional commits&lt;/li&gt;
&lt;li&gt;opens/updates a release pr&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the pr is merged, it can optionally publish the detected tag to potentially trigger other workflows; in the &lt;a href="https://github.com/matfire/drizzle-sluggable" rel="noopener noreferrer"&gt;drizzle-sluggable&lt;/a&gt; repo, this is what I use to trigger publishing the package to npm.&lt;/p&gt;

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

&lt;p&gt;To get started, you need to install &lt;code&gt;brel&lt;/code&gt; (better-releases' main tool); if you don't want to, you can also run it with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx brel@latest init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The init command will ask some question to setup the base config and will generate the base workflow for Github Actions. Here's what the config file might look like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="n"&gt;default_branch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"main"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But we can do so much better than that.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
When modifying the config, you will need to rerun the init command to update&lt;br&gt;
the workflow file&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Bumping Package versions
&lt;/h3&gt;

&lt;p&gt;Honestly, this feature is why I decided to build this tool: I wanted to be able to update versions across toml and json files (Rust, Javascript, PHP) with a single tool. Let's see how we can do this.&lt;/p&gt;

&lt;p&gt;For a &lt;strong&gt;package.json&lt;/strong&gt; file, we might want to bump the &lt;strong&gt;version&lt;/strong&gt; field; with Brel, you can just do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[&lt;/span&gt;&lt;span class="n"&gt;release_pr&lt;/span&gt;&lt;span class="k"&gt;.&lt;/span&gt;&lt;span class="n"&gt;version_updates&lt;/span&gt;&lt;span class="k"&gt;]&lt;/span&gt;
&lt;span class="s"&gt;"package.json"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But that's not all! Imagine you want to update the version inside a lock file (though you probably shouldn't do this in CI), you can also pass selectors when selecting an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[&lt;/span&gt;&lt;span class="n"&gt;release_pr&lt;/span&gt;&lt;span class="k"&gt;.&lt;/span&gt;&lt;span class="n"&gt;version_updates&lt;/span&gt;&lt;span class="k"&gt;]&lt;/span&gt;
&lt;span class="s"&gt;"Cargo.toml"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"package.version"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="s"&gt;"Cargo.lock"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"package[name=brel].version"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might notice there's a &lt;strong&gt;.lock&lt;/strong&gt; file in there; you can override the filetype like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[&lt;/span&gt;&lt;span class="n"&gt;release_pr&lt;/span&gt;&lt;span class="k"&gt;.&lt;/span&gt;&lt;span class="n"&gt;format_overrides&lt;/span&gt;&lt;span class="k"&gt;]&lt;/span&gt;
&lt;span class="s"&gt;"Cargo.lock"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"toml"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pushing a Tag
&lt;/h3&gt;

&lt;p&gt;Let's say we want to add automatic tag creation when merging the release branch; we can do so with a few config changes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[&lt;/span&gt;&lt;span class="n"&gt;release_pr&lt;/span&gt;&lt;span class="k"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tagging&lt;/span&gt;&lt;span class="k"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="n"&gt;tag_template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"{version}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this setup, merging the branch will create a tag corresponding to the version, like &lt;strong&gt;0.7.0&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt;&lt;br&gt;
To actually enable release tagging, you need to provide a token allowed to do&lt;br&gt;
so under the secret name BREL_TAG_PUSH_TOKEN&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Generating/Updating a Changelog
&lt;/h3&gt;

&lt;p&gt;When enabled, Brel integrates with &lt;a href="https://git-cliff.org/" rel="noopener noreferrer"&gt;Git Cliff&lt;/a&gt; to automatically update a &lt;strong&gt;CHANGELOG.MD&lt;/strong&gt; file. Here's how you might configure this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[&lt;/span&gt;&lt;span class="n"&gt;release_pr&lt;/span&gt;&lt;span class="k"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changelog&lt;/span&gt;&lt;span class="k"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="n"&gt;output_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"CHANGELOG.md"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will automatically update the &lt;strong&gt;CHANGELOG.md&lt;/strong&gt; file using &lt;a href="https://git-cliff.org" rel="noopener noreferrer"&gt;Git Cliff&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  There's more
&lt;/h3&gt;

&lt;p&gt;I will not bore you with everything Brel can do (you can even customize the template used for the pr body), but if you want to give it a try here's &lt;a href="https://better-releases.com" rel="noopener noreferrer"&gt;the official website&lt;/a&gt; and the &lt;a href="https://github.com/better-releases/brel" rel="noopener noreferrer"&gt;github repo&lt;/a&gt;; do try it out if you have need of a tool like this and let me know what you think!&lt;/p&gt;

</description>
      <category>betterreleases</category>
      <category>rust</category>
      <category>devops</category>
    </item>
    <item>
      <title>Making an RSS Feed for a Nuxt Website</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Mon, 22 Sep 2025 15:11:18 +0000</pubDate>
      <link>https://dev.to/matfire/making-an-rss-feed-for-a-nuxt-website-3jab</link>
      <guid>https://dev.to/matfire/making-an-rss-feed-for-a-nuxt-website-3jab</guid>
      <description>&lt;p&gt;I recently remade my website (I know, I know) and I got a surprise when getting to reimplement an rss feed because, while &lt;a href="https://astro.build" rel="noopener noreferrer"&gt;Astro&lt;/a&gt; has a module that helps with generating an rss feed, Nuxt doesn't - at least not for V3 and consequently V4. But worry not, for making one is easy enough !&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an RSS Feed ?
&lt;/h2&gt;

&lt;p&gt;An RSS feed is an xml document that allows users to subscribe to updates on a website. It is an xml document that can be easily parsed to retrieve the latest published article, the website's author and more info (wikipedia entry &lt;a href="https://en.wikipedia.org/wiki/RSS" rel="noopener noreferrer"&gt;here&lt;/a&gt; if you want to learn more).&lt;/p&gt;

&lt;p&gt;There are a lot of applications that will allow you to subscribe to an rss feed and even get notified when one is updated.&lt;/p&gt;

&lt;p&gt;Although RSS in its xml format is the most well-known way to consume web feeds, there are other formats that are also widely supported:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;json feeds&lt;/li&gt;
&lt;li&gt;atom feeds&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article I'll only be talking about RSS - and briefly mentioning atom - but all the things I'm talking about apply to all of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  The structure of an RSS Feed
&lt;/h3&gt;

&lt;p&gt;Let's take a look at what an rss feed looks like (you can find mine &lt;a href="https://www.matteogassend.com/rss.xml" rel="noopener noreferrer"&gt;here&lt;/a&gt;) - specifically the one for my website&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;rss&lt;/span&gt; &lt;span class="na"&gt;version=&lt;/span&gt;&lt;span class="s"&gt;"2.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;channel&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Matteo's Log&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&amp;gt;&lt;/span&gt;https://www.matteogassend.com&lt;span class="nt"&gt;&amp;lt;/link&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;generator&amp;gt;&lt;/span&gt;Nuxt &lt;span class="err"&gt;&amp;amp;&lt;/span&gt; Feed&lt;span class="nt"&gt;&amp;lt;/generator&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;language&amp;gt;&lt;/span&gt;en&lt;span class="nt"&gt;&amp;lt;/language&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;atom:link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://www.matteogassend.com/rss.xml"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"self"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"application/rss+xml"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;item&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;T3Chat Cloneathon Postmortem&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;link&amp;gt;&lt;/span&gt;
      https://www.matteogassend.com/articles/t3-cloneathon-postmortem
      &lt;span class="nt"&gt;&amp;lt;/link&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;guid&lt;/span&gt; &lt;span class="na"&gt;isPermaLink=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;t3-cloneathon-postmortem&lt;span class="nt"&gt;&amp;lt;/guid&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;pubDate&amp;gt;&lt;/span&gt;Mon, 14 Jul 2025 00:00:00 GMT&lt;span class="nt"&gt;&amp;lt;/pubDate&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;description&amp;gt;&lt;/span&gt;
      I participated in the T3Chat cloneathon; here's how it went
      &lt;span class="nt"&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;content:encoded&amp;gt;&lt;/span&gt;
        ...
      &lt;span class="nt"&gt;&amp;lt;/content:encoded&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/channel&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/rss&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First we have the main tag specifying that this xml document is an rss feed and its implementation version (in this case, version 2.0).&lt;br&gt;
We then get to the &lt;strong&gt;channel&lt;/strong&gt; definition; this is the actual feed that will be consumed and inside of it we can find info such as its name, description, language and more. &lt;br&gt;
Then, for each element we want to add to our &lt;strong&gt;channel&lt;/strong&gt;, we have a &lt;strong&gt;item&lt;/strong&gt; tag. Each item contains a name, description, publication date, unique id and optionally the raw content of the item (in this case, a blog article).&lt;/p&gt;
&lt;h2&gt;
  
  
  How to build one in Nuxt
&lt;/h2&gt;

&lt;p&gt;Luckily, Nuxt routes can be either Vue components or server endpoints - you could also use tsx, but we'll skip that for now. Server - or API - endpoints are handled by Nitro and use the classic browser Request &amp;amp; Response, meaning we can simply return an xml document with the correct headers and we're good to go! Let's see how to do it in detail&lt;/p&gt;
&lt;h3&gt;
  
  
  Declaring the API route
&lt;/h3&gt;

&lt;p&gt;Let's start by declaring the Nitro route; in this instance I'll have it match the &lt;code&gt;/rss.xml&lt;/code&gt; path, meaning I will create a file here: &lt;code&gt;/server/routes/rss.xml.ts&lt;/code&gt; and fill it with the basic Nitro handlers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineEventHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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="c1"&gt;//generate the feed&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
  &lt;span class="c1"&gt;//return the actual feed data here&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The RSS Feed enter the game
&lt;/h3&gt;

&lt;p&gt;We &lt;strong&gt;could&lt;/strong&gt; write the xml document by hand, but why bother? There exist the perfect package for this: &lt;a href="https://github.com/jpmonette/feed" rel="noopener noreferrer"&gt;feed&lt;/a&gt;. It allows use to programmatically build a feed and return it in different formats. Let's see how we can integrate it with Nitro.&lt;/p&gt;

&lt;p&gt;First things first, let's install the dependency:&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;feed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And let's start creating the feed itself; we'll begin by setting all the basic info needed for the feed and leave the items for later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;feed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Feed&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Matteo's Log&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;All the articles from matteogassend.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;unique&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;link&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;your&lt;/span&gt; &lt;span class="nx"&gt;website&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;language&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;copyright&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`All rights reserved &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;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;, Matteo Gassend`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;updated&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;Date&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nuxt &amp;amp; Feed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;feedLinks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;rss&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;url of your website&amp;gt;/rss.xml`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With just this, we could generate an xml document and return it with the endpoint we made above. Let's do just that&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineEventHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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="p"&gt;...&lt;/span&gt; &lt;span class="c1"&gt;// the feed is here&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;feed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rss2&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;We only need two other things before we have a fully functional rss feed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;informing the browser of the type of data we're sending&lt;/li&gt;
&lt;li&gt;inserting the actual items in the feed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first step is simple enough, so let's get it out of the way; before returning the generated feed, let's set the &lt;code&gt;content-type&lt;/code&gt; header. This header tells the browser how to understand the content we'll send it back; you can see it used mostly when sending back json data - when making an api, for example. Here's how we can do it in Nitro:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;setResponseHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content-type&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="s2"&gt;text/xml&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells the browser we're sending back an xml document.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Items to the feed
&lt;/h3&gt;

&lt;p&gt;Now that we have our basis covered, let's get to adding actual items to the feed. In my usecase, I needed to fetch items from a Nuxt Content collection and add it to the feed. So let's do just that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;articles&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;queryCollection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;articles&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;publishDate&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="s2"&gt;DESC&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't have a collection, just pretend this is an array of objects.&lt;/p&gt;

&lt;p&gt;After that, it's as simple as looping over your data array and calling the &lt;code&gt;addItem&lt;/code&gt; method on your feed instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;article&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;feed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addItem&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="nx"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;article&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;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;date&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;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publishDate&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;link&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="nx"&gt;BASE_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/articles/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;article&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;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rawbody&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's all you need to do to generate an RSS feed in your Nuxt app! I also added an atom feed with the exact same logic - I just had to replace &lt;code&gt;rss2&lt;/code&gt; call with &lt;code&gt;atom1&lt;/code&gt; and you're done!&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding the Feed to the Website
&lt;/h2&gt;

&lt;p&gt;Once you have your server route you just need to add it to your pages and most rss readers should be able to pick it up. Let's say our rss feed lives at &lt;code&gt;/rss.xml&lt;/code&gt;: if so, we'll need to add the following &lt;code&gt;link&lt;/code&gt; tag to our page's &lt;code&gt;head&lt;/code&gt;:&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;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"alternate"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"application/rss+xml"&lt;/span&gt; &lt;span class="na"&gt;title=&lt;/span&gt;&lt;span class="s"&gt;"Your feed's title"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;`${BASE_URL}/rss.xml`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're using &lt;code&gt;unhead&lt;/code&gt;, then this can also be done in a useHead composable hook using something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;useHead&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;link&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;rel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;alternate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/rss+xml&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Matteo's Log&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/rss.xml&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;alternate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/atom+xml&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Matteo's Log&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/atom&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you're officially done!&lt;/p&gt;

</description>
      <category>nuxt</category>
      <category>javascript</category>
      <category>rss</category>
    </item>
    <item>
      <title>Developing and Compiling Webapps with Vite and Go</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Sat, 10 May 2025 00:00:00 +0000</pubDate>
      <link>https://dev.to/matfire/developing-and-compiling-webapps-with-vite-and-go-32mp</link>
      <guid>https://dev.to/matfire/developing-and-compiling-webapps-with-vite-and-go-32mp</guid>
      <description>&lt;p&gt;&lt;a href="https://www.matteogassend.com/articles/go-webapp-vite" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;this article uses custom markdown components. Expect some of them to break in places other than my blog&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;I've recently been playing around with Go (and RPC) and have stumbled upon the &lt;code&gt;embed&lt;/code&gt; package, which allows us to specify files and directory to be &lt;strong&gt;embedded&lt;/strong&gt; (hence the name) into the final binary. You would usually use this to embed something like the db schema / migrations, but there's also a world where this can be used for a vite bundle so that we can embed a SPA (single page app) into the final executable; neat right ?&lt;/p&gt;

&lt;h2&gt;
  
  
  Bundling the assets
&lt;/h2&gt;

&lt;p&gt;Let's consider that we already have a Vite application and that we have already run an &lt;code&gt;npm run build&lt;/code&gt; to generate its bundle and so we have a &lt;code&gt;dist&lt;/code&gt; folder where all our front assets are.&lt;/p&gt;

&lt;p&gt;If we have a standard http mux, we could simply add a &lt;code&gt;Handle&lt;/code&gt; function. Let's see what that would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// this file could be called front_prod.go&lt;/span&gt;

&lt;span class="c"&gt;//go:embed dist/*&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;embedFS&lt;/span&gt; &lt;span class="n"&gt;embed&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FS&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Front&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mux&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ServeMux&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;staticFiles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;embedFS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"dist"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fileServer&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FileServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;staticFiles&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;mux&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fileServer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Serving static files from embedded filesystem"&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;Let's break this down: most of the magic happens on these lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;//go:embed dist/*&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;embedFS&lt;/span&gt; &lt;span class="n"&gt;embed&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These lines tell go to get the &lt;code&gt;dist&lt;/code&gt; folder and all its subfolders (and files) into a structure that matches the standard library's &lt;code&gt;FS&lt;/code&gt; interface and stores it in a variable called &lt;code&gt;embedFS&lt;/code&gt;. Inside the &lt;code&gt;Front&lt;/code&gt;  function we simply target the &lt;code&gt;dist&lt;/code&gt; folder (with a bit of error handling ) and we add the &lt;code&gt;FileServer&lt;/code&gt; as a route to our mux.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Frflosxtrwjlblow7w35f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Frflosxtrwjlblow7w35f.gif" alt="gif" width="450" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Caveats
&lt;/h3&gt;

&lt;p&gt;This is a simple and pretty "dumb" implementation of the "production assets"; if using something like React, you might need to write some logic to redirect the requests to the &lt;code&gt;index.html&lt;/code&gt; file if no matching asset is found.&lt;/p&gt;

&lt;h2&gt;
  
  
  What about during development ?
&lt;/h2&gt;

&lt;p&gt;Well, I think having to build a Vite app every time you make a change during development is not the best DX, right ? What if I told you there was a way that you could have all the power of the Vite dev server (i.e. hot reload) from within your go app ?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fcg0ew8i8wya8tjly5ca9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fcg0ew8i8wya8tjly5ca9.gif" alt="gif" width="400" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing the Vite Proxy
&lt;/h3&gt;

&lt;p&gt;This is the (mostly) the whole code we'll need to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// this file could be called front_dev.go&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;createViteProxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Handler&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;proxy&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;httputil&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewSingleHostReverseProxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HandlerFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c"&gt;// Update the request to point to the Vite server&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Host&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;URL&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Scheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Scheme&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;URL&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Host&lt;/span&gt;
        &lt;span class="n"&gt;proxy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ServeHTTP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&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;func&lt;/span&gt; &lt;span class="n"&gt;Front&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mux&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ServeMux&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;viteProxy&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;createViteProxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"http://localhost:5173"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;mux&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;viteProxy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"proxying requests to vite dev server"&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;Let's break it down!&lt;/p&gt;

&lt;p&gt;We have the same function signature for the &lt;code&gt;Front&lt;/code&gt; function&lt;br&gt;
:::callout&lt;br&gt;
Remember this, it will be important later on&lt;br&gt;
:::&lt;br&gt;
The magic happens with the &lt;code&gt;createViteProxy&lt;/code&gt; function, where we return a new &lt;code&gt;http.HandlerFunc&lt;/code&gt; that sends the request through a &lt;code&gt;SingleHostReverseProxy&lt;/code&gt; that points to the Vite dev server. This means that all requests the &lt;code&gt;Front&lt;/code&gt; function handles will be sent to the Vite server; this allows all the hot reload goodness that Vite provides to work out of the box.&lt;/p&gt;
&lt;h2&gt;
  
  
  How Do You Switch Between the Two ?
&lt;/h2&gt;

&lt;p&gt;Here's the fun part: you let the compiler do it!&lt;br&gt;
&lt;a href="https://media2.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%2Fgkdv4h0ymy7gowyfwr0f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgkdv4h0ymy7gowyfwr0f.gif" alt="gif" width="300" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On its latest versions, Go supports a feature called &lt;strong&gt;build constraints&lt;/strong&gt;. These are values that you can pass your &lt;code&gt;go build&lt;/code&gt; command and that can influence which files the compiler will include.&lt;br&gt;
When I shared the whole code file, I might have lied; there are actually three more lines you might need to have at the top of the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;//go:build dev&lt;/span&gt;
&lt;span class="c"&gt;//+build dev&lt;/span&gt;

&lt;span class="c"&gt;// the rest of the code goes here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two comments above are the two syntaxes for &lt;strong&gt;build constraints&lt;/strong&gt;. These tell the compiler to only include this file if this constraint is passed to the &lt;code&gt;build&lt;/code&gt; function: here's how you would run this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go build &lt;span class="nt"&gt;-tags&lt;/span&gt; dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you add the reverse condition on the "production" logic, you're done!&lt;br&gt;
:::callout&lt;br&gt;
you can just add a ! before the constraint you're checking&lt;br&gt;
:::&lt;/p&gt;

&lt;p&gt;This is why I said it would be important to name the &lt;code&gt;Front&lt;/code&gt; function the same in both files; if both files are in the same package, the rest of the program is completely oblivious to this switcharoo happening in dev or prod!&lt;/p&gt;

&lt;h2&gt;
  
  
  Should you do this ?
&lt;/h2&gt;

&lt;p&gt;While this might almost look like magic, there are cases in which this might not be the ideal choice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you need more complex routing that just redirecting to &lt;code&gt;index.html&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While I have addressed this a bit in the related section, I just want to point this out again.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;separation of concerns and scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This setup will obviously not work if you want to deploy your frontend code to a dedicated service (Vercel, Netflify etc), this will obviously not work. &lt;/p&gt;

&lt;p&gt;Still, there are some cases where you might want this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;offline-first&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Weirdly, this could work really well with an offline-first approach; download the binary, run it on your system and just browse to localhost:3000 (or any other port) and you have your whole application running, no internet required (except if you're connecting to external services, obviously)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;simple deploy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's a binary.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;great DX&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this setup, you have a backend and frontend living on the same port (and/or domain), meaning you don't need to worry about CORS, proxy rules and whatever else causes mental breakdowns to developers nowadays.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fq749ougiahwfm65xotb7.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fq749ougiahwfm65xotb7.gif" alt="gif" width="500" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Custom markdown components with remark and web components</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Fri, 21 Feb 2025 00:00:00 +0000</pubDate>
      <link>https://dev.to/matfire/custom-markdown-components-with-remark-and-web-components-43ho</link>
      <guid>https://dev.to/matfire/custom-markdown-components-with-remark-and-web-components-43ho</guid>
      <description>&lt;p&gt;&lt;a href="https://www.matteogassend.com/articles/remark-directives-web-components" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;this article uses custom markdown components. Expect some of them to break in places other than my blog&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;Recently, I ported my portfolio (again) to Astro from Hugo. While I really liked Hugo, I missed the choice JS gave me (plus, I was bored) so here we go!&lt;br&gt;
&lt;a href="https://media2.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%2F6go26ddknmxj3y6wu8qu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F6go26ddknmxj3y6wu8qu.gif" alt="gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Porting Data
&lt;/h2&gt;

&lt;p&gt;Everything is markdown in Hugo (mostly), so transitioning to and from was pretty simple; just import the data, build the collections and we're off to the races! The one thing I had to deal with was importing the cover images for the opengraph images, but that wasn't hard and went on without many issues.&lt;/p&gt;
&lt;h2&gt;
  
  
  Where are my shortcodes ?
&lt;/h2&gt;

&lt;p&gt;One thing that I really like about Hugo is how it handles shortcodes. This is how I could generate a stackblitz embed using Hugo: &lt;code&gt;{{&amp;lt;stackblitz url goes here&amp;gt;}}&lt;/code&gt; That line right there would then be mapped to a component called &lt;code&gt;stackblitz&lt;/code&gt; where I could describe the html element and I was done! But unfortunately, Astro does not handle shortcodes (or similar) natively, so I had to get creative.&lt;/p&gt;

&lt;p&gt;Astro uses &lt;a href="https://github.com/remarkjs/remark" rel="noopener noreferrer"&gt;remark&lt;/a&gt; and &lt;a href="https://github.com/rehypejs/rehype" rel="noopener noreferrer"&gt;rehype&lt;/a&gt; to transform your markdown collections into html.&lt;/p&gt;

&lt;p&gt;:::callout{type="info"}&lt;br&gt;
I've already written about the unified ecosystem, you can checkout that article &lt;a href="https://dev.to/blog/markdown-editor"&gt;here&lt;/a&gt;&lt;br&gt;
:::&lt;/p&gt;

&lt;p&gt;That means that we can hopefully build something within this pipeline and recreate the feeling of shortcodes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Enter Remark Directive
&lt;/h2&gt;

&lt;p&gt;Turns out we (kind of) can! There's a remark plugin called &lt;a href="https://github.com/remarkjs/remark-directive" rel="noopener noreferrer"&gt;remark-directive&lt;/a&gt; that enables remark to parse directives (basically shortcodes, but maybe more powerful). With this plugin, we can then write a custom function that looks for these directives and "does something with them".&lt;/p&gt;
&lt;h3&gt;
  
  
  What do we do with a remark directive ?
&lt;/h3&gt;

&lt;p&gt;Let's take a small look at the source of one of my articles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;Astro uses &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;remark&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://github.com/remarkjs/remark&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; and &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;rehype&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://github.com/rehypejs/rehype&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; to transform your markdown collections into html.

:::callout(type="info")
I've already written about the unified ecosystem, you can checkout that article &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;here&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;/blog/markdown-editor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
:::
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The thing with the 3 &lt;code&gt;:&lt;/code&gt; is a remark directive. When I traverse the tree of the article (an abstract syntax tree describing the repo), I can check whether the node I'm looking at is a directive. If I find one, I can then check the type of directive (there are 3) and finally get its attributes.&lt;/p&gt;

&lt;p&gt;For example, the following snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;::stackblitz{#mg-fbr-express}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Contains a node that is a &lt;code&gt;leafDirective&lt;/code&gt; with an id of &lt;code&gt;mg-fbr-express&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;:::callout{type="info"}&lt;br&gt;
the attributes section of the directive supports multiple elements separated by a whitespace like this: &lt;code&gt;::codesandbox{projectType="devbox" projectid="cwmtww"}&lt;/code&gt;&lt;br&gt;
:::&lt;/p&gt;

&lt;p&gt;Getting the node's attributes is pretty straightforward from there: they're in&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="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attributes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now we have everything we need to create our custom elements!&lt;br&gt;
&lt;a href="https://media2.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%2Fke8j8jlexp0d3ic7ij8j.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fke8j8jlexp0d3ic7ij8j.gif" alt="gif" width="480" height="400"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Web Components
&lt;/h2&gt;

&lt;p&gt;Web Components are not new (they have been baseline available since 2021) but I don't think I've ever seen them much out in the wild. They have lots of advantages and will work pretty well in this use case, but they also come with some drawbacks.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Good
&lt;/h3&gt;

&lt;p&gt;Web components, as stated above, are pretty easy to get up and running and put in a page. Here's the code for my youtube embed web component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Youtube&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;connectedCallback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;render&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;iframe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;iframe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;iframe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://www.youtube.com/embed/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;videoid&lt;/span&gt;&lt;span class="dl"&gt;'&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;div style="width: 100%; min-height: 500px;"&amp;gt;&amp;lt;iframe class="w-full min-h-[500px]" src="https://www.youtube.com/embed/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;videoId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen&amp;gt;&amp;lt;/iframe&amp;gt;&amp;lt;/div&amp;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;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wc-youtube&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Youtube&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This little snippet does all the heavy lifting to generate an iframe tag with the provided videoid and all the necessary styles and (potentially) logic.&lt;/p&gt;

&lt;p&gt;Notice the last line; that's where we tell the browser that there's a new valid tag (called &lt;code&gt;wc-youtube&lt;/code&gt;) that is represented by the &lt;code&gt;Youtube&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fnio4uumgv1p8xi3zoycp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fnio4uumgv1p8xi3zoycp.gif" alt="gif" width="364" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Bad
&lt;/h3&gt;

&lt;p&gt;Well, if web components are so nice, why is everyone bothering with frontend frameworks ?&lt;/p&gt;

&lt;p&gt;Well, because it’s not all roses. There are some design principles that you need to take into account if you want to use web components. If I had to choose one thing that "grinds my gears" about web components is that they are encapsulated; while this has some benefits in my use case this caused quite some headaches.&lt;/p&gt;

&lt;p&gt;I tried for quite some time to have TailwindCSS (which I'm using to style this whole website) pick up and generate the styling required by the web components. Because of this encapsulation (called the shadow DOM, by the way) this proved pretty hard - I probably would have needed to spend too much time looking into it (maybe next time?).&lt;/p&gt;

&lt;h2&gt;
  
  
  The Compromise
&lt;/h2&gt;

&lt;p&gt;So, what did I do ? I simply rewrote the styles in plain css. I didn't need that much styling to begin with, so why bother ?&lt;/p&gt;

&lt;h2&gt;
  
  
  Should you do this?
&lt;/h2&gt;

&lt;p&gt;Honestly I don't know; this "stack" fit my use case pretty well and is, by definition, portable (I could use these web components on basically any website). Could I have found another solution? Probably. Was this fun? Kind of. Was this interesting? Definitely.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>markdown</category>
    </item>
    <item>
      <title>How to rebuilt a personal website</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Sun, 15 Dec 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/matfire/how-to-rebuilt-a-personal-website-238k</link>
      <guid>https://dev.to/matfire/how-to-rebuilt-a-personal-website-238k</guid>
      <description>&lt;p&gt;The first website I ever had was built on wordpress; it was a way for my friends and me to write small articles in things we liked at the time (like the Lavender Town Syndrome - yes, it was a long time ago) and share it with one another. Since then, said website has changed and evolved. Through it all it at some point became my professional portfolio and, as such, changed what was required of it. It became a place to showcase all I did (and help me land a job); and so wordpress was left behind. Throughout the last 4 years it went through some major rewrites; this article is a way to log those rewrites and what I've learned along the way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F0ftbbuhj19hsdi20tc29.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F0ftbbuhj19hsdi20tc29.gif" alt="gif" width="500" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Timeline
&lt;/h2&gt;

&lt;p&gt;I think there are mainly 3 major releases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Astro&lt;/li&gt;
&lt;li&gt;Laravel&lt;/li&gt;
&lt;li&gt;Hugo (the current one)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Astro
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://astro.build/" rel="noopener noreferrer"&gt;Astro&lt;/a&gt; is an awesome web framework that works really well with static content (which is baiscally all of my content). It worked pretty well with all my content collections and had pretty much all the extensions I needed, but I still needed to add custom extensions to remark to have it handle some &lt;code&gt;iframe&lt;/code&gt; elements I needed in some articles (codesandbox and stackblitz embeds, basically). This ultimately led me to look for a more customizable solution (where I could easily build some more custom stuff). This leads us to the first rewrite of this version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Laravel
&lt;/h2&gt;

&lt;p&gt;Now, I hear you asking:&lt;br&gt;
&lt;a href="https://media2.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%2Fo34sk2gmwbbq13ahgzgz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fo34sk2gmwbbq13ahgzgz.gif" alt="gif" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The honest answer to that is: &lt;strong&gt;why not?&lt;/strong&gt; I believe that if you want to try new technologies (and can afford to - meaning probably don't do this in a work production app), you probably should. I had been hearing of Laravel for a while and finally gave it a shot.&lt;/p&gt;

&lt;p&gt;It was a really nice experience and it was really easy to add some more integrations like automatically adding &lt;a href="https://photoswipe.com/" rel="noopener noreferrer"&gt;photoswipe&lt;/a&gt; tags to each image in an article (I even made &lt;a href="https://github.com/matfire/commonmark-photoswipe?tab=readme-ov-file" rel="noopener noreferrer"&gt;an extension for it&lt;/a&gt;). It also allowed me extra space to add some more quality of life stuff, like a search function using &lt;a href="https://www.meilisearch.com/" rel="noopener noreferrer"&gt;meilisearch&lt;/a&gt; and its &lt;a href="https://laravel.com/docs/11.x/scout" rel="noopener noreferrer"&gt;laravel scout&lt;/a&gt; interface. Plus, Livewire is pretty cool to use (though I have my issues with it - to be discussed in a later post).&lt;/p&gt;

&lt;p&gt;Ultimately, though, it was probably too much for a personal website; it had too much overhead to simply publishing content, mainly just updating the website (without using Forge or Vapor); containerising the application definitely helped, but in my opinion it still took too long and, after some more reflections, it was needlessly overcomplicated for a blog/portfolio.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hugo
&lt;/h2&gt;

&lt;p&gt;And thus we get to &lt;a href="https://gohugo.io/" rel="noopener noreferrer"&gt;Hugo&lt;/a&gt;. I had heard of it in passing but had never really looked into it - so I finally did; it's pretty cool. It:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;supports md files natively&lt;/li&gt;
&lt;li&gt;can handle tags and series automatically (taxonomies FTW)
And best of all, it just produces a &lt;code&gt;public&lt;/code&gt; folder with all static html that I can send off to a cloudflare pages project and call it a day. This allows me to do as much (or as little) customization to the output as I want (more on that in the next section). I believe it is (for my use case, obviously) the most compelling solution at this time (as proven in this article, I'm not against rewriting all of this at some point)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Overengineering simplicity
&lt;/h3&gt;

&lt;p&gt;But it's not over yet! You know how I said above that you should be able to experiment and have fun, right ? Well, let's say I managed to find some fun stuff to do with this new setup. I'll just list them here, because some of this stuff is interesting enough to get its own articles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;client-only search using Lunr and AlpineJS&lt;/li&gt;
&lt;li&gt;automatic og (opengraph) image generation&lt;/li&gt;
&lt;li&gt;automatic photoswipe image rendering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And these are the potential things I might add later:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;newsletter subscription section&lt;/li&gt;
&lt;li&gt;automatic bluesky post with the new article&lt;/li&gt;
&lt;li&gt;and so much more&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I will also look into having a self-hosted Github Runner if I end up reaching the limits of the free plan (though that should hopefully not happen)&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>astro</category>
      <category>hugo</category>
    </item>
    <item>
      <title>Dotfiles, the nix way</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Wed, 30 Oct 2024 08:55:50 +0000</pubDate>
      <link>https://dev.to/matfire/dotfiles-the-nix-way-nob</link>
      <guid>https://dev.to/matfire/dotfiles-the-nix-way-nob</guid>
      <description>&lt;p&gt;I've recently started exploring the &lt;a href="https://nixos.org/" rel="noopener noreferrer"&gt;Nix&lt;/a&gt; ecosystem (I got hooked by &lt;a href="https://www.youtube.com/@vimjoyer" rel="noopener noreferrer"&gt;Vimjoyer's videos&lt;/a&gt;) and decided to give it a try (I even installed NixOS on my laptop, but that will come in a later article).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F4mg1v198weptbflrtzld.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F4mg1v198weptbflrtzld.gif" alt="gif" width="1024" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Dotfiles
&lt;/h2&gt;

&lt;p&gt;First things first, what are dotfiles ? They are basically configuration files that are usually preceded by a &lt;code&gt;.&lt;/code&gt;. or that are usually kept inside a folder called &lt;code&gt;.config&lt;/code&gt; in your home directory. They are used to configure per user settings for apps that support it. For example, you could use it to change the keybindings in your i3 configuration, or pimp your neovim config or just change the color scheme for your favorite terminal. Why would you want to do that, I hear you ask? Why not, I would answer...&lt;br&gt;
&lt;a href="https://media2.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%2Fd89kl003ub3gj9p50y6u.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fd89kl003ub3gj9p50y6u.gif" alt="gif" width="500" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, let's be serious for a second; if you went through the (kind of) trouble that installing Linux is (though that obviously depends on the distro you choose), then you'd probably want to customize to be more "you" or to better fit your needs. Here's an example: I have pretty bad eyesight and tend to prefer some specific colors for windows, text and stuff; after a while, I found out that the Catppuccin Mocha theme is not as hard on my eyes than some other (or even the Gnome or KDE default dark mode, for that matter), so I like for as many of the applciations as I daily drive to use that same theme (plus, I think it looks pretty).&lt;/p&gt;

&lt;p&gt;Here's how you would configure &lt;code&gt;rofi&lt;/code&gt; to use Catppuccin Mocha:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a &lt;code&gt;mocha.rasi&lt;/code&gt; file that will contain all the theme customization rule&lt;/li&gt;
&lt;li&gt;create a &lt;code&gt;config.rasi&lt;/code&gt; file in &lt;code&gt;.config/rofi/&lt;/code&gt; that will contain the import rule for the theme you want: &lt;code&gt;@theme "catppuccin-mocha"&lt;/code&gt;
You might have noticed what my problem is with these kind of configuration files; most of them are custom file formats! This might be fine if you have one or two configuration files, but it gets old really quick if you have more than that.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  My Journey with Dotfiles
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Step 1: files ending in dots
&lt;/h3&gt;

&lt;p&gt;I started playing with dotfiles when I first installed Arch (btw), and the first approach I had was to just write my files directly in the &lt;code&gt;.config&lt;/code&gt; directory. That phase ended quickly once I mistakenly wiped my OS and lost all said files...&lt;/p&gt;

&lt;p&gt;Happens to the best of us, right?&lt;br&gt;
&lt;a href="https://media2.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%2Fmihesrecgqirl49u3pij.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fmihesrecgqirl49u3pij.gif" alt="gif" width="192" height="231"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: version control for the win
&lt;/h3&gt;

&lt;p&gt;Once I got my system up and running again, I decided to version control those files (you live you learn, right?)&lt;br&gt;
Here's the problem with that approach: you either version control the whole &lt;code&gt;.config&lt;/code&gt; directory, or you can create many small repos for each program because, spoiler alert, anything can write stuff in that directory.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3: Stowing
&lt;/h3&gt;

&lt;p&gt;So now you have a git repo containing all your dotfiles but cannot directly clone into to replace your &lt;code&gt;.config&lt;/code&gt; folder, what do you do? You find out there's a tool that could fix all these problems: &lt;a href="https://www.gnu.org/software/stow/" rel="noopener noreferrer"&gt;GNU Stow&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;This tool allows you to create symlinks to anywhere and keep all your original files in a single folder (sound familiar?)&lt;/p&gt;

&lt;p&gt;I'd been on this step for a long time and kind of liked it, to be honest. But then I started hearing about Nix more and more often and so decided to take a look at it.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 4: Manage your home
&lt;/h3&gt;

&lt;p&gt;I'd read about Nix a while ago but had never explored it correctly. That changed when I got some time off work to tinker with some stuff. That's when I heard about &lt;a href="https://github.com/nix-community/home-manager" rel="noopener noreferrer"&gt;home-manager&lt;/a&gt; and decided to give it a try.&lt;/p&gt;
&lt;h2&gt;
  
  
  Home Manager
&lt;/h2&gt;

&lt;p&gt;Home-manager is a tool that allows you to declare your config files and put them wherever they need to be. You can declare almost anything directly using the Nix DSL, but you can also simply copy files into their correct directory and even clone directly a repo from Github (this is the method I use to get my neovim configuration instead of rewriting it to use Nix).&lt;/p&gt;

&lt;p&gt;Let's take a look at a simple home-manager &lt;code&gt;home.nix&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nix"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;pkgs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;home&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;stateVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"24.05"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;home&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;packages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nv"&gt;pkgs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;fzf&lt;/span&gt;
        &lt;span class="nv"&gt;pkgs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;tmuxifier&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nv"&gt;home&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s2"&gt;".config/waybar/mocha.css"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;./styles/mocha.css&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This little configuration will ensure that both fzf and tmuxifier are on your user's $PATH and copies over a css file from your directory into the appropriate &lt;code&gt;.config&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;But this is not all we can do with home-manager (again, I highly encourage you to read the documentation); let's see how we can configure some more stuff.&lt;br&gt;
This is how you can configure kitty, a tty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nix"&gt;&lt;code&gt;  &lt;span class="nv"&gt;programs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;kitty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;enable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"tab_bar_min_tabs"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="s2"&gt;"tab_bar_edge"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"bottom"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="s2"&gt;"tab_bar_style"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"powerline"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="s2"&gt;"tab_powerline_style"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"slanted"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="s2"&gt;"tab_title_template"&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"{title}{' :{}:'.format(num_windows) if num_windows &amp;gt; 1 else ''}"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nv"&gt;font&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"JetBrainsMono Nerd Font"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nv"&gt;themeFile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Catppuccin-Mocha"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This enables kitty, sets some configuration stuff, like the topbar style title template string, but ti also sets up the font to use in the terminal and the theme the terminal will use.&lt;/p&gt;

&lt;p&gt;How about writing configs when home-manager does not have a module for it (or you can't find it)? Well, here is how I configure tmux using home-manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nix"&gt;&lt;code&gt;&lt;span class="nv"&gt;programs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;tmux&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;enable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;plugins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kn"&gt;with&lt;/span&gt; &lt;span class="nv"&gt;pkgs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;tmuxPlugins&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="nv"&gt;catppuccin&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nv"&gt;extraConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;''&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g prefix C-s&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g mouse on&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set-option -g status-position top&lt;/span&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="s2"&gt;      set -g @plugin 'tmux-plugins/tpm'&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_flavour 'macchiato'&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @plugin 'kenos1/tmux-cht-sh'&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @plugin 'jimeh/tmuxifier'&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_window_left_separator ""&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_window_right_separator "&amp;nbsp;"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_window_middle_separator " █"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_window_number_position "right"&lt;/span&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_window_default_fill "number"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_window_default_text "#W"&lt;/span&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_window_current_fill "number"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_window_current_text "#W"&lt;/span&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_status_modules_right "directory user host session"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_status_left_separator  " "&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_status_right_separator ""&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_status_right_separator_inverse "no"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_status_fill "icon"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_status_connect_separator "no"&lt;/span&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="s2"&gt;      set -g @catppuccin_directory_text "#{pane_current_path}"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="s2"&gt;      run '~/.tmux/plugins/tpm/tpm'&lt;/span&gt;&lt;span class="err"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration here allows you to see how you can pass "raw" configuration values via &lt;strong&gt;extraConfig&lt;/strong&gt; and how to setup plugins taken directly from nixpackages.&lt;/p&gt;

&lt;p&gt;The last example I want to show you, is how to retrieve configuration files from a github repository and copy it over to the correct &lt;code&gt;.config&lt;/code&gt; folder. This goes in a bit deeper in the Nix DSL, but I think it still keeps pretty readable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nix"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt;
  &lt;span class="nv"&gt;neovim_config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;pkgs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;fetchFromGitHub&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"matfire"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;repo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"config.nvim"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;rev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"044cb8670307bb3195607b90229f26ffcb61d46d"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;sha256&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"sha256-tzWcYrRGX82kBmPc50LjQmXfNjBoT/sLNanH470NuAE="&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kn"&gt;in&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;home&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;".config/nvim"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;neovim_config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will automatically clone and verify (with the sha256 you provide) the right repository and commit, and then clone (or copy) it over to the right place.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fsafs069suo79ltmrftgb.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fsafs069suo79ltmrftgb.gif" alt="gif" width="480" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The best of both worlds ?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Personally&lt;/em&gt;, I really like doing configs like this; it lets me keep it all in one format (with the occasional exception, obviously) and be sure that whatever OS I use this on, I'll get the same programs &amp;amp; configs each time.&lt;/p&gt;

&lt;p&gt;But it still requires you to learn a new language (or the basics of it, at least) and it's a functional language, which may be a blocker for some. The first experience I ever had with a functional programming language was Haskell back in university, so I can understand the animosity with this principle.&lt;/p&gt;

&lt;p&gt;Still, I believe it worthwhile if you daily drive Linux and have a lot of config files to learn and use this kind of system.&lt;/p&gt;

</description>
      <category>nix</category>
    </item>
    <item>
      <title>Build a reverse ssh tunnel reverse proxy for (not) fun and (not) profit</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Mon, 03 Jun 2024 14:58:51 +0000</pubDate>
      <link>https://dev.to/matfire/build-a-reverse-ssh-tunnel-reverse-proxy-for-not-fun-and-not-profit-50kl</link>
      <guid>https://dev.to/matfire/build-a-reverse-ssh-tunnel-reverse-proxy-for-not-fun-and-not-profit-50kl</guid>
      <description>&lt;p&gt;A few years ago, a team I was part of was working on &lt;a href="https://matteogassend.com/projects/vivi/" rel="noopener noreferrer"&gt;vivi&lt;/a&gt;, our master thesis's project. You can read more about it in the link above if you'd like, but the gist of it is; we were trying to build a solution to handle internet traffic and routing for ephemeral events (think something like comic-con etc) with lots of features and a user interface non-technical users could use and understand.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fby32dyoyr9bld7do00n6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fby32dyoyr9bld7do00n6.gif" alt="Didnt Work The Blob GIF by Max" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where does a reverse ssh tunnel reverse proxy fit into this
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Context
&lt;/h3&gt;

&lt;p&gt;When the time came to built the box that would live between the router and the rest of the network, we went (al least for the POC - proof of concept) with a RaspberryPi 4. We tried different solutions to handle communications between our backend server and all the machines, including using &lt;a href="https://www.balena.io/" rel="noopener noreferrer"&gt;balena os&lt;/a&gt; - which would have worked fine had we not needed to work with the network stack of the device.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build it yourself
&lt;/h3&gt;

&lt;p&gt;So that's why we ended up building this kind of Frankenstein monster of a service. We needed a way to remotely connect to the device to check its status and perform maintenance operations (i.e. reboots, firmware updates etc). And before you ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;couldn't you have just used the ip address of the machine or exposed a port on the network to connect to it?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  NAT and local ip addresses
&lt;/h3&gt;

&lt;p&gt;Fasterthanlime has an excellent video describing how the internet works, you should check it out&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/jjKFXlFNR4E?start=4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  A (forward) ssh tunnel
&lt;/h3&gt;

&lt;p&gt;A normal (or forward) SSH tunnel allows you to securely access a remote service over an encrypted SSH connection.&lt;/p&gt;

&lt;p&gt;For example, let's say you want to access a web service running on a remote server's port 8000, but that port is blocked by a firewall. You can create an SSH tunnel by connecting to the remote server (assuming port 22 is open) and forwarding a local port, say 9000, to the remote port 8000:&lt;br&gt;
you can run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-L&lt;/span&gt; 9000:localhost:8000 user@remote_server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with this command, you can then open the address &lt;code&gt;localhost:9000&lt;/code&gt; and the request will then be forwarded to the remote machine's ssh port and then finally reach the destination port (8000 in this case). This is also called &lt;strong&gt;Tcp Forwarding&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F0u3awbdh98arklcs0zzj.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F0u3awbdh98arklcs0zzj.webp" alt="a schema of the logic behind ssh tunneling" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's reverse that
&lt;/h3&gt;

&lt;p&gt;Now, what happens if the machine I need to connect to is behind a firewall and/or a NAT? It would most likely not work because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I don't know the machine's actual IP address&lt;/li&gt;
&lt;li&gt;I cannot (usually) initiate a connection from outside the local network without an exposed port or something similar&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And so, enters the reverse ssh tunnel.&lt;br&gt;
A reverse ssh tunnel is based on the same principle as the normal ssh tunnel, except it contains an additional step, with the remote machine using the initial connection from the other host to create a new "tunnel" toward the initiating machine. This allows to bypass the issues with firewalls and NATs listed above.&lt;/p&gt;

&lt;p&gt;For example, to tunnel the SSH port (22) of a remote machine to port 8022 on your local machine, the command would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-R&lt;/span&gt; 8022:localhost:22 user@local_host &lt;span class="nt"&gt;-N&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How we built it (attention: do not try this at home, there are easier ways to do this)
&lt;/h2&gt;

&lt;p&gt;There are a couple of part to this setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The http server onboard each device&lt;/li&gt;
&lt;li&gt;The systemd service responsible for the ssh tunnel on each device&lt;/li&gt;
&lt;li&gt;The Server handling all of these connections and all the reverse proxy logic&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Http Server
&lt;/h3&gt;

&lt;p&gt;The Http server is the API we built to manage the device; it allowed us to remotely restart the device, update the dependencies, retrieve its logs etc...&lt;/p&gt;

&lt;p&gt;It was a simple NestJS application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Systemd Service
&lt;/h3&gt;

&lt;p&gt;The systemd service was responsible for receiving a port from the server and configuring the reverse ssh-tunnel to connect to said port.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remote Server
&lt;/h3&gt;

&lt;p&gt;The remote server was the one receiving all the connections and handling the domain name registration for each device and its corresponding reverse proxy configuration.&lt;/p&gt;

&lt;p&gt;The code is available &lt;a href="https://github.com/vivitek/OpenVivi" rel="noopener noreferrer"&gt;here&lt;/a&gt; if you want to take a look at it (though I would not recommend it)&lt;/p&gt;

&lt;p&gt;The steps were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A device would upload its ssh public key to the remote server&lt;/li&gt;
&lt;li&gt;The remote server would then generate an nginx config and associate a domain name to a port number&lt;/li&gt;
&lt;li&gt;The port number would be sent to the device to configure its service&lt;/li&gt;
&lt;li&gt;THe connection was then started on boot&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why you shouldn't do it this way
&lt;/h2&gt;

&lt;p&gt;The main issue with the way we did this is security; there really is no central authority managing this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The device uploads its ssh key and registers itself with the server&lt;/li&gt;
&lt;li&gt;The server never verifies that the request it coming to a legitimate source.&lt;/li&gt;
&lt;li&gt;The server also doesn't check to see if the ssh connection for a specific host is aiming for the right port&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;p&gt;A simpler way to handle this, given the infrastructure requirements, would probably have been a mesh vpn like tailscale or zerotier - or even plain old wireguard. This would still allow all reverse proxy goodies, but would provide a central authority to handle authentication (the server provides and checks for correct credentials on a new connection).&lt;/p&gt;

&lt;p&gt;Really, a vpn would probably have simplified a lot of things for this use case&lt;/p&gt;

</description>
      <category>networking</category>
      <category>ssh</category>
      <category>vpn</category>
      <category>nginx</category>
    </item>
    <item>
      <title>Using Shadcn-ui with Inertia and AdonisJS</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Tue, 26 Mar 2024 14:01:34 +0000</pubDate>
      <link>https://dev.to/matfire/using-shadcn-ui-with-inertia-and-adonisjs-42b3</link>
      <guid>https://dev.to/matfire/using-shadcn-ui-with-inertia-and-adonisjs-42b3</guid>
      <description>&lt;p&gt;Since &lt;a href="https://adonisjs.com" rel="noopener noreferrer"&gt;AdonisJS&lt;/a&gt; V6 has experimental support for &lt;a href="https://inertiajs.com" rel="noopener noreferrer"&gt;Inertia&lt;/a&gt;, I thought it might be a good idea to see if I could configure &lt;a href="//ui.shadcn.com"&gt;shadcn/ui&lt;/a&gt; to run with the aforementioned stack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Inertia with AdonisJS
&lt;/h2&gt;

&lt;p&gt;Since support is experimental, I'll refer you to &lt;a href="https://docs.adonisjs.com/guides/inertia#installation" rel="noopener noreferrer"&gt;Adonis&lt;/a&gt;'s documentation on this procedure. If you're starting from scratch, it may be as simple as installing their inertia starter kit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Shadcn/ui
&lt;/h2&gt;

&lt;p&gt;To install &lt;a href="//ui.shadcn.com"&gt;shadcn/ui&lt;/a&gt;, you can follow the basic instructions for Vite-based projects, but we'll need to adapt a few steps.&lt;br&gt;
The one thing to keep in mind is that you need to specifiy inertia's css file as the &lt;code&gt;global CSS file&lt;/code&gt; during setup.&lt;/p&gt;
&lt;h3&gt;
  
  
  Where to store components and libs
&lt;/h3&gt;

&lt;p&gt;I would personally advice (also, this is what I tested) to store all shadcn related files inside the &lt;code&gt;inertia&lt;/code&gt; folder; i personally created a &lt;code&gt;lib&lt;/code&gt; folder and had shadcn install everything in there.&lt;/p&gt;
&lt;h3&gt;
  
  
  tsconfig
&lt;/h3&gt;

&lt;p&gt;The documentation asks us to create aliases in both the &lt;code&gt;tsconfig&lt;/code&gt; file and the &lt;code&gt;vite.config.{js|ts}&lt;/code&gt; file. If you only change those in the root directory, shadcn will work fine, but your inertia pages will not be able to resolve the imports using those aliases.&lt;br&gt;
You can definitely stop here for this step and modify the imported components to use a normal path instead of the aliases it includes.&lt;/p&gt;

&lt;p&gt;But if you want to avoid that headache, there is one more tsconfig file you'll need to modify; the one inside the &lt;code&gt;inertia&lt;/code&gt; folder. Just copy the same aliases you just set up in the root project.&lt;/p&gt;

&lt;p&gt;Here's, for example, my root project tsconfig:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;compilerOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;//other paths can go here&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@/*&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./inertia/lib/*&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which then translates inside the &lt;code&gt;inertia&lt;/code&gt; folder to:&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="nx"&gt;compilerOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// other paths here&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@/*&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./lib/*&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as for the vite config, here's the interesting bit:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;alias&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// other aliases can go here&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@&lt;/span&gt;&lt;span class="dl"&gt;'&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="nf"&gt;getDirname&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;url&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;/inertia/lib`&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Tailwind Config
&lt;/h3&gt;

&lt;p&gt;After running the installation commands, we need to change a few settings from those created by default in our tailwind config file. This is because shadcn makes certain assumptions regarding the location of all our components and files.&lt;br&gt;
The only thing to modify is the &lt;code&gt;content&lt;/code&gt; array. If you're only using inertia (with React, in this case), you can probably use 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="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;content&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="s2"&gt;./inertia/**/*.{js,ts,jsx,tsx}&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There you go! Now you can enjoy using shadcn/ui with Inertia and AdonisJS. To demonstrate this, I built a small example you can find below:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/rntkn3" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>adonisjs</category>
      <category>react</category>
      <category>inertiajs</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building a dynamic form with Svelte and Typescript</title>
      <dc:creator>Matteo</dc:creator>
      <pubDate>Fri, 23 Feb 2024 13:48:57 +0000</pubDate>
      <link>https://dev.to/matfire/building-a-dynamic-form-with-svelte-and-typescript-4b6o</link>
      <guid>https://dev.to/matfire/building-a-dynamic-form-with-svelte-and-typescript-4b6o</guid>
      <description>&lt;p&gt;In the quest to make &lt;a href="https://magiedit.magitools.app" rel="noopener noreferrer"&gt;magiedit&lt;/a&gt; always better, I figured out that people may want to publish to multiple "accounts" on the same platform. So, the goal for the next feature was to allow just that. A user should be able to select the platform they want to create a &lt;strong&gt;Publisher&lt;/strong&gt; for, fill in the required data, and be able to publish to it.&lt;br&gt;
The problem was in the second to last step; the form. How do you handle the fact that different platforms require different authenticating elements to send requests?&lt;/p&gt;
&lt;h2&gt;
  
  
  Generating a form from a class
&lt;/h2&gt;

&lt;p&gt;As mentioned in a previous article, all the platforms have a decorator that adds them to a list that can be imported in other files, meaning I could get a list of supported platforms and generate a &lt;code&gt;select&lt;/code&gt;, allowing the user to select the platform they wanted to configure. The next step consisted of having a way for the class to describe the input it needs to handle publishing an article.&lt;/p&gt;
&lt;h3&gt;
  
  
  Describing form elements
&lt;/h3&gt;

&lt;p&gt;After some deliberation, I settled on the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;IPlatformSetting&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;htmlFor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nl"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;type defines what form element will be rendered (i.e. input)&lt;/li&gt;
&lt;li&gt;name: the name of the element (pretty self explanatory, I know)&lt;/li&gt;
&lt;li&gt;label: the settings for the label (both the &lt;code&gt;for&lt;/code&gt; attribute and the actual text inside it)&lt;/li&gt;
&lt;li&gt;settings: an object of settings for the html element; as an example, here's what the Dev.to platform settings look like:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&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;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api_token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;htmlFor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api_key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;API Key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&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;text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There still is a bit of information duplication, but for now it works pretty well.&lt;/p&gt;

&lt;h3&gt;
  
  
  Displaying the form elements
&lt;/h3&gt;

&lt;p&gt;Once the user has selected the platforms they want to publish on, the next step is to display all the fields necessary for that specific platform. Remember how we had a method that described precisely this? This is where we get to use it.&lt;br&gt;
With Sveltekit, this could look somthing 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="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;setting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Label&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;setting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;htmlFor&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;setting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Label&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Input&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;setting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;setting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;setting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sr"&gt;/if&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you ever need to do more field types, just add them as available types for each setting element and modify the if condition (hoping someday to have a switch statement in svelte - or pattern matching).&lt;/p&gt;

&lt;h3&gt;
  
  
  Handling submission
&lt;/h3&gt;

&lt;p&gt;This next step is probably the easiest. Since you're also sending the select platform &lt;strong&gt;template&lt;/strong&gt;, you can reference that to determine if the data is valid (why not try &lt;a href="https://superforms.rocks" rel="noopener noreferrer"&gt;superforms&lt;/a&gt;? I made an adapter for it).&lt;/p&gt;

&lt;p&gt;With no validation whatsoever, it could 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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;formData&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;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;formData&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;publisher_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;publisher_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&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;fromEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userPublications&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;publisherName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;publisher_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;publisherData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;publisher_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&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;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ok&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>typescript</category>
      <category>svelte</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
