Swiftpack.co - swiftysites/swiftysites as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by swiftysites.
swiftysites/swiftysites 2.0.0
Generate static sites from Markdown using Swift
⭐️ 1
🕓 3 days ago
.package(url: "https://github.com/swiftysites/swiftysites.git", from: "2.0.0")


Generate static sites from Markdown using Swift.

Getting Started

Start by creating a folder for your site.

mkdir MySite
cd MySite

Initialize as an executable Swift Package.

swift package init --type executable

Edit your package.swift to first set macOS 11 as the platform and to add SwiftySites as a dependency to both package and target.

let package = Package(
    name: "MySite",
    platforms: [.macOS(.v11)],
    dependencies: [
        .package(url: "https://github.com/swiftysites/swiftysites.git", from: "1.0.0-beta.1")
    targets: [
            name: "MySite",
            dependencies: [.product(name: "SwiftySites", package: "swiftysites")]),

Populate your site with some content.

cat >> Sources/MySite/home.swift << EOF
import Foundation
import SwiftySites

let homePage = Page(
    file: URL(fileURLWithPath: "/"),
    title: "Home Page",
    markdown: """
    # Welcome
    This is the Home Page.

And some templates.

cat >> Sources/MySite/homeTemplate.swift << EOF
import SwiftySites

let homeTemplate = BasicSite.templateA(match: #"/"#, suffix: "html") { site, page in

To tie it all together, let's define the site itself in main.swift.

rm Sources/MySite/main.swift

cat >> Sources/MySite/main.swift << EOF
import SwiftySites

    SiteConfig(title: "My Site"),
    contentA: [homePage],
    templates: [homeTemplate]

Tip: Check out the Samples folder for more examples on how to write and organize your content files.

Finally build and run your executable to generate your static site!

swift run

All the generated files will be in the www folder.

Spin up a web server to publish your static site locally.

python -m http.server --directory www

Direct your browser to http://localhost:8000/index.html to see your site.


Generate DocC

Use the following command:

swift package --allow-writing-to-directory [output-directory-path] \ 
    generate-documentation --target [target-name] --disable-indexing \
    --output-path [output-directory-path] \
    --transform-for-static-hosting \
    --hosting-base-path [hosting-base-path]


Stars: 1
Last commit: 3 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics