Skip to content

Fix broken images in Cloudflare preview builds#1244

Merged
mdlinville merged 2 commits into
mainfrom
fix_images_in_pr_preview
Apr 18, 2025
Merged

Fix broken images in Cloudflare preview builds#1244
mdlinville merged 2 commits into
mainfrom
fix_images_in_pr_preview

Conversation

@mdlinville
Copy link
Copy Markdown
Contributor

@mdlinville mdlinville commented Apr 8, 2025

Moved from #1232

This change updates production.sh to call hugo
differently in Cloudflare environments than otherwise.

  • In Cloudflare, the variable $CF_PAGES_URL tracks the
    base URL of a PR build or the production deploy and needs
    to be part of the hugo command.
  • Locally, this variable is not set so don't try to use it.

To help with debugging, log the environment we are building in.

Tests

  • Local build works, image shows up correctly
  • PR build works, image shows up correctly

@mdlinville mdlinville requested a review from ngrayluna April 8, 2025 22:52
@mdlinville mdlinville requested a review from a team as a code owner April 8, 2025 22:52
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 8, 2025

Deploying docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: a375faa
Status: ✅  Deploy successful!
Preview URL: https://5e73d6ce.docodile.pages.dev
Branch Preview URL: https://fix-images-in-pr-preview.docodile.pages.dev

View logs

@ngrayluna ngrayluna requested a review from johndmulhausen April 9, 2025 17:18
@mdlinville mdlinville enabled auto-merge (squash) April 11, 2025 23:04
Comment thread hugo.yaml Outdated
@@ -1,4 +1,4 @@
baseURL: https://docs.wandb.ai
baseURL: /
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running locally, this makes it so that the link provided in the terminal when doing hugo serve does not work, as it removes the https:// protocol from the string. Must we do it this way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I can work around this. Thanks for noticing it. I'll ping you when it's ready for another look.

This change updates production.sh to call hugo
differently in Cloudflare environments than otherwise.
- In Cloudflare, the variable $CF_PAGES_URL tracks the
  base URL of a PR build or the production deploy and needs
  to be part of the hugo command.
- Locally, this variable is not set so don't try to use it.

To help with debugging, log the environment we are building in.
@mdlinville mdlinville force-pushed the fix_images_in_pr_preview branch 2 times, most recently from c8defcd to cffed63 Compare April 15, 2025 21:23
@github-actions
Copy link
Copy Markdown
Contributor

Images automagically compressed by Calibre's image-actions

Compression reduced images by 15%, saving 7.62 KB.

Filename Before After Improvement Visual comparison
assets/images/USS_Lake_Erie_missile_test.jpg 50.72 KB 43.10 KB -15.0% View diff

439 images did not require optimisation.

Copy link
Copy Markdown
Contributor

@ngrayluna ngrayluna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Don't forget to remove rocket image first!

@mdlinville mdlinville force-pushed the fix_images_in_pr_preview branch from a375faa to 25f86af Compare April 18, 2025 21:12
@mdlinville mdlinville merged commit 00c0eb5 into main Apr 18, 2025
3 checks passed
@mdlinville mdlinville deleted the fix_images_in_pr_preview branch April 18, 2025 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants