Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,27 @@ jobs:
APPWRITE_API_KEY_INIT: ${{ secrets.APPWRITE_API_KEY_INIT }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bun run build
assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Optimize assets
run: CI=true bun run optimize
- name: Check for uncommitted changes
run: |
if ! git diff --exit-code; then
echo "Assets are not optimized! The following changes were detected:"
echo ""
git diff
echo ""
echo "Please run 'bun run optimize' locally and commit the changes."
exit 1
fi
echo "✅ All assets are properly optimized."
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
assets/**/*.optimized
.DS_Store
node_modules
/build
Expand Down
73 changes: 67 additions & 6 deletions scripts/optimize-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,84 @@ function get_relative_path(file) {
}

async function main() {
console.log(
'This script runs for ~5 mins. It runs silently if all files are already optimized.'
);

for (const file of walk_directory(join(__dirname, '../static'))) {
const relative_path = get_relative_path(file);
if (!is_image(file)) continue;
if (exceptions.some((exception) => relative_path.startsWith(exception))) continue;

console.log(relative_path);
const image = sharp(file);
const size_before = (await image.toBuffer()).length;
const meta = await image.metadata();

let meta;
try {
meta = await image.metadata();
} catch (err) {
const msg = `${relative_path} failed: ${err.message}`;
if (Bun.env.CI) {
throw new Error(msg);
}

console.log(msg);
continue;
}

if (Bun.env.CI && (meta.width > 1980 || meta.height > 1980)) {
const msg = `${relative_path} is too large: ${meta.width}x${meta.height}`;
throw new Error(msg);
}

const buffer = await image[meta.format](config[meta.format])
.resize(resize_config)
.toBuffer();
const size_after = buffer.length;

if (size_after >= size_before) continue;
await sharp(buffer).toFile(file + '.optimized');

const file_before = Bun.file(file);
await file_before.arrayBuffer();
const size_before = file_before.size;

const file_after = Bun.file(file + '.optimized');
const file_after_contents = await file_after.arrayBuffer();
const size_after = file_after.size;

await sharp(buffer).toFile(file);
const size_diff = size_before - size_after;
if (size_diff <= 0) {
await Bun.file(file + '.optimized').delete();
continue;
}

const size_diff_percent = size_diff / size_before;
if (size_diff_percent < 0.2) {
await Bun.file(file + '.optimized').delete();
continue;
}

// Atomic rewrite
try {
await Bun.write(file, file_after_contents);
await Bun.file(file + '.optimized').delete();
} catch (error) {
try {
await Bun.file(file + '.optimized').delete();
} catch {
// Silenced
}

throw new Error(`Failed to replace ${relative_path}: ${error.message}`);
}

const diff_verbose = Math.round(size_diff_percent * 100);
console.log(`✅ ${relative_path} has been optimized (-${diff_verbose}%)`);

if (Bun.env.CI) {
console.log(
`Stopping optimization in CI/CD env, as one diff is enough to make test fail`
);
break;
}
}
}

Expand Down
Binary file modified static/email/discord.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/email/x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/avatars/snezhanna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/avatars/steven.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/bgs/building-blocks.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/blog/appwrite-pricing-update/add-ons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/blog/appwrite-pricing-update/one-subscription.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/blog/appwrite-pricing-update/project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/blog/comparing-vibe-coding-tools/bolt.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/blog/comparing-vibe-coding-tools/claude-code.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/blog/comparing-vibe-coding-tools/cursor.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/blog/comparing-vibe-coding-tools/lovable.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/blog/comparing-vibe-coding-tools/windsurf.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/blog/tickets-blog2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/changelog/2024-03-07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/docs/ai/audio-processing-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/docs/ai/audio-processing-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/docs/ai/computer-vision-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/docs/ai/computer-vision-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/docs/ai/natural-language-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/icons/illustrated/light/databases-transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/icons/illustrated/light/functions-transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/testimonials/jonas.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/images/testimonials/xue.webp