Skip to content

Commit 0f38730

Browse files
committed
Update gh-pages script and adjust HTML header.
1 parent b20a23e commit 0f38730

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

Sources/TSPL/TSPL.docc/TSPL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# ``TSPL``
1+
# The Swift Programming Language
22

33
@Metadata {
4-
@DisplayName("The Swift Programming Language")
4+
@TechnologyRoot
55
}
66

77
@Options(scope: global) {

Sources/TSPL/TSPL.docc/header.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
-->
10+
<header id="header" role="banner">
11+
<div class="container">
12+
<aside style="border-radius: 20px; border: 2px solid goldenrod; background: rgba(230, 241, 69, 0.625); padding: 5px; margin: 5px;">
13+
<h3>Important</h3>
14+
<p>
15+
This is the development version of <em>The Swift Programming Language</em> book.
16+
</p>
17+
<p>
18+
For the current shipping book, see <a href="https://docs.swift.org/swift-book/">swift.org</a>.
19+
To contribute to its development, see the <a href="https://www.swift.org/documentation-workgroup/">Swift Documentation Workgroup</a>.
20+
</p>
21+
</aside>
22+
</div>
23+
</header>

bin/update-book-preview

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for Swift project authors
10+
#
11+
# Updates the GitHub Pages documentation site thats published from the 'docs'
12+
# subdirectory in the 'gh-pages' branch of this repository.
13+
#
14+
# This script should be run by someone with commit access to the 'gh-pages' branch
15+
# at a regular frequency so that the documentation content on the GitHub Pages site
16+
# is up-to-date with the content in this repo.
17+
#
18+
19+
set -eu
20+
21+
# A `realpath` alternative using the default C implementation.
22+
filepath() {
23+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
24+
}
25+
26+
SWIFT_BOOK_ROOT="$(dirname $(dirname $(filepath $0)))"
27+
28+
# Set current directory to the repository root
29+
cd "$SWIFT_BOOK_ROOT"
30+
31+
# Use git worktree to checkout the gh-pages branch of this repository in a gh-pages sub-directory
32+
git fetch
33+
git worktree add --checkout gh-pages origin/gh-pages
34+
35+
# Pretty print DocC JSON output so that it can be consistently diffed between commits
36+
export DOCC_JSON_PRETTYPRINT="YES"
37+
38+
# Generate documentation for TSPL and output it
39+
# to the /docs subdirectory in the gh-pages worktree directory.
40+
export SWIFTPM_ENABLE_COMMAND_PLUGINS=1
41+
swift package \
42+
--allow-writing-to-directory "$SWIFT_BOOK_ROOT/gh-pages/docs" \
43+
generate-documentation \
44+
--target TSPL \
45+
--disable-indexing \
46+
--transform-for-static-hosting \
47+
--experimental-enable-custom-templates \
48+
--hosting-base-path swift-book \
49+
--output-path "$SWIFT_BOOK_ROOT/gh-pages/docs"
50+
51+
# Save the current commit we've just built documentation from in a variable
52+
CURRENT_COMMIT_HASH=`git rev-parse --short HEAD`
53+
54+
# Commit and push our changes to the gh-pages branch
55+
cd gh-pages
56+
git add docs
57+
58+
if [ -n "$(git status --porcelain)" ]; then
59+
echo "Documentation changes found. Commiting the changes to the 'gh-pages' branch and pushing to origin."
60+
git commit -m "Update GitHub Pages documentation site to '$CURRENT_COMMIT_HASH'."
61+
git push origin HEAD:gh-pages
62+
else
63+
# No changes found, nothing to commit.
64+
echo "No documentation changes found."
65+
fi
66+
67+
# Delete the git worktree we created
68+
cd ..
69+
exit
70+
git worktree remove gh-pages

0 commit comments

Comments
 (0)