Skip to content

WIP: search extension #1237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/Custom.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
72 changes: 72 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 19 additions & 0 deletions app/composer.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}

21 changes: 21 additions & 0 deletions packages/guides-search/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
37 changes: 37 additions & 0 deletions packages/guides-search/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/phpDocumentor/guides>`__, 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 <https://packagist.org/packages/phpdocumentor/guides-theme-bootstrap>`__ adds
`bootstrap theme <https://getbootstrap.com/>`__ 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
24 changes: 24 additions & 0 deletions packages/guides-search/composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
16 changes: 16 additions & 0 deletions packages/guides-search/resources/config/guides-search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use phpDocumentor\Guides\Event\PostRenderProcess;
use phpDocumentor\Guides\Search\Indexer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $container): void {
$container->services()
->set(Indexer::class)
->tag(
'event_listener',
['event' => PostRenderProcess::class, 'method' => 'index'],
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link https://phpdoc.org
*/

namespace phpDocumentor\Guides\Search\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;

use Symfony\Component\EventDispatcher\EventDispatcher;

Check failure on line 22 in packages/guides-search/src/Search/DependencyInjection/SearchExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected 0 lines between same types of use statement, found 1.

Check failure on line 22 in packages/guides-search/src/Search/DependencyInjection/SearchExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Type Symfony\Component\EventDispatcher\EventDispatcher is not used in this file.
use function dirname;

Check failure on line 23 in packages/guides-search/src/Search/DependencyInjection/SearchExtension.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected 1 line between different types of use statement, found 0.

final class SearchExtension extends Extension implements PrependExtensionInterface
{
/** @param mixed[] $configs */
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new PhpFileLoader(
$container,
new FileLocator(dirname(__DIR__, 3) . '/resources/config'),
);
$loader->load('guides-search.php');
}

public function prepend(ContainerBuilder $container): void
{
}
}
50 changes: 50 additions & 0 deletions packages/guides-search/src/Search/Indexer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace phpDocumentor\Guides\Search;

use phpDocumentor\Guides\Event\PostRenderProcess;

final class Indexer
{
public function index(PostRenderProcess $postRenderProcess): void
{
$command = $postRenderProcess->getCommand();
// Create a configuration
$config = new \Pagefind\ServiceConfig(

Check failure on line 15 in packages/guides-search/src/Search/Indexer.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Class \Pagefind\ServiceConfig should not be referenced via a fully qualified name, but via a use statement.
true, // keep URL
true, // verbose mode
'en' // fallback language (optional, defaults to 'en')

Check failure on line 18 in packages/guides-search/src/Search/Indexer.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Multi-line function calls must have a trailing comma after the last parameter.
);

$indexer = new \Pagefind\Indexer($config);
$fileSystem = $command->getDestination();

foreach ($fileSystem->listContents($command->getDestinationPath(), true) as $file)

Check failure on line 24 in packages/guides-search/src/Search/Indexer.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected 1 space after closing parenthesis; found newline
{
if ($file['type'] !== 'file') {
continue;
}

if (!str_ends_with($file['path'], '.html')) {

Check failure on line 30 in packages/guides-search/src/Search/Indexer.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Function str_ends_with() should not be referenced via a fallback global name, but via a use statement.
continue;
}

$content = $fileSystem->read($file['path']);
if ($content === false) {
continue;
}

$indexer->addHtmlFile(
$file['path'],
$file['path'],
$content

Check failure on line 42 in packages/guides-search/src/Search/Indexer.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Multi-line function calls must have a trailing comma after the last parameter.
);
}

foreach ($indexer->getFiles() as $file) {
$fileSystem->put('pagefind/' . $file->getFileName(), $file->getContents());
}
}
}
Loading