hn.today

Show HN: I rewrote my website in Swift

sindresorhus.com17 points0 comments
Screenshot of Show HN: I rewrote my website in Swift

Sindre Sorhus rewrote his entire website in Swift, replacing Astro with a small Swift-based framework built on Elementary that emits plain HTML, CSS, and a little JavaScript. Components are Swift structs that read like SwiftUI views, styles are applied as modifiers and compiled into hashed, file-scoped classes, and style variants are enums that autocomplete. The build uses swift-syntax for token-accurate highlighting, RegisteredProperty for animatable custom properties, typed CSS variables, and typed media queries. Interactive behavior is implemented as custom elements with small scripts colocated with their Swift components, and content lives in Markdown files with typed frontmatter generated by Swift macros (@Frontmatter, @NonEmpty, @CalendarDay). The build also pulls App Store data and runs additional checks via swift run website check.

Shifting checks into the compiler catches broken links, bad IDs, mistyped keys, and other issues at build time; warnings fail the build and refactors are safe thanks to autocomplete and renames. Pages are compact - typical blog post ~14 KB compressed, app pages ~29 KB before screenshots - because each page only includes the CSS and JS of the components it uses, there are no web fonts, and images lazy-load; Chrome hover prefetch often makes navigation instant. The approach delivers faster pages, strong accessibility and responsive behavior by default, fewer runtime surprises, and a development experience that feels as pleasant as building apps in Swift. The source is open and the 1999 home page with 81 custom elements demonstrates the system at scale.

Read on sindresorhus.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.