Skip to content

Commit 72c2358

Browse files
committed
chore: improve initialise script
1 parent 50b49ad commit 72c2358

File tree

11 files changed

+463
-10
lines changed

11 files changed

+463
-10
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Build and Deploy Static Site
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
build:
14+
runs-on: macos-15
15+
steps:
16+
# Check out the repository code
17+
- uses: actions/checkout@v4
18+
19+
# Set up Swift
20+
- name: Setup Swift
21+
uses: swift-actions/setup-swift@v2
22+
23+
# Cache Swift build artifacts
24+
- name: Cache Swift Build
25+
uses: actions/cache@v4
26+
id: cache-swift-build
27+
with:
28+
path: .build
29+
key: ${{ runner.os }}-swift-build-${{ hashFiles('Package.swift', 'Sources/**') }}
30+
restore-keys: |
31+
${{ runner.os }}-swift-build-
32+
33+
# Build the project
34+
- name: Build
35+
run: swift build -v
36+
if: steps.cache-swift-build.outputs.cache-hit != 'true'
37+
38+
# Cache generated site output
39+
- name: Cache Generated Site
40+
uses: actions/cache@v4
41+
id: cache-site-output
42+
with:
43+
path: .output
44+
key: ${{ runner.os }}-site-output-${{ hashFiles('Sources/**') }}
45+
restore-keys: |
46+
${{ runner.os }}-site-output-
47+
48+
# Run the static site generator
49+
- name: Generate Site
50+
run: swift run Application
51+
if: steps.cache-site-output.outputs.cache-hit != 'true'
52+
53+
# Push to static branch (only on push to main)
54+
- name: Push to static branch
55+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
56+
run: |
57+
git config user.name "GitHub Actions Bot"
58+
git config user.email "actions@github.com"
59+
git checkout -B static
60+
rm -rf ./*
61+
mv .output/* .
62+
rm -rf .output .gitignore .github .build .swift-format
63+
git add .
64+
git commit -m "release: update static site content"
65+
git push origin static --force
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

examples/static/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.build/
3+
.output/
4+
.swiftpm/

examples/static/.swift-format

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"indentation" : {
3+
"spaces" : 4
4+
},
5+
"tabWidth" : 4,
6+
"fileScopedDeclarationPrivacy" : {
7+
"accessLevel" : "private"
8+
},
9+
"spacesAroundRangeFormationOperators" : false,
10+
"indentConditionalCompilationBlocks" : false,
11+
"indentSwitchCaseLabels" : false,
12+
"lineBreakAroundMultilineExpressionChainComponents" : false,
13+
"lineBreakBeforeControlFlowKeywords" : false,
14+
"lineBreakBeforeEachArgument" : true,
15+
"lineBreakBeforeEachGenericRequirement" : true,
16+
"lineLength" : 120,
17+
"maximumBlankLines" : 1,
18+
"respectsExistingLineBreaks" : true,
19+
"prioritizeKeepingFunctionOutputTogether" : true,
20+
"rules" : {
21+
"AllPublicDeclarationsHaveDocumentation" : false,
22+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
23+
"AlwaysUseLowerCamelCase" : false,
24+
"AmbiguousTrailingClosureOverload" : true,
25+
"BeginDocumentationCommentWithOneLineSummary" : false,
26+
"DoNotUseSemicolons" : true,
27+
"DontRepeatTypeInStaticProperties" : true,
28+
"FileScopedDeclarationPrivacy" : true,
29+
"FullyIndirectEnum" : true,
30+
"GroupNumericLiterals" : true,
31+
"IdentifiersMustBeASCII" : true,
32+
"NeverForceUnwrap" : false,
33+
"NeverUseForceTry" : false,
34+
"NeverUseImplicitlyUnwrappedOptionals" : false,
35+
"NoAccessLevelOnExtensionDeclaration" : true,
36+
"NoAssignmentInExpressions" : true,
37+
"NoBlockComments" : true,
38+
"NoCasesWithOnlyFallthrough" : true,
39+
"NoEmptyTrailingClosureParentheses" : true,
40+
"NoLabelsInCasePatterns" : true,
41+
"NoLeadingUnderscores" : false,
42+
"NoParensAroundConditions" : true,
43+
"NoVoidReturnOnFunctionSignature" : true,
44+
"OmitExplicitReturns" : true,
45+
"OneCasePerLine" : true,
46+
"OneVariableDeclarationPerLine" : true,
47+
"OnlyOneTrailingClosureArgument" : true,
48+
"OrderedImports" : true,
49+
"ReplaceForEachWithForLoop" : true,
50+
"ReturnVoidInsteadOfEmptyTuple" : true,
51+
"UseEarlyExits" : false,
52+
"UseExplicitNilCheckInConditions" : false,
53+
"UseLetInEveryBoundCaseVariable" : false,
54+
"UseShorthandTypeNames" : true,
55+
"UseSingleLinePropertyGetter" : false,
56+
"UseSynthesizedInitializer" : false,
57+
"UseTripleSlashForDocumentationComments" : true,
58+
"UseWhereClausesInForLoops" : false,
59+
"ValidateDocumentationComments" : false
60+
}
61+
}

examples/static/Package.resolved

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/static/Package.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// swift-tools-version: 6.1
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "Portfolio",
7+
platforms: [.macOS(.v15)],
8+
dependencies: [
9+
.package(url: "https://github.com/maclong9/web-ui.git", from: "1.0.0")
10+
],
11+
targets: [
12+
.executableTarget(
13+
name: "Application",
14+
dependencies: [
15+
.product(name: "WebUI", package: "web-ui")
16+
],
17+
path: "Sources",
18+
resources: [.process("Public")]
19+
)
20+
]
21+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Foundation
2+
import WebUI
3+
4+
@main
5+
actor Application {
6+
static let metadata = Metadata(
7+
site: "example",
8+
titleSeperator: " | ",
9+
description: "A static website built with Swift and WebUI",
10+
image: "https://placehold.co/600x400/EEE/31343C",
11+
author: "Swift Developer",
12+
keywords: [
13+
"swift", "web development", "static site", "webui",
14+
],
15+
type: .website,
16+
favicons: [
17+
.init("https://fav.farm/🖥", type: "image/svg")
18+
],
19+
)
20+
21+
static let routes = [
22+
Home().document,
23+
About().document,
24+
]
25+
26+
static func main() async {
27+
do {
28+
try Website(
29+
metadata: metadata,
30+
routes: routes,
31+
).build()
32+
} catch {
33+
print("Failed to build application: \(error)")
34+
}
35+
}
36+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import Foundation
2+
import WebUI
3+
4+
struct Layout: HTML {
5+
let children: Children
6+
7+
init(@HTMLBuilder children: @escaping HTMLContentBuilder) {
8+
self.children = Children(content: children)
9+
}
10+
11+
public func render() -> String {
12+
Stack {
13+
Header {
14+
Link(to: "/") { Application.metadata.site! }
15+
.font(size: .xl2)
16+
.font(size: .xl3, on: .md)
17+
.font(decoration: .underline, on: .hover)
18+
Navigation {
19+
for path in Application.routes {
20+
Link(to: "/\(path.path ?? "")") { path.metadata.title ?? "" }
21+
.font(size: .sm)
22+
.font(size: .base, on: .md)
23+
.font(decoration: .underline, on: .hover)
24+
}
25+
}.flex(align: .center).spacing(of: 2, along: .x)
26+
}
27+
.flex(justify: .between, align: .center)
28+
.frame(width: .full, maxWidth: .character(86))
29+
.margins(at: .bottom)
30+
.margins(at: .horizontal, auto: true)
31+
.padding(at: .vertical)
32+
33+
Main {
34+
children.render()
35+
}
36+
.flex(grow: .one)
37+
.font(wrapping: .pretty)
38+
.frame(maxWidth: .character(72))
39+
.margins(at: .horizontal, auto: true)
40+
41+
Footer {
42+
Text {
43+
"© \(Date().formattedYear()) "
44+
Link(to: "/") { Application.metadata.site! }.font(
45+
weight: .normal
46+
)
47+
}.font(size: .sm, color: .neutral(._700, opacity: 0.7))
48+
}
49+
.flex(justify: .center, align: .center)
50+
}
51+
.font(family: "system-ui")
52+
.frame(minHeight: .screen)
53+
.flex(direction: .column)
54+
.padding()
55+
.responsive {
56+
$0.md {
57+
$0.font(size: .lg)
58+
}
59+
}
60+
.render()
61+
}
62+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import WebUI
2+
3+
struct About: HTML {
4+
var document: Document {
5+
.init(
6+
path: "about",
7+
metadata: Metadata(
8+
title: "About",
9+
description: "Learn more about this website and its creator"
10+
),
11+
content: { self }
12+
)
13+
}
14+
15+
func render() -> String {
16+
Layout {
17+
Section {
18+
Heading(.title) {
19+
"About This Site"
20+
}
21+
.font(size: .xl3, weight: .bold)
22+
23+
Text {
24+
"This is the About page of my static website built with WebUI. This page demonstrates how to create multiple pages that share common layout elements but have unique content."
25+
}
26+
27+
Heading(.headline) {
28+
"About the Creator"
29+
}
30+
.font(size: .xl, weight: .bold)
31+
32+
Text {
33+
"I'm a Swift developer who loves building clean, fast websites. This site serves as a demonstration of using Swift for web development."
34+
}
35+
36+
Heading(.headline) {
37+
"Built with WebUI"
38+
}
39+
.font(size: .xl, weight: .bold)
40+
41+
Text {
42+
"WebUI is a Swift library that makes it easy to build static websites using a component-based approach. Key features include:"
43+
}
44+
45+
List(style: .disc) {
46+
Item { "Type-safe HTML generation" }
47+
Item { "Tailwind-inspired styling API" }
48+
Item { "Component reusability" }
49+
Item { "Simple static site generation" }
50+
}.padding()
51+
52+
Link(to: "/") {
53+
"Return to Home Page"
54+
}
55+
.background(color: .blue(._500))
56+
.font(color: .custom("white"))
57+
.padding(EdgeInsets(vertical: 2, horizontal: 4))
58+
.rounded(.md)
59+
}.spacing(of: 4, along: .y)
60+
}.render()
61+
}
62+
}

0 commit comments

Comments
 (0)