diff --git a/.github/workflows/Pages.yml b/.github/workflows/Pages.yml new file mode 100644 index 0000000..41a1120 --- /dev/null +++ b/.github/workflows/Pages.yml @@ -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 diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml deleted file mode 100644 index 460f782..0000000 --- a/.github/workflows/static.yml +++ /dev/null @@ -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 diff --git a/Build.php b/Build.php new file mode 100644 index 0000000..b631e85 --- /dev/null +++ b/Build.php @@ -0,0 +1,235 @@ +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; diff --git a/Pages/Bits/Head.php b/Pages/Bits/Head.php index 055ce3d..c715a5f 100644 --- a/Pages/Bits/Head.php +++ b/Pages/Bits/Head.php @@ -1,8 +1,20 @@
- + -Speaking of introducing myself, you should probably visit the - page about me. + page about me.