| 1 |
--- |
| 2 |
title: Host on SourceHut Pages |
| 3 |
description: Host your project on SourceHut Pages. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
aliases: [/hosting-and-deployment/hosting-on-sourcehut/] |
| 7 |
--- |
| 8 |
|
| 9 |
Use these instructions to host your site on SourceHut Pages using either manual deployment or the SourceHut build system. |
| 10 |
|
| 11 |
{{% include "/_common/gitignore-public.md" %}} |
| 12 |
|
| 13 |
## Prerequisites |
| 14 |
|
| 15 |
- Working familiarity with [Git][] or [Mercurial][] for version control |
| 16 |
- Completion of the Hugo [Quick Start][] |
| 17 |
- A [SourceHut account][] |
| 18 |
- A Hugo website on your local machine that you are ready to publish |
| 19 |
|
| 20 |
Any and all mentions of `<YourUsername>` refer to your actual SourceHut username and must be substituted accordingly. |
| 21 |
|
| 22 |
## BaseURL |
| 23 |
|
| 24 |
The [`baseURL`][] in your project configuration must reflect the full URL provided by SourceHut Pages if you are using the default address (e.g. `https://<YourUsername>.srht.site/`). If you want to use another domain, check the [custom domain section][] of the official documentation. |
| 25 |
|
| 26 |
## Manual deployment |
| 27 |
|
| 28 |
This method does not require a paid account. To proceed you will need to create a [SourceHut personal access token][] and install and configure the [hut][] CLI tool: |
| 29 |
|
| 30 |
```sh |
| 31 |
hugo build |
| 32 |
tar -C public -cvz . > site.tar.gz |
| 33 |
hut init |
| 34 |
hut pages publish -d <YourUsername>.srht.site site.tar.gz |
| 35 |
``` |
| 36 |
|
| 37 |
A TLS certificate will be automatically obtained for you, and your new website will be available at `https://<YourUsername>.srht.site/` (or the provided custom domain). |
| 38 |
|
| 39 |
## Automated deployment |
| 40 |
|
| 41 |
This method requires a paid account and relies on the SourceHut build system. |
| 42 |
|
| 43 |
First, define your [build manifest][] by creating a `.build.yml` file in the root of your project. The following is a bare-bones template: |
| 44 |
|
| 45 |
```yaml {file=".build.yml" copy=true} |
| 46 |
image: alpine/edge |
| 47 |
packages: |
| 48 |
- hugo |
| 49 |
- hut |
| 50 |
oauth: pages.sr.ht/PAGES:RW |
| 51 |
environment: |
| 52 |
site: <YourUsername>.srht.site |
| 53 |
tasks: |
| 54 |
- package: | |
| 55 |
cd $site |
| 56 |
hugo build |
| 57 |
tar -C public -cvz . > ../site.tar.gz |
| 58 |
- upload: | |
| 59 |
hut pages publish -d $site site.tar.gz |
| 60 |
``` |
| 61 |
|
| 62 |
If your site requires [Dart Sass][] to transpile Sass to CSS, set the DART_SASS_VERSION to the [latest version number][] and include the Dart Sass installation lines before running the Hugo build step. Note that for Alpine, the `linux-x64-musl` version is used. |
| 63 |
|
| 64 |
```yaml {file=".build.yml" copy=true} |
| 65 |
image: alpine/edge |
| 66 |
packages: |
| 67 |
- hugo |
| 68 |
- hut |
| 69 |
- curl # For Dart Sass installation |
| 70 |
oauth: pages.sr.ht/PAGES:RW |
| 71 |
environment: |
| 72 |
site: <YourUsername>.srht.site |
| 73 |
tasks: |
| 74 |
- package: | |
| 75 |
DART_SASS_VERSION=1.102.0 |
| 76 |
mkdir -p $HOME/.local |
| 77 |
curl -L https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64-musl.tar.gz -o dart-sass.tar.gz |
| 78 |
tar -xzf dart-sass.tar.gz -C $HOME/.local |
| 79 |
rm dart-sass.tar.gz |
| 80 |
chmod -R +x $HOME/.local/dart-sass/src |
| 81 |
export PATH="$HOME/.local/dart-sass:$PATH" |
| 82 |
sass --version # Verify installation |
| 83 |
cd $site |
| 84 |
hugo build |
| 85 |
tar -C public -cvz . > ../site.tar.gz |
| 86 |
- upload: | |
| 87 |
hut pages publish -d $site site.tar.gz |
| 88 |
``` |
| 89 |
|
| 90 |
Create a repository titled `<YourUsername>.srht.site` (or your custom domain, if applicable) and push your local project to the repository. |
| 91 |
|
| 92 |
You can now follow the build progress of your page at `https://builds.sr.ht/`. |
| 93 |
|
| 94 |
After the build has passed, a TLS certificate will be automatically obtained for you and your new website will be available at `https://<YourUsername>.srht.site/` (or the provided custom domain). |
| 95 |
|
| 96 |
## Other resources |
| 97 |
|
| 98 |
- [SourceHut Pages][] |
| 99 |
- [SourceHut Builds user manual][] |
| 100 |
|
| 101 |
[Dart Sass]: https://gohugo.io/functions/css/sass/#dart-sass |
| 102 |
[Git]: https://git-scm.com/ |
| 103 |
[Mercurial]: https://www.mercurial-scm.org/ |
| 104 |
[Quick Start]: /getting-started/quick-start/ |
| 105 |
[SourceHut Builds user manual]: https://man.sr.ht/builds.sr.ht/ |
| 106 |
[SourceHut Pages]: https://srht.site/ |
| 107 |
[SourceHut account]: https://meta.sr.ht/login |
| 108 |
[SourceHut personal access token]: https://meta.sr.ht/oauth2/personal-token |
| 109 |
[`baseURL`]: /configuration/all/#baseurl |
| 110 |
[build manifest]: https://man.sr.ht/builds.sr.ht/#build-manifests |
| 111 |
[custom domain section]: https://srht.site/custom-domains |
| 112 |
[hut]: https://sr.ht/~xenrox/hut/ |
| 113 |
[latest version number]: https://github.com/sass/dart-sass/releases |