diff --git a/.github/workflows/deploy-gh-pages.yml b/.github/workflows/deploy-gh-pages.yml new file mode 100644 index 0000000..36a9cb2 --- /dev/null +++ b/.github/workflows/deploy-gh-pages.yml @@ -0,0 +1,61 @@ +name: Deploy to GitHub pages + +on: + push: + branches: [ "master" ] + workflow_dispatch: + +# 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: "gh-pages" + cancel-in-progress: false + +permissions: {} + +jobs: + build: + name: Build site + runs-on: ubuntu-latest + if: github.repository_owner == 'silverstripe' + permissions: + contents: read + steps: + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup GH pages + id: pages + uses: actions/configure-pages@v5 + + - name: Build static files + shell: bash + run: | + composer install + ./makedoc.sh + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: "htdocs/" + + deploy: + name: Deploy site + needs: build + runs-on: ubuntu-latest + if: github.repository_owner == 'silverstripe' + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{steps.deployment.outputs.page_url}} + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/conf/doctum.json b/conf/doctum.json index bf9d5c6..33f8eb9 100644 --- a/conf/doctum.json +++ b/conf/doctum.json @@ -8,6 +8,7 @@ "4": "4.x", "3": "3.x" }, + "default_version": "5", "paths": { "www": "htdocs", "cache": "data/cache", diff --git a/conf/doctum.php b/conf/doctum.php index 7051914..e16a1a7 100644 --- a/conf/doctum.php +++ b/conf/doctum.php @@ -2,13 +2,13 @@ use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; -use Doctum\Project; use Doctum\Doctum; use SilverStripe\ApiDocs\Data\ApiJsonStore; use SilverStripe\ApiDocs\Data\Config; use SilverStripe\ApiDocs\Inspections\RecipeFinder; use SilverStripe\ApiDocs\Inspections\RecipeVersionCollection; use SilverStripe\ApiDocs\RemoteRepository\SilverStripeRemoteRepository; +use SilverStripe\ApiDocs\SilverstripeProject; // Get config $config = Config::getConfig(); @@ -70,7 +70,7 @@ // Override project unset($doctum['project']); $doctum['project'] = function ($sc) { - $project = new Project($sc['store'], $sc['_versions'], array( + $project = new SilverstripeProject($sc['store'], $sc['_versions'], array( 'build_dir' => $sc['build_dir'], 'cache_dir' => $sc['cache_dir'], 'remote_repository' => $sc['remote_repository'], @@ -82,6 +82,7 @@ 'source_dir' => $sc['source_dir'], 'insert_todos' => $sc['insert_todos'], 'base_url' => $sc['base_url'], + 'favicon' => 'favicon.ico', 'footer_link' => [ 'href' => 'https://github.com/silverstripe/api.silverstripe.org', 'rel' => 'noreferrer noopener', diff --git a/conf/themes/silverstripe/404.twig b/conf/themes/silverstripe/404.twig new file mode 100644 index 0000000..812e919 --- /dev/null +++ b/conf/themes/silverstripe/404.twig @@ -0,0 +1,40 @@ + + + + {# NOTE: Do not put this file into the manifest.yml, as that would render it per version rather than in the base dir #} + Not Found | {{ project.config('title') }} + + + + {% if project.config('favicon') %} + + {%- endif %} + + + + +
+
+
+

Whoa 404, either we broke something or you had a typing mishap :-/

+

Let's go back home.

+
+
+ + diff --git a/errors/error-styles.css b/conf/themes/silverstripe/css/error-styles.css similarity index 88% rename from errors/error-styles.css rename to conf/themes/silverstripe/css/error-styles.css index ca56053..a46eb4b 100644 --- a/errors/error-styles.css +++ b/conf/themes/silverstripe/css/error-styles.css @@ -1,5 +1,5 @@ .gif_holder { - background-image: url('https://www.silverstripe.com/themes/ssv3/img/banners/page-not-found.gif'); + background-image: url('/images/page-not-found.gif'); position: relative; z-index: 807; -webkit-background-size: cover; @@ -52,5 +52,5 @@ a:hover { body { padding: 0; - margin: 0;" -} \ No newline at end of file + margin: 0; +} diff --git a/conf/themes/silverstripe/images/favicon.ico b/conf/themes/silverstripe/images/favicon.ico new file mode 100644 index 0000000..f5d53b6 Binary files /dev/null and b/conf/themes/silverstripe/images/favicon.ico differ diff --git a/conf/themes/silverstripe/images/page-not-found.gif b/conf/themes/silverstripe/images/page-not-found.gif new file mode 100644 index 0000000..ebd084b Binary files /dev/null and b/conf/themes/silverstripe/images/page-not-found.gif differ diff --git a/conf/themes/silverstripe/main_index.twig b/conf/themes/silverstripe/main_index.twig new file mode 100644 index 0000000..a498649 --- /dev/null +++ b/conf/themes/silverstripe/main_index.twig @@ -0,0 +1,16 @@ + + + + {# NOTE: Do not put this file into the manifest.yml, as that would render it per version rather than as the main index file #} + Redirecting... + + + + {% if project.config('favicon') %} + + {%- endif %} + + +

Redirecting... if you aren't redirected automatically, click here

+ + diff --git a/conf/themes/silverstripe/main_search.twig b/conf/themes/silverstripe/main_search.twig new file mode 100644 index 0000000..d819029 --- /dev/null +++ b/conf/themes/silverstripe/main_search.twig @@ -0,0 +1,68 @@ + + + + {# NOTE: Do not put this file into the manifest.yml, as that would render it per version rather than in the base dir #} + Redirecting... + + + {% if project.config('favicon') %} + + {%- endif %} + + + + {# Fall back to just sending users to the default search page if the redirect fails for some reason #} +

Redirecting... if you aren't redirected automatically, click here

+ + diff --git a/conf/themes/silverstripe/manifest.yml b/conf/themes/silverstripe/manifest.yml index 1ddacca..05c8267 100644 --- a/conf/themes/silverstripe/manifest.yml +++ b/conf/themes/silverstripe/manifest.yml @@ -1,6 +1,11 @@ name: silverstripe parent: default +static: + 'images/favicon.ico': 'favicon.ico' + 'images/page-not-found.gif': 'images/page-not-found.gif' + 'css/error-styles.css': 'css/error-styles.css' + global: 'doctum.js.twig': 'doctum.js' diff --git a/errors/404.html b/errors/404.html deleted file mode 100644 index 92bab30..0000000 --- a/errors/404.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - Page not found » SilverStripe API docs - - - -
-
-
-

Whoa 404, either we broke something or you had a typing mishap :-/

-

Let's go back home.

-
-
- - diff --git a/src/SilverstripeProject.php b/src/SilverstripeProject.php new file mode 100644 index 0000000..5214b79 --- /dev/null +++ b/src/SilverstripeProject.php @@ -0,0 +1,47 @@ +renderMainPages(); + } + + public function render($callback = null, $force = false): void + { + parent::render($callback, $force); + $this->renderMainPages(); + } + + /** + * Renders pages that are not version dependent such as the main index.html + */ + private function renderMainPages() + { + $this->version = ''; + $this->initialize(); + $config = Config::getConfig(); + $variables = [ + // Get array of strings of major version numbers + 'versions' => array_map(fn($version) => (string)$version, array_keys($config['versions'])), + 'default_version' => $config['default_version'], + ]; + $this->renderer->save($this, 'index.html', 'main_index.twig', $variables); + $this->renderer->save($this, 'search.html', 'main_search.twig', $variables); + $this->renderer->save($this, '404.html', '404.twig', $variables); + } + + protected function replaceVars(string $pattern): string + { + if (!$this->version) { + $pattern = str_replace('%version%/', '', $pattern); + } + return parent::replaceVars($pattern); + } +}