A modern website built with Swift using the swift-html library and Vapor web framework.
- 🎨 Type-safe HTML generation
- ✅ Compile-time validation
- 🚀 Fast and modern web framework (Vapor)
- 📦 Easy to extend and transform
- Swift 5.9 or later
- macOS 13.0 or later (for running the server)
- Xcode Command Line Tools
- Clone or navigate to this directory:
cd swift-html-website- Build the project:
swift build- Run the server:
swift run AppThe server will start on http://localhost:8080
/- Home page/about- About page/contact- Contact page
swift-html-website/
├── Package.swift # Swift Package Manager configuration
├── Sources/
│ └── App/
│ └── main.swift # Main server code with routes
└── README.md # This file
This project uses:
- swift-html: A DSL for building type-safe HTML documents in Swift
- Vapor: A powerful web framework for Swift
- swift-html-vapor: Integration between swift-html and Vapor
The HTML is generated using Swift's type system, which means:
- Invalid HTML won't compile
- You get autocomplete and type checking
- You can transform HTML documents programmatically
- No runtime template errors
let html = Node.document(
.html(
.head(
.title("My Page")
),
.body(
.h1("Hello, World!"),
.p("This is a paragraph.")
)
)
)MIT