Skip to content

Commit

Permalink
Remote data: Update commnunity api on build
Browse files Browse the repository at this point in the history
  • Loading branch information
noxilixon authored and Lino committed Feb 13, 2024
1 parent 38a53a4 commit aaf9faf
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 94 deletions.
2 changes: 2 additions & 0 deletions .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
ignorePatterns: ["layouts/page/single.json"]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ 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.

## Data fetching

To display up to date information, we fetch and generate some data during the build process. These informations are available as shortcodes for the content and as partials for the templates. They are used at various places of the website.

- Nodecount (ff-community api)
- Lastchange (ff-community api)
5 changes: 5 additions & 0 deletions content/berlin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
outputs:
- json
url: /static/berlin.json
---
98 changes: 98 additions & 0 deletions layouts/page/single.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{{ $lastchange := partial "lastchange.html" }}
{{ $nodecount := partial "nodecount.html" }}

{
"api": "0.5.2",
"contact": {
"email": "info@berlin.freifunk.net",
"ml": "berlin@berlin.freifunk.net",
"twitter": "@freifunk_berlin",
"matrix": "https://matrix.to/#/#berlin.freifunk.net:matrix.org"
},
"location": {
"address": {
"name": "Haus der Materialisierung",
"street": "Otto-Braun-Str. 70-72",
"zipcode": "10178"
},
"city": "Berlin",
"country": "DE",
"geoCode": {
"lat": 52.52315,
"lon": 13.41957
}
},
"name": "Freifunk Berlin",
"nodeMaps": [
{
"interval": "daily",
"mapType": "geographical",
"technicalType": "openwifimap",
"url": "https://openwifimap.net"
},
{
"interval": "daily",
"mapType": "geographical",
"technicalType": "hopglass",
"url": "https://hopglass.berlin.freifunk.net"
}
],
"socialprojects": {
"number": 38,
"website": "https://wiki.freifunk.net/Berlin:Refugees"
},
"state": {
"focus": [
"infrastructure/backbone",
"Public Free Wifi",
"Free internet access"
],
"lastchange":"{{ $lastchange }}",
"nodes": {{ $nodecount }}
},
"techDetails": {
"firmware": {
"docs": "https://wiki.freifunk.net/Berlin:Firmware",
"name": "falter",
"registrationurl": "https://config.berlin.freifunk.net/",
"url": "https://berlin.freifunk.net/downloads/",
"vpnaccess": "fwimage"
},
"legals": [
"vpnnational",
"institutions"
],
"networks": {
"ipv4": [
{
"network": "10.31.0.0/16"
},
{
"network": "10.36.0.0/16"
},
{
"network": "10.230.0.0/16"
},
{
"network": "10.248.0.0/14"
}
],
"ipv6": [
{
"network": "2001:bf7::/32"
}
]
},
"routing": [
"batman-adv",
"OLSR",
"Babel"
],
"updatemode": [
"manual",
"autoupdate"
]
},
"url": "https://berlin.freifunk.net/"
}

4 changes: 4 additions & 0 deletions layouts/partials/lastchange.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{/* Get the current time in coorrect format */}}
{{ $currentTime := now }}
{{ $lastchange := $currentTime.Format "2006-01-02T15:04:05-07:00" }}
{{ return $lastchange }}
14 changes: 14 additions & 0 deletions layouts/partials/nodecount.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{/* Count the nodes active on hopglass */}}
{{ $data := "" }}
{{ $url := "https://hopglass.berlin.freifunk.net/nodes.json" }}
{{ with resources.GetRemote $url }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ $data = . | transform.Unmarshal }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
{{ $nodecount := len $data.nodes }}
{{ return $nodecount }}
1 change: 1 addition & 0 deletions layouts/shortcodes/lastchange.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ partial "lastchange.html" }}
1 change: 1 addition & 0 deletions layouts/shortcodes/nodecount.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ partial "nodecount.html" }}
94 changes: 0 additions & 94 deletions static/static/berlin.json

This file was deleted.

0 comments on commit aaf9faf

Please sign in to comment.