diff --git a/app/Custom.Dockerfile b/app/Custom.Dockerfile new file mode 100644 index 000000000..9a942fd2c --- /dev/null +++ b/app/Custom.Dockerfile @@ -0,0 +1,12 @@ +FROM phpdocumentor-guides + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /app + +RUN composer require phpdocumentor/guides-code phpdocumentor/guides-theme-bootstrap -W --prefer-dist + +COPY ./packages/guides-search /tmp/guides-search + +RUN composer config repositories.phpdocumentor/guides-search path /tmp/guides-search && \ + composer require phpdocumentor/guides-search:dev-main@dev diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 000000000..59e9758ba --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,72 @@ +FROM php:8.4-cli AS builder + +COPY --from=ghcr.io/php/pie:bin /pie /usr/bin/pie + +RUN export DEBIAN_FRONTEND="noninteractive"; \ + set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + unzip \ + curl \ + ca-certificates \ + build-essential \ + pkg-config \ + libssl-dev \ + libclang-dev \ + llvm-dev; \ + rm -rf /var/lib/apt/lists/* + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH \ + RUST_VERSION=1.82.0 + +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ + sh -s -- -y --profile minimal --default-toolchain ${RUST_VERSION} && \ + chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \ + rustc --version && cargo --version + +RUN pie install jaapio/pagefind:dev-main@dev + +RUN rm -rf /usr/local/cargo/registry /usr/local/cargo/git + +FROM php:8.4-cli AS application + +COPY --from=builder /usr/local/lib/php /usr/local/lib/php + +RUN echo "extension=pagefind" > /usr/local/etc/php/conf.d/pagefind.ini + +RUN export DEBIAN_FRONTEND="noninteractive"; \ + set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + git \ + unzip; \ + rm -rf /var/lib/apt/lists/* + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /app +COPY composer.json composer.json + +RUN composer install --no-dev --optimize-autoloader + +# Production stage +FROM php:8.4-cli AS production + +WORKDIR /app + +COPY --from=builder /usr/local/lib/php /usr/local/lib/php +COPY --from=application /app /app + +RUN export DEBIAN_FRONTEND="noninteractive"; \ + set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + libclang1 libzip-dev; \ + rm -rf /var/lib/apt/lists/* + +RUN echo "extension=pagefind" > /usr/local/etc/php/conf.d/pagefind.ini +RUN docker-php-ext-install zip + +ENTRYPOINT ["php", "/app/vendor/bin/guides"] diff --git a/app/composer.json b/app/composer.json new file mode 100644 index 000000000..7609b091f --- /dev/null +++ b/app/composer.json @@ -0,0 +1,19 @@ +{ + "name": "phpdocumentor/guides-app", + "description": "phpDocumentor Guides CLI Application", + "type": "project", + "require": { + "php": "^8.1", + "ext-pagefind": "*", + "phpdocumentor/guides-cli": "^1.8" + }, + "minimum-stability": "dev", + "prefer-stable": true, + "config": { + "sort-packages": true, + "allow-plugins": { + "composer/package-versions-deprecated": true + } + } +} + diff --git a/packages/guides-search/LICENSE b/packages/guides-search/LICENSE new file mode 100644 index 000000000..aabeb825a --- /dev/null +++ b/packages/guides-search/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2025 Jaap van Otterdijk + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/guides-search/README.rst b/packages/guides-search/README.rst new file mode 100644 index 000000000..38eb7396d --- /dev/null +++ b/packages/guides-search/README.rst @@ -0,0 +1,37 @@ + +.. image:: https://poser.pugx.org/phpdocumentor/guides-theme-bootstrap/require/php + :alt: PHP Version Require + :target: https://packagist.org/packages/phpdocumentor/guides-theme-bootstrap + +.. image:: https://poser.pugx.org/phpdocumentor/guides-theme-bootstrap/v/stable + :alt: Latest Stable Version + :target: https://packagist.org/packages/phpdocumentor/guides-theme-bootstrap + +.. image:: https://poser.pugx.org/phpdocumentor/guides-theme-bootstrap/v/unstable + :alt: Latest Unstable Version + :target: https://packagist.org/packages/phpdocumentor/guides-theme-bootstrap + +.. image:: https://poser.pugx.org/phpdocumentor/guides-theme-bootstrap/d/total + :alt: Total Downloads + :target: https://packagist.org/packages/phpdocumentor/guides-theme-bootstrap + +.. image:: https://poser.pugx.org/phpdocumentor/guides-theme-bootstrap/d/monthly + :alt: Monthly Downloads + :target: https://packagist.org/packages/phpdocumentor/guides-theme-bootstrap + +==================================== +phpDocumentor Guides Bootstrap Theme +==================================== + +This repository is part of `phpDocumentor's Guides library `__, a framework +designed to take hand-written documentation in code repositories and create an AST (abstract syntax tree) from it. +This AST is then fed to a renderer, which produces the desired output, such as HTML. + +The package `phpdocumentor/guides-theme-bootstrap `__ adds +`bootstrap theme `__ to the +phpDocumentor's Guides library. + +:Mono-Repository: https://github.com/phpDocumentor/guides +:Documentation: https://docs.phpdoc.org/components/guides/guides/index.html +:Packagist: https://packagist.org/packages/phpdocumentor/guides-theme-bootstrap +:Contribution: https://github.com/phpDocumentor/guides/tree/main/CONTRIBUTING.rst diff --git a/packages/guides-search/composer.json b/packages/guides-search/composer.json new file mode 100644 index 000000000..56b9e4f5d --- /dev/null +++ b/packages/guides-search/composer.json @@ -0,0 +1,24 @@ +{ + "name": "phpdocumentor/guides-search", + "description": "Search extension for phpDocumentor Guides", + "type": "library", + "license": "MIT", + "homepage": "https://www.phpdoc.org", + "config": { + "sort-packages": true + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Guides\\": "src/" + } + }, + "require": { + "php": "^8.1", + "phpdocumentor/guides": "^1.0 || ^2.0" + }, + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + } +} diff --git a/packages/guides-search/resources/config/guides-search.php b/packages/guides-search/resources/config/guides-search.php new file mode 100644 index 000000000..e97328aff --- /dev/null +++ b/packages/guides-search/resources/config/guides-search.php @@ -0,0 +1,16 @@ +services() + ->set(Indexer::class) + ->tag( + 'event_listener', + ['event' => PostRenderProcess::class, 'method' => 'index'], + ); +}; diff --git a/packages/guides-search/src/Search/DependencyInjection/SearchExtension.php b/packages/guides-search/src/Search/DependencyInjection/SearchExtension.php new file mode 100644 index 000000000..eba1af3f7 --- /dev/null +++ b/packages/guides-search/src/Search/DependencyInjection/SearchExtension.php @@ -0,0 +1,40 @@ +load('guides-search.php'); + } + + public function prepend(ContainerBuilder $container): void + { + } +} diff --git a/packages/guides-search/src/Search/Indexer.php b/packages/guides-search/src/Search/Indexer.php new file mode 100644 index 000000000..e383f4a5a --- /dev/null +++ b/packages/guides-search/src/Search/Indexer.php @@ -0,0 +1,50 @@ +getCommand(); + // Create a configuration + $config = new \Pagefind\ServiceConfig( + true, // keep URL + true, // verbose mode + 'en' // fallback language (optional, defaults to 'en') + ); + + $indexer = new \Pagefind\Indexer($config); + $fileSystem = $command->getDestination(); + + foreach ($fileSystem->listContents($command->getDestinationPath(), true) as $file) + { + if ($file['type'] !== 'file') { + continue; + } + + if (!str_ends_with($file['path'], '.html')) { + continue; + } + + $content = $fileSystem->read($file['path']); + if ($content === false) { + continue; + } + + $indexer->addHtmlFile( + $file['path'], + $file['path'], + $content + ); + } + + foreach ($indexer->getFiles() as $file) { + $fileSystem->put('pagefind/' . $file->getFileName(), $file->getContents()); + } + } +}