Logo

dev-resources.site

for different kinds of informations.

Concept: Including dev.to Posts in a Static Hugo Site

Published at
10/30/2023
Categories
webdev
hugo
api
Author
andrebuse
Categories
3 categories in total
webdev
open
hugo
open
api
open
Author
9 person written this
andrebuse
open
Concept: Including dev.to Posts in a Static Hugo Site

Edit: I found a way more elegant solution. I will leave this post up for reference, but I won't actually implement this. Instead, I'll do it the other way round. I found out that dev.to can automatically import posts from RSS feeds, and Hugo can generate RSS feeds. So that feels way more natural and involves less code.

I am currently building a small personal website with Hugo and want to include a blog on it. However, just a static blog on my site won't allow people to comment or otherwise interact with it.

Idea and Motivation 💡

There are some awesome (self-hosted) open source blog systems that do allow interactions, but I don't want to go this route. I want to be able to connect with other developers easily, and also have better discoverability than just a website. This is where dev.to comes into play: It has an awesome community of developers! 🎉

So the plan is: Use my personal site to embed posts from dev.to (with linking back between them). This will achieve a few things that I find important:

  • I can use dev.to to connect with other developers
  • visitors of my website can easily see my content without having to leave the site
  • people that want to further engage can follow the link to the dev.to post

I personally don't mind that this will duplicate content. I think it's a good idea to have a mirror anyway. But I can see why some people wouldn't want that.

Planned Implementation 📝

I already have an idea on how to implement this. My personal website is made using Hugo, so the solution should neatly integrate into this.

Forem API

As you might know, dev.to is a Forem instance. Forem exposes a JSON API that can be used to query posts. For me the important endpoint is GET /api/articles which will give you published posts, optionally filtered by a given username parameter. Perfect!

Hugo Integration

How will I get this data into my static site? I sure could add some JavaScript to load the posts dynamically, but to be honest I prefer them to be static too. So instead, I will use Hugo to fetch the content automatically for me.

Hugo has a getJSON function which can fetch external data. When the static site is built, those resources are fetched so that the result can be used in the website templates.

This should be enough for my usecase. For more advanced scenarios I would use a Hugo Module.

GitHub Action

With the posts included in my static site, the only thing missing is some way to easily rebuild and deploy the static site whenever I create a new dev.to post. Therefore I will create a GitHub Action that does exactly this.

I won't automate this in the beginning since I want to keep track if everything works as expected. This will change once I'm sure that my code is running stable. GitHub has an API endpoint that allows triggering a Workflow, so I can use a dev.to webhook which triggers the CI for every new post. 🪄

Thanks for reading! ❤️

I hope you found this concept/idea interesting. The implementation will follow, however I needed a first post here on dev.to to test the API. So I thought, why not share the idea? That way I have a post to test my code with, plus other people can see what I'm working on!

I will probably post a new article once this project is working, including anything I learned along the way. ✨

hugo Article's
30 articles in total
Favicon
How to Deploy a Static Website with Hugo and GitHub Pages
Favicon
How to create a hugo theme with contact form
Favicon
🛠 Build a Professional CV in PDF with Markdown and Hugo
Favicon
Open source Hugo Theme for building SaaS websites: Saasify
Favicon
How to Host Hugo in Vercel
Favicon
Create a Hugo Theme from Scratch - II
Favicon
Create a Hugo Theme from Scratch - III
Favicon
Create a Hugo Theme from Scratch - IV
Favicon
Life of a blog - blogging in 2024 and beyond
Favicon
Create a Hugo Theme from Scratch - I
Favicon
Using Hugo Render hooks to make links bend to your will
Favicon
Step-by-Step Guide to Deploy Hugo on Vercel
Favicon
Hugo shortcode for sns with unit.link like button
Favicon
Deploying Hugo from Self-Hosted GitLab to Cloudflare Pages
Favicon
Adding Search Functionality to a Hugo Static Site Based on INFINI Pizza for WebAssembly
Favicon
How to Build Personal Website for Free With Hugo
Favicon
My Obsidian + Hugo blogging setup
Favicon
How to schedule new blog posts
Favicon
Hello World
Favicon
Migrating my blog from Jekyll to Hugo
Favicon
[pt-BR] Hugo: Criando sua primeira aplicação
Favicon
My mistakes regarding the tech SEO optimization of my website
Favicon
Building static websites
Favicon
How to deploy a Hugo site to S3 in 2024
Favicon
Need advice on first website
Favicon
[pt-BR] Hugo: a forma mais rápida de fazer um site
Favicon
Building a Dynamic Contact Form for Your Hugo Static Website
Favicon
Building a Blog With a CMS Using Hugo and Netlify
Favicon
Concept: Including dev.to Posts in a Static Hugo Site
Favicon
Build & Deploy a Site with Hugo & Firebase

Featured ones: