Skip to content

Commit

Permalink
Merge pull request #3084 from balena-io/vipulgupta2048/build-webp
Browse files Browse the repository at this point in the history
Convert images on deploy time instead at pre-commit
  • Loading branch information
flowzone-app[bot] authored Oct 16, 2024
2 parents 86ae640 + 80d95f9 commit c05749a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 28 deletions.
1 change: 1 addition & 0 deletions .cspell/computer-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ cpuset
createapikey
crossbuilding
cssesc
cwebp
CUDA
Customboard
decamelize
Expand Down
1 change: 0 additions & 1 deletion .husky/pre-commit

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ One can open or check existing issues on [GitHub issues](https://github.com/bale

## Deploying

Shortly after merging a PR to the `master` branch, Flowzone will run on the deploy script `npm run deploy-docs` on master branch and deploy the docs on [balenacloud-docs.pages.dev](https://balenacloud-docs.pages.dev).
Shortly after merging a PR to the `master` branch, Flowzone will run on the deploy script on the master branch and deploy the docs on [balenacloud-docs.pages.dev](https://balenacloud-docs.pages.dev). The deploy script needs to install `cwebp` to convert images to webp format. At the moment, this command is only available to be run on Linux.

The docs are hosted on Cloudflare Pages as a static site.

Expand Down
12 changes: 11 additions & 1 deletion config/redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,20 @@

# Important: keep dynamic redirect below the static redirects
# https://developers.cloudflare.com/pages/platform/redirects/
# Dynamic redirects

# BREAKING - Redirect all image formats to webp
# All images must be served in webp format
# The build script converts images during build time.

/img/*.png/ /img/:splat.webp
/img/*.png /img/:splat.webp
/img/*.jpg/ /img/:splat.webp
/img/*.jpg /img/:splat.webp
/img/*.jpeg/ /img/:splat.webp
/img/*.jpeg /img/:splat.webp

# Dynamic redirects

/deployment/network/:version/ /reference/OS/network/
/deployment/network/:version /reference/OS/network/
/understanding/understanding-devices/:version/ /reference/OS/overview/
Expand Down
16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
"test:spelling": "cspell lint --gitignore -c cspell.json",
"build": "./tools/fetch-external.sh && npm run build:fast",
"build:fast": "./tools/build.sh && webpack --mode production && ./tools/deploy-static-page.sh",
"deploy-docs": "npm ci && npm run build",
"deploy-docs": "sudo apt install webp && npm ci && npm run build",
"watch-pages": "watch ./tools/build.sh pages shared templates config",
"watch-assets": "webpack --mode=development -w",
"watch": "npm run watch-pages & npm run watch-assets",
"prepare": "husky"
"watch": "npm run watch-pages & npm run watch-assets"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -48,7 +47,6 @@
"cspell": "^8.9.1",
"css-loader": "5.2.7",
"file-loader": "6.2.0",
"husky": "^9.1.4",
"mini-css-extract-plugin": "^1.6.2",
"node-html-markdown": "^1.3.0",
"node-jq": "^4.4.0",
Expand Down
3 changes: 3 additions & 0 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ node ./tools/generate-docs-contracts.js
# Generate base images docs
./tools/build-base-images.sh

# Convert .jpg, .jpeg, .png images to .webp format
./tools/convert-images-to-webp.sh

# run cd in a subshell so we don't end up in another directory on failure
(
cd "$SCRIPT_DIR/.."
Expand Down
10 changes: 5 additions & 5 deletions tools/convert-images-to-webp.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash

# One time script to convert all jpeg, jpg, png image to webp format
# Script to convert all jpeg, jpg, png image to webp format in the docs
# Run the script from the docs root directory to convert all image files in the IMAGE_DIR folder

# Define the directory containing the images
IMAGE_DIR="./static/img"

# Check if cwebp is installed
if ! command -v cwebp &> /dev/null; then
echo "Error: cwebp is not installed. Please install and try again."
exit 1
# Exit 0 if cwebp is not installed
if ! command -v cwebp >/dev/null 2>&1; then
echo "Warning: cwebp is not installed. Can't convert existing images to Webp format. Please install cwebp to use this script."
exit 0
fi

# Find all .jpg, .jpeg, .png files in the directory and its subdirectories
Expand Down

0 comments on commit c05749a

Please sign in to comment.