Coding Y3
How to publish a static HTML website?

How to publish a static HTML website?

At the end of a more or less extensive development process, it’s time to bring a website to life once and for all by publishing it and making it accessible to everyone online. We’re going to look at how to make publication as simple as possible and how best to integrate it into a workflow.

Chapter 1
At the source, a server

Publishing a website intrinsically involves uploading the website’s data to a connected server, which then makes the website’s content available to as many people as possible, from a browser, via the HTTP protocol.

Setting up a server

Depending on the technologies used, the server will need various specific settings to enable communication with external clients and to make it secure and optimised. Servers are usually based on the OS Ubuntu, also known as a distribution of Linux.

Hosting services

However, setting up a server is a fairly complex task that requires a great deal of expertise and is often expensive. This is why the vast majority of the general public use what is known as a hosting company, i.e. a service that provides access to shared, secure, pre-set servers, making it much easier to upload files.

But these services obviously come at a price, and are not necessarily suitable for experimental projects or projects that require frequent code modifications, since uploading is done manually via what is known as FTP software.

Chapter 2
Breaking free from traditional hosting providers

For some years now, other possibilities have been available to make the publication of static websites even simpler and more integrated to development work.

Static websites

A static website is based on HTML files (i.e. files that can be read directly), as opposed to a dynamic website which is based on a server-side language (PHP for example) and generally a database (i.e. requiring a server). The simplicity of a static website makes it possible to “do without” a traditional server and use simplified services.

Codeberg Pages

The best known of these is Github Pages, directly integrated into Github. Since our work lives on Codeberg, we’ll use its equivalent, Codeberg Pages. The idea behind Codeberg Pages is to make a website deployed on Codeberg directly accessible online, so that updating is based solely on the need to publish via Git, a technology already widely integrated into web developers’ workflows.

Create a Codeberg repository

To deploy a website on Codeberg, start by creating a new repository from the Codeberg interface, by clicking on the + button at the top right and selecting New repository. Leave it empty, without README or license, as your files will come from your computer. It’s important to keep the repository Public and not tick Make repository private, as Codeberg Pages only publishes public repositories.

Choose the name carefully, without spaces, dots or special characters, as it becomes part of your website’s address: https://username.codeberg.page/repository-name/. For example, the repository my-website of the user jane-doe will be online at https://jane-doe.codeberg.page/my-website/.

Allow Codeberg Pages

To make a website deployed on Codeberg accessible, go to the repository Settings and the Webhooks tab, click on Add webhook and choose Forgejo. In Target URL, enter the address of your website, https://username.codeberg.page/repository-name/, set the Branch filter to pages, then confirm with Add webhook. From now on, every time something is pushed to the pages branch of the repository, Codeberg Pages updates the website. Don’t use the Test delivery button: it always fails, and that’s expected.

Publish your website

All that’s left is to send your files to the pages branch. Open the folder of your project, based on the starterkit I’ve provided, in VS Code and type these commands in the Terminal, replacing the URL with the one of your repository:

git init
git checkout -b pages
git add .
git commit -m "First commit"
git remote add origin https://codeberg.org/username/repository-name.git
git push -u origin pages

Git will ask for your Codeberg username and password. A few moments later, your website is online at its address. From then on, every change can be published from the Source Control window of VS Code, by committing it and clicking on Sync Changes.

The hidden .git folder

The git init command creates a hidden folder called .git inside your project folder. Git keeps in it a copy of every version of every file you commit, so it grows with each commit, and an image you deleted from your project still takes up space in it.

This folder is not published online, but Finder counts it in the size of your project folder. Since your website has to weigh less than 10MB, leave it out when you check: press Cmd + Shift + . in Finder to show hidden files, and subtract the size of .git from the total.

Other services

Other services of this type exist, often more complete and allowing, for example, the hosting of websites coded in NodeJS on the server side. These include Vercel and Netlify, but these services rely on platforms such as Github to deploy the code, and can’t connect to Codeberg directly.