Skip to content

Commit

Permalink
Generate and use image thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Oct 1, 2022
1 parent e2e23d3 commit a9cb9f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/gh-pages-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ jobs:
run: |
python generate_static_api.py
- name: Generate image thumbnails
uses: subic/ghaction-thumbnails@master
with:
source: images
output: site/images/thumbs
sizes: 300x300
fit: outside

- name: Copy images to site directory
run: |
cp images/* site/images/
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: site
force: false
9 changes: 9 additions & 0 deletions generate_static_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def sort_list(obj: dict, key: str):
DIR_OUTPUT = "site"
DIR_DEVICES = join(DIR_OUTPUT, "devices")
DIR_PROFILES = join(DIR_OUTPUT, "profiles")
IMAGES_URL = "https://tuya-cloudcutter.github.io/cloudcutter-data/images"

makedirs(DIR_DEVICES, exist_ok=True)
makedirs(DIR_PROFILES, exist_ok=True)
Expand Down Expand Up @@ -85,6 +86,14 @@ def get_base_profile(profile: dict) -> dict:
# assign default image URL
if device["image_urls"]:
device["image_url"] = device["image_urls"][0]
# prepend local image URLs with repo URL
for i, url in enumerate(device["image_urls"]):
if url.startswith("https://") or url.startswith("http://"):
continue
device["image_urls"][i] = f"{IMAGES_URL}/{url}"
if i == 0:
device["image_url"] = f"{IMAGES_URL}/thumbs/{url}"

# add missing empty lists
put_list(device, "github_issues")
put_list(device, "image_urls")
Expand Down

0 comments on commit a9cb9f8

Please sign in to comment.