Skip to content

feat(home): replace hero image with a real, highlighted code block#878

Merged
yusukebe merged 4 commits into
honojs:mainfrom
martinezharo:feat/hero-code-block
Jun 28, 2026
Merged

feat(home): replace hero image with a real, highlighted code block#878
yusukebe merged 4 commits into
honojs:mainfrom
martinezharo:feat/hero-code-block

Conversation

@martinezharo

Copy link
Copy Markdown
Contributor

Summary

The hero currently shows a static bitmap (public/images/code.webp) of the "Hello Hono" snippet. This PR replaces it with the same snippet rendered as real, syntax‑highlighted text inside a macOS‑style window.

It's highlighted at build time with the site's own Shiki themes (github-light / github-dark) and frozen as static HTML, so there is no client‑side highlighting.

Before / After

Light mode

Before After
image image

Dark mode

Before After
image image

Why

  • Light/dark aware — the old bitmap was dark‑only and looked out of place in light mode (see Before / light). The new block uses --vp-code-block-bg and the github‑light/dark themes, exactly like the docs code blocks.
  • Accessibility — real text: selectable, copyable, scalable with browser zoom, and readable by screen readers, instead of a flat image.
  • Crispness — vector text stays sharp at any zoom / DPI; no bitmap pixelation.
  • No flash / CLS — highlighting happens at build time and ships as static HTML, so there is no client‑side highlighting pass and no layout shift. It also drops the code.webp image request.
  • Responsive — the window is sized in container‑query units (cqw) with an aspect-ratio, so it keeps the original footprint and scales with its width.

Kawaii mode is unchanged

The ?kawaii=true easter egg works exactly as before — same image, same size (510×320) and same position. In normal mode you get the code window; in kawaii mode it is swapped for the kawaii logo via CSS. The toggle script in config.ts is simplified to only set the class before paint (the swap itself is now handled in CSS).

Before (kawaii) After (kawaii)
image image

Notes

  • The snippet is frozen Shiki output; HeroImage.vue documents how to regenerate it if the example ever changes.
  • HeroImage.vue uses v-html with that static, build‑time HTML (no dynamic or user input → no XSS surface); it is done this way to avoid client‑side highlighting and the flash it causes.

Verification

bun install --frozen-lockfile
bun run format
bun run build


Happy to iterate on the design or close this if it doesn't fit the direction you want for the hero. 🙏

Swap the static hero bitmap (code.webp) for a real, syntax-highlighted code
snippet rendered as selectable text inside a macOS-style window.

- Highlighted at build time with the site's own Shiki themes
  (github-light/github-dark) and frozen as static HTML: no client-side
  highlighting, so no flash/CLS.
- Follows light/dark mode and reuses --vp-code-block-bg, matching the docs
  code blocks; no longer a dark-only bitmap.
- Crisp at any DPI and the code is now selectable, copyable and accessible
  to screen readers, unlike the image it replaces.
- Scales with its width (container query units + aspect-ratio) to keep the
  original footprint.
- Kawaii mode is preserved unchanged (same image, size and position); its
  toggle script is simplified to only set the class before paint, with the
  swap now handled in CSS.
Comment thread .vitepress/theme/components/HeroImage.vue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the contrast between the code background and the overall background is too subtle. How about making the background of the code darker?

Image

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.

Sure! I've prepared a few proposals. Happy to apply whichever you prefer.

Here are the options for the code block background in light mode:

Option Preview
1. Darker background (#eff2f5)
Going much darker starts to hurt the syntax-highlight contrast
Captura de pantalla 2026-06-27 002604
2. Keep the current color + add a subtle shadow
(If you like this one, I can make it light-mode-only or apply it to both modes)
Captura de pantalla 2026-06-27 002142
3. Use the same appearance in both light and dark mode, closer to the original screenshot Captura de pantalla 2026-06-27 002814

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@martinezharo

I love "2. Keep the current color + add a subtle shadow"! It's the best. I also want to see the dark-mode pattern.

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.

Glad you like option 2! The shadow version is already committed.
Here's how it looks in dark mode:

Captura de pantalla 2026-06-27 094129

Also, a heads-up: while making these changes I noticed this PR had
introduced a small regression in kawaii mode. The hero
logo had shifted slightly and changed size compared to the original on
mobile and some other devices. I've fixed it in cab9107, and I've
re-checked that it now matches the original across the widths I tested.

Let me know if anything else needs changing.

@yusukebe

Copy link
Copy Markdown
Member

Hey @martinezharo !

Super cool! I added the comments. Please check!

The hero image area now renders from the `home-hero-image` slot
(heroImageSlotExists), so the `hero.image` frontmatter and the
public/images/code.webp bitmap it pointed to are no longer needed.
The hero refactor sized the kawaii logo with max-width:100%, which shrank it
on narrow image columns (tablets, iPad Pro) and top-aligned it below 960px.
Restore the original hero image behaviour: absolutely centered at every
breakpoint with a per-breakpoint max-height as the size limit.
@BlankParticle

Copy link
Copy Markdown
Contributor

very cool!
i recently just made the fix for flashing kawaii mode, this is good 👍

@yusukebe yusukebe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@yusukebe

Copy link
Copy Markdown
Member

@martinezharo

Looks good! This is a great PR in the AI era, when many PRs are sloppy. I'm so glad. Thank you very much!

@yusukebe yusukebe merged commit 77afaab into honojs:main Jun 28, 2026
2 checks passed
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