SwiftyNotes is a website, built using the Swift programming language, to provide quick idiomatic tips on the Swift language—aka writing Swifty code (yes, Swifty is a real term used). This repo contains the code that powers the website.
I've learned so much from the Swift community. My hope is to give a little back with this project.
Contributions of any kind are most welcome. Even feel free to contribute a new tip 🤓.
To test out the SwiftyNotes website locally
- Open terminal
- Clone this repo
git clone https://github.com/jasonzurita/swiftynotes
- Change directories to the cloned project
cd <path>/swiftynotes
- Generate the website
swift run
- Open the generated website in your browser
open _site/index.html
That's it 🥳. Make changes to the site, do a swift run
, and refresh your browser!
There are two main Swift modules in this repo: the website, and the HTML eDSL.
The HTML embedded domain specific language (eDSL) was build using Swift's Result Builders to be SwiftUI like in its syntax (with a little work, this library can be made public for other websites!). Knowing about HTML will help in knowing the provided elements like body and what styles to use.
Example from the SwiftyNotes site:
Html {
Head(title: "SwiftyNotes", cssStyleFileName: "CodeColors.css")
Body {
SiteHeader()
SiteNotes()
Footer {
P("Jason Zurita © 2023 | Built in Swift and ") {
A(copy: "open source.", url: "https://github.com/jasonzurita/swiftynotes")
}
}
.textAlign(.center)
.color(.mediumGray)
}
.font(.apple)
.textAlign(.center)
.background(.color(.lightGray))
.margin(0)
.padding(0)
}
This module consumes the above HTML eDSL module. The result is a fully Swift defined site along with styling. When swift run
is invoked, this module runs as an executable and generates HTML that is ready to be statically hosted and consumed by browsers.
The website is hosted on CloudFlare pages as a static website. When a new commit is pushed to the main branch, CloudFlare runs a swift run
and takes the output generated HTML and hosts it. Pretty much that simple.