How to build static site using Publish

Issue #564

Code

Steps

Step 1: Create executable

1
swift package init --type executable

Step 2: Edit package

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

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

Step 3: Double click Package.swift, Xcode opens that in a generated project
Step 4: Declare website. Go to Sources/main.swift

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import Publish
import Plot
import Ink
import Foundation

struct PumaSwiftWeb: Website {
enum SectionID: String, WebsiteSectionID {
case gettingStarted
case workflow
case tasks
case about
}

struct ItemMetadata: WebsiteItemMetadata {}

var url = URL(string: "https://pumaswift.github.io")!
var name = "Puma Swift"
var description = "Build utilities in pure Swift"
var language: Language { .english }
var imagePath: Path? { "https://avatars2.githubusercontent.com/u/54233247?s=200&v=4" }
}

try PumaSwiftWeb()
.publish(withTheme: .foundation)

Step 5: Create Content folder
Step 6: swift run
Step 7: Copy Output to root and push to GitHub

Comments