Skip to content

Commit c6c941c

Browse files
committed
New website
1 parent 5e6d9a8 commit c6c941c

File tree

21 files changed

+601
-259
lines changed

21 files changed

+601
-259
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from pathlib import Path
2+
from jinja2 import Template
3+
import datetime
4+
import logging
5+
import json
6+
import re
7+
import sys
8+
import yaml
9+
10+
logger = logging.getLogger(__name__)
11+
12+
def get_externals() -> list:
13+
data = []
14+
15+
return data
16+
17+
def main() -> bool:
18+
logger.info(f"Reading lists of datasets")
19+
20+
catalog = json.loads(Path('./stac/catalog.json').read_text())
21+
data = list(filter(lambda link: link["rel"] == "child", catalog["links"]))
22+
23+
for i, d in enumerate(data):
24+
title = re.sub(r"^Field\s+boundaries\s+for\s+", "", d["title"])
25+
title = title[0].upper() + title[1:]
26+
data[i]["title"] = title
27+
28+
config = yaml.safe_load(Path("./data/external.yaml").read_text())
29+
for r in config["external"]:
30+
data.append(r)
31+
32+
data.sort(key = lambda x: x["title"])
33+
count = len(data)
34+
now = datetime.datetime.now(datetime.timezone.utc).strftime("%b %d %Y, %H:%M %Z")
35+
template = Template(Path("./data/index.md.jinja").read_text())
36+
content = template.render(data=data, updated=now, count=count)
37+
with open("./data/index.md", "w", encoding="utf-8") as f:
38+
f.write(content)
39+
40+
sys.exit(0)
41+
42+
43+
if __name__ == "__main__":
44+
main()
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from os import error
2+
from pathlib import Path
3+
from jinja2 import Template
4+
import datetime
5+
import logging
6+
import requests
7+
import os
8+
import sys
9+
import yaml
10+
11+
logger = logging.getLogger(__name__)
12+
13+
headers = {}
14+
env = dict(os.environ)
15+
if "GITHUB_TOKEN" in env:
16+
headers["Authorization"] = " ".join(["Bearer", os.environ["GITHUB_TOKEN"]])
17+
else:
18+
logger.warning("No GITHUB_TOKEN found in env")
19+
20+
def unslugify(s: str) -> str:
21+
return s.replace("-", " ").replace("_", " ").title()
22+
23+
def get_repo(response) -> dict:
24+
data = {
25+
"title": unslugify(response["name"]),
26+
"url": response["html_url"],
27+
"description": response["description"]
28+
}
29+
if response["archived"]:
30+
data["description"] = "**DEPRECATED.** " + data["description"]
31+
return data
32+
33+
def get_repos() -> list:
34+
logger.info(f"Reading list of repositories")
35+
36+
with requests.get("https://api.github.com/users/fiboa/repos?per_page=1000", headers=headers) as site:
37+
repos = site.json()
38+
return repos
39+
40+
def filter_repos(repos, type) -> list:
41+
data = []
42+
try:
43+
for repo in repos:
44+
if not isinstance(repo, dict):
45+
logger.error(f"response invalid")
46+
continue
47+
if repo["is_template"] or repo["visibility"] != "public" or type not in repo["topics"]:
48+
continue
49+
data.append(get_repo(repo))
50+
except error as e:
51+
logger.error(f"fiboa org not available: {e}")
52+
return data
53+
54+
def get_externals(base) -> list:
55+
data = []
56+
config = yaml.safe_load((base / "external.yaml").read_text())
57+
for r in config["github"]:
58+
try:
59+
logger.info(f"Reading community GitHub repos individually")
60+
with requests.get(f"https://api.github.com/repos/{r['org']}/{r['repo']}", headers=headers) as repo:
61+
data.append(get_repo(repo.json()))
62+
except error as e:
63+
logger.error(f"community repo not available: {e}")
64+
65+
for r in config["external"]:
66+
data.append(r)
67+
68+
return data
69+
70+
def create_overview(repos, folder, label):
71+
print(f"Generating {folder}")
72+
base = Path(f"./{folder}/")
73+
data = filter_repos(repos, label)
74+
data.extend(get_externals(base))
75+
data.sort(key = lambda x: x["title"])
76+
count = len(data)
77+
now = datetime.datetime.now(datetime.timezone.utc).strftime("%b %d %Y, %H:%M %Z")
78+
template = Template((base / "index.md.jinja").read_text())
79+
target = base / "index.md"
80+
content = template.render(data=data, updated=now, count=count)
81+
82+
with open(target, "w", encoding="utf-8") as f:
83+
f.write(content)
84+
85+
def main():
86+
repos = get_repos()
87+
create_overview(repos, "extensions", "extension")
88+
create_overview(repos, "software", "software")
89+
sys.exit(0)
90+
91+
92+
if __name__ == "__main__":
93+
main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
requests
2+
jinja2
3+
pyyaml

.github/workflows/build.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

.github/workflows/update.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build and Deploy Jekyll Site
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # at 00:00 everyday
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
build-and-deploy:
12+
runs-on: ubuntu-latest
13+
14+
permissions:
15+
contents: read
16+
pages: write
17+
id-token: write
18+
19+
environment:
20+
name: github-pages
21+
url: ${{ steps.deployment.outputs.page_url }}
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Ruby
28+
uses: ruby/setup-ruby@v1
29+
with:
30+
ruby-version: '3.1'
31+
bundler-cache: true
32+
33+
- name: Setup Python
34+
uses: actions/setup-python@v5
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: lts/*
40+
41+
- name: Setup Pages
42+
id: pages
43+
uses: actions/configure-pages@v4
44+
45+
- name: Update extensions / software
46+
run: |
47+
pip install -r .github/build-script/requirements.txt
48+
python .github/build-script/create_overviews.py
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Update datasets
53+
run: python .github/build-script/create_data.py
54+
55+
- name: Build Jekyll site
56+
run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"
57+
env:
58+
JEKYLL_ENV: production
59+
60+
- name: Build Map
61+
run: |
62+
cd map
63+
npm ci
64+
npm run build
65+
cd ..
66+
rm -r ./_site/map/*
67+
cp -r ./map/dist/* ./_site/map
68+
69+
- name: Upload artifact
70+
uses: actions/upload-pages-artifact@v3
71+
with:
72+
path: ./_site
73+
74+
- name: Deploy to GitHub Pages
75+
if: github.ref == 'refs/heads/main'
76+
id: deployment
77+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Jekyll build files
2+
_site/
3+
.sass-cache/
4+
.jekyll-cache/
5+
.jekyll-metadata
6+
7+
# Bundler files
8+
vendor/
9+
.bundle/
10+
Gemfile.lock
11+
12+
# OS generated files
13+
.DS_Store
14+
.DS_Store?
15+
._*
16+
.Spotlight-V100
17+
.Trashes
18+
ehthumbs.db
19+
Thumbs.db
20+
21+
# IDE files
22+
.vscode/
23+
.idea/
24+
*.swp
25+
*.swo
26+
27+
# Node modules (if using npm)
28+
node_modules/
29+
30+
# Local development
31+
.env
32+
/extensions/index.md
33+
/software/index.md

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source "https://rubygems.org"
2+
3+
gem "github-pages", group: :jekyll_plugins

0 commit comments

Comments
 (0)