Skip to content

Commit

Permalink
chore: switch to caddy webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
noxilixon committed Jul 4, 2024
1 parent 10fb5d6 commit 2aee301
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 158 deletions.
113 changes: 113 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# www redirect
www.{$SITE_ADDRESS:localhost} {
redir https://{$SITE_ADDRESS}{uri}
}

# production
{$SITE_ADDRESS:localhost} {
root * {$WEBROOT:public}
encode gzip

@de_before_en {
header_regexp Accept-Language de.*en
path /
}
@en_before_de {
header_regexp Accept-Language en.*de
path /
}
@de_only {
header_regexp Accept-Language de
path /
}
@fallback {
path /
}

redir @de_before_en /de 302
redir @en_before_de /en 302
redir @de_only /de 302
redir @fallback /en 302

redir /index_en /en 301
redir /network /de/map 301
redir /contact /de/contact/ 301
redir /contact_en /en/contact 301
redir /download /de/downloads 301
redir /participate/ /de/participate 301
redir /p /de/participate 301
redir /impressum /de/impressum 301
redir /wiki /de/wiki 301
redir /meshwiki /de/wiki 301

file_server
}

# development
dev.{$SITE_ADDRESS:localhost} {
root * {$WEBROOT_DEV:public}
encode gzip

@de_before_en {
header_regexp Accept-Language de.*en
path_regexp branch ^\/([[:alnum:]]+)(\/$|$)
}
@en_before_de {
header_regexp Accept-Language en.*de
path_regexp branch ^\/([[:alnum:]]+)(\/$|$)
}
@de_only {
header_regexp Accept-Language de
path_regexp branch ^\/([[:alnum:]]+)(\/$|$)
}
@fallback {
path_regexp branch ^\/([[:alnum:]]+)(\/$|$)
}

redir @de_before_en /{re.branch.1}/de 302
redir @en_before_de /{re.branch.1}/en 302
redir @de_only /{re.branch.1}/de 302
redir @fallback /{re.branch.1}/en 302

@index_en {
path_regexp branch ^\/([[:alnum:]]+)\/index\_en
}
redir @index_en /{re.branch.1}/en 301

@network {
path_regexp branch ^\/([[:alnum:]]+)\/network
}
redir @network /{re.branch.1}/de/map 301

@contact {
path_regexp branch ^\/([[:alnum:]]+)\/contact
}
redir @contact /{re.branch.1}/de/contact 301

@contact_en {
path_regexp branch ^\/([[:alnum:]]+)\/contact_en
}
redir @contact_en /{re.branch.1}/en/contact 301

@download {
path_regexp branch ^\/([[:alnum:]]+)\/download
}
redir @download /{re.branch.1}/de/downloads 301

@participate {
path_regexp branch ^\/([[:alnum:]]+)\/(participate|p$)
}
redir @participate /{re.branch.1}/de/participate 301

@impressum {
path_regexp branch ^\/([[:alnum:]]+)\/impressum
}
redir @impressum /{re.branch.1}/de/impressum 301

@wiki {
path_regexp branch ^\/([[:alnum:]]+)\/(meshwiki|wiki)
}
redir @wiki /{re.branch.1}/de/wiki 301

file_server
}
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,41 @@

This is the repository for the website of the [Freifunk Community Berlin](https://berlin.freifunk.net).

The website is built using the static website generator Hugo.
The website is built using the static website generator Hugo and served with Caddy.

## Install

- Clone this repository
- Load submodule with `git submodule init` and `git submodule update`
- Install [Hugo](https://gohugo.io/installation/)
- Install [Caddy](https://caddyserver.com/docs/install)

## Run for development
## Development

For quick start you can use the hugo development server.

```console
hugo server -w
```

You can change the base address `-b` and the bind address `--bind` if your run it on a remote machine.
If you want to test the full setup including the webserver you can generate the content for localhost and serve it, while watching for changes in content and config.

```console
hugo server -w -b http://localhost:1313/ --bind 0.0.0.0
hugo -b https://localhost/ -w & caddy run --watch
```

You can set the environment variables `HUGO_MATRIX_ACCESS_TOKEN`, `HUGO_MATRIX_HOME_SERVER` and `HUGO_GITHUB_ACCESS_TOKEN` to get real activity informations. Else some dummy data is used.
## Production

First you must generate the content. You can set the environment variables `HUGO_MATRIX_ACCESS_TOKEN`, `HUGO_MATRIX_HOME_SERVER` and `HUGO_GITHUB_ACCESS_TOKEN` to get real activity informations. Else some dummy data is used.

```console
HUGO_GITHUB_ACCESS_TOKEN="secret" HUGO_MATRIX_ACCESS_TOKEN="secret" HUGO_MATRIX_HOME_SERVER="htps://matrix.org" hugo server -w
HUGO_GITHUB_ACCESS_TOKEN="<github_secret>" HUGO_MATRIX_ACCESS_TOKEN="<matrix_secret>" HUGO_MATRIX_HOME_SERVER="htps://matrix.org" hugo --minify -b <baseURL>
```

## Build for production
Then start the server with the production address and webroots.

```console
hugo build --minify -b <baseURL>
SITE_ADDRESS="berlin.freifunk.net" WEBROOT="/var/www" WEBROOT_DEV="/var/www-dev" caddy start
```

## Structure
Expand All @@ -50,7 +55,7 @@ hugo build --minify -b <baseURL>

The website is deployed automatically via GitHub actions. The main branch is at [berlin.freifunk.net](https://berlin.freifunk.net). The other branches could be accessed via `dev.berlin.freifunk.net/<BRANCH_NAME>/`.

The actions are defined in `.github/workflows` and could be configured with [GitHub variables and secrets](https://github.com/freifunk-berlin/berlin.freifunk.net/settings/secrets/actions). The configurations for the production and development webserver are in the `apache` directory.
The actions are defined in `.github/workflows` and could be configured with [GitHub variables and secrets](https://github.com/freifunk-berlin/berlin.freifunk.net/settings/secrets/actions). The configurations for the production and development webserver are in the `Caddyfile` file.

## Data fetching

Expand Down
33 changes: 0 additions & 33 deletions apache/dev.website.conf

This file was deleted.

116 changes: 0 additions & 116 deletions apache/website.conf

This file was deleted.

1 change: 1 addition & 0 deletions themes/lotusdocs
Submodule lotusdocs added at f5785a

0 comments on commit 2aee301

Please sign in to comment.