Create an internationalized blog in minutes with this Astro template
Adonys â˘
In this article, I will show you how to create a blog with internationalization (like this one) in minutes using Astro and deploy it with Cloudflare Pages for free. This blog supports English, Spanish, and French by default, but you can add more languages.
Features
- Internationalization (i18n) support.
- RSS feed (with i18n support).
- Sitemap.
- Markdown support.
- SEO optimized.
- Lighthouse score 100.
Prerequisites
- GitHub account.
- Cloudflare account.
- Node.js 18.x or later.
- Git.
Setup and deploy
To set up and deploy your blog follow these 6 steps:
- Create a new repo using the astro-blog-i18n-starter. Click on the âUse this templateâ button, add the new repository name, and click on âCreate repositoryâ.
- Log in to the Cloudflare dashboard and select your account.
- In Account Home, select Workers & Pages > Pages > Connect to Git.
- Select the repository you created in step 1 and click on âBegin setupâ. If this is your first time using Cloudflare Pages, you may need to connect your GitHub account.
- In this step, you can configure the build setting. For this template, you can use the default settings.
- Click on âSave and Deployâ.
Once the deployment is done, you can access to your blog using an URL that ends with .pages.dev. Keep in mind that the first deployment can take a few minutes and if you join to the website URL you will see a DNS address could not be found. Diagnosing the problem error. This is normal, you just need to wait a few minutes and refresh the page.
Custom domain (optional but recommended)
To add a custom domain to your blog, you need to have a purchased domain. (In this article, I will not explain how to buy a domain, but I recommend using Namecheap or much better, Cloudflare Registrar) and follow these steps:
- In the Cloudflare dashboard, select your account.
- On the âWebsiteâ tab, click on âAdd domainâ.
- In this case we will use the free plan, so scroll down, select the free plan, and click on âContinueâ.
- Change the nameservers of your domain to the Cloudflare nameservers. You can do this where you bought the domain (I.e. Namecheap, Cloudflare Registrar or any other domain provider).
- To validate if Cloudflare was configured correctly with your domain, go to Websites and you should see the domain status as âActiveâ. If you see a âPending Nameserver Updateâ, I recommend double-checking the nameserverâs configuration.
- Now, come back to the Cloudflare dashboard and select your account.
- Select Worker & Pages and then your project name (if you did not change the default name, it will be the same as the repository name).
- Select the âCustom domainsâ tab and click on âSetup a custom domainâ.
- Write your domain or subdomain, click on âContinueâ, and then click on âActivate DNSâ.
I recommend adding two domains, one with www and another without it. This is because some users will write the www and others will not.
CNAME www adonys-dot-me-website.pages.dev
CNAME @ adonys-dot-me-website.pages.dev
After adding the custom domains, you need to wait up to 24 hours to see the changes. Although, normally, the changes are seen in a few minutes.
If you have any issues, you can check the Cloudflare documentation for more information.
Modifying the template
- First, I recommend modifying the
site.config.mjsfile to add your site URL. Change thehttps://example.comby your Cloudflare pages URL or custom domain. - Also, you can handle the translations modifying the
src/i18n/ui.tsfile. - Edit the site header items in
src/components/Header.astro. - Add your name to the footer in
src/components/Footer.astro. - Remove the demo posts in the
src/content/blog/folder.
Adding new posts
To add a new post, you need to create a new folder inside the src/content/blog/ folder. The folder name will be the post slug. Inside the folder, you need to create a en.md file with the post content in English and a es.md file with the post content in Spanish, and fr.md file with the post content in French. You can add more languages if you want.
On the head of each Markdown file, you need to add the following metadata:
---
title: ""
description: ""
pubDate: ""
heroImage: ""
author: ""
lang: ""
---
Your post content here...
Why I am using Cloudflare Pages instead of Vercel?
I think that this is a good question, and it is enough to write a new article about it. But in summary, I am using Cloudflare Pages because, for me, the Cloudflare CDN and Vercel Hosting do not work well together, some static files like images are not loading.
I have been using Vercel for a long time, but I have been having some issues to use the Cloudflare CDN with Vercel. So I decided to use all the Cloudflare ecosystem for this blog, so that I stopped having issues with the images and other static files.
Now I am using my adonys.me domain from Namecheap with the Hosting, CDN, and SSL from Cloudflare. I am very happy with the performance and the free tier that Cloudflare offers.
Maybe there is a way to use Vercel with Cloudflare CDN, but for me, using Cloudflare Page was a faster solution.
Credits
The template astro-blog-i18n-starter was created by Rebeca Murillo. In fact, I have contributed to the project.
I am using that template for this site, but I have made some modifications that you can see on my GitHub repository. I recommend reading my first article About this blog to know more about the changes I made.