Static Site Generation with Swift using Publish, Plot and Ink

By the end of this tutorial, you will be able to create static websites generated with Swift using Publish, Plot and Ink.

Static Site Generation with Swift using Publish, Plot and Ink

I have been using Publish, a static site generator for Swift developers, by John Sundell, in recent months to generate JavaScript-free websites with just HTML and CSS from Markdown files. Publish uses Ink, a Markdown parser written in Swift, and Plot, a domain-specific language (DSL) for writing type-safe HTML, XML, and RSS in Swift, which was recently updated to build HTML components in a more SwiftUI like fashion.

Publish is provided as a Swift package and can be used with the Swift Package Manager by adding the package as a dependency within the Package.swift manifest:

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/johnsundell/publish.git", from: "0.1.0")
    ],
    ...
)

However, the easiest way to get started is using the command-line tool to set up new projects and deploy websites. To use the command-line tool, clone the Publish repository and run make in the local folder of the repository:

$ git clone https://github.com/JohnSundell/Publish.git
$ cd Publish
$ make

The command publish help provides instructions on how to use it. The basic publish new command will create a new project at the current location, which can then be edited in Xcode using the open Package.swift command.

$ mkdir AmazingWebsite
$ cd AmazingWebsite
$ publish new
main.swift

Now, let's have a closer look at how it works in detail. Become a free member or log in to proceed.