Hopefully this works.

This commit is contained in:
sarah committed 2026-08-19 18:28:34 +02:00
1 parent 3222f5aa99
commit 2c8ccd51db
6 files changed
+318 -47

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
name: Build And Deploy Website
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: Pages
cancel-in-progress: false
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.5"
coverage: none
- name: Configure Pages
uses: actions/configure-pages@v5
- name: Build Website
run: php Build.php
- name: Upload Website
uses: actions/upload-pages-artifact@v4
with:
path: ./_Site
Deploy:
environment:
name: github-pages
url: ${{ steps.Deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: Build
steps:
- name: Deploy Website
id: Deployment
uses: actions/deploy-pages@v4
-43
View File
@@ -1,43 +0,0 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: '.'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5
+235
View File
@@ -0,0 +1,235 @@
<?php
declare(strict_types=1);
$RootDirectory = __DIR__;
$OutputDirectory = $RootDirectory . "/_Site";
$PagesDirectory = $RootDirectory . "/Pages";
function RemoveDirectory(string $Directory): void
{
if (!is_dir($Directory)) {
return;
}
$Iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$Directory,
FilesystemIterator::SKIP_DOTS
),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($Iterator as $Item) {
if ($Item->isDir()) {
rmdir($Item->getPathname());
} else {
unlink($Item->getPathname());
}
}
rmdir($Directory);
}
function CopyDirectory(
string $Source,
string $Destination
): void {
if (!is_dir($Destination)) {
mkdir($Destination, 0777, true);
}
$Iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$Source,
FilesystemIterator::SKIP_DOTS
),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($Iterator as $Item) {
$RelativePath = $Iterator->getSubPathName();
$DestinationPath = $Destination . "/" . $RelativePath;
if ($Item->isDir()) {
if (!is_dir($DestinationPath)) {
mkdir($DestinationPath, 0777, true);
}
continue;
}
copy(
$Item->getPathname(),
$DestinationPath
);
}
}
function RenderPage(
string $SourceFile,
string $DestinationFile,
string $RootPath
): void {
$DestinationDirectory = dirname($DestinationFile);
if (!is_dir($DestinationDirectory)) {
mkdir($DestinationDirectory, 0777, true);
}
ob_start();
try {
require $SourceFile;
$Contents = ob_get_clean();
} catch (Throwable $Exception) {
ob_end_clean();
throw $Exception;
}
if ($Contents === false) {
throw new RuntimeException(
"Failed to render: " . $SourceFile
);
}
file_put_contents(
$DestinationFile,
$Contents
);
}
/*
* Remove the previous build.
*/
RemoveDirectory($OutputDirectory);
mkdir(
$OutputDirectory,
0777,
true
);
/*
* Copy static directories.
*/
$StaticDirectories = [
"Assets",
"Scripts",
"Styles"
];
foreach ($StaticDirectories as $Directory) {
CopyDirectory(
$RootDirectory . "/" . $Directory,
$OutputDirectory . "/" . $Directory
);
}
/*
* Copy index.html.
*/
copy(
$RootDirectory . "/index.html",
$OutputDirectory . "/index.html"
);
/*
* Build PHP pages.
*/
$Iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$PagesDirectory,
FilesystemIterator::SKIP_DOTS
)
);
foreach ($Iterator as $File) {
if (!$File->isFile()) {
continue;
}
if (strtolower($File->getExtension()) !== "php") {
continue;
}
$SourceFile = $File->getPathname();
$RelativePath = substr(
$SourceFile,
strlen($PagesDirectory) + 1
);
$RelativePath = str_replace(
DIRECTORY_SEPARATOR,
"/",
$RelativePath
);
/*
* Anything under Pages/Bits is a partial.
* Do not generate HTML pages from these.
*/
if (str_starts_with($RelativePath, "Bits/")) {
continue;
}
$OutputPath = preg_replace(
"/\.php$/i",
".html",
$RelativePath
);
if ($OutputPath === null) {
throw new RuntimeException(
"Failed to create output path for: " . $SourceFile
);
}
/*
* Pages/Home.html
* RootPath = ../
*
* Pages/Stuff/Page.html
* RootPath = ../../
*/
$Depth = substr_count(
$OutputPath,
"/"
) + 1;
$RootPath = str_repeat(
"../",
$Depth
);
$DestinationFile =
$OutputDirectory .
"/Pages/" .
$OutputPath;
echo "Building Pages/" . $OutputPath . PHP_EOL;
RenderPage(
$SourceFile,
$DestinationFile,
$RootPath
);
}
echo "Build complete." . PHP_EOL;
+15 -3
View File
@@ -1,8 +1,20 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
>
<title>Sarah's garden</title>
<title>
<?= htmlspecialchars(
"SG/" . ($PageTitle ?? "Home"),
ENT_QUOTES,
"UTF-8"
) ?>
</title>
<link rel="stylesheet" href="../../Styles/Style.css">
<link
rel="stylesheet"
href="<?= $RootPath ?>Styles/Style.css"
>
</head>
+7 -1
View File
@@ -1,3 +1,9 @@
<?php
$PageTitle = "Home";
?>
<!DOCTYPE html>
<html lang="en" data-palette="CatppuccinMocha">
@@ -38,7 +44,7 @@
<p>
Speaking of introducing myself, you should probably visit the
<a href="HTML/Sarahtonin.php">page</a> about me.
<a href="./Sarahtonin.html">page</a> about me.
</p>
<h3>Credits</h3>
+6
View File
@@ -1,3 +1,9 @@
<?php
$PageTitle = "Sarahtonin";
?>
<!DOCTYPE html>
<html lang="en" data-palette="CatppuccinMocha">