Skip to content
Open
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
78 changes: 78 additions & 0 deletions benchmarks/SiteCheckerBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace YiiPress\Benchmarks;

use PhpBench\Attributes\AfterMethods;
use PhpBench\Attributes\BeforeMethods;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;
use PhpBench\Attributes\Warmup;
use YiiPress\Build\SiteChecker;

#[BeforeMethods('setUp')]
#[AfterMethods('tearDown')]
final class SiteCheckerBench
{
private string $outputDir;
private SiteChecker $checker;

public function setUp(): void
{
$this->outputDir = sys_get_temp_dir() . '/yiipress-site-checker-bench-' . uniqid();
mkdir($this->outputDir, 0o755, true);

for ($i = 1; $i <= 100; $i++) {
$dir = $this->outputDir . '/page-' . $i;
mkdir($dir, 0o755, true);
$next = $i === 100 ? 1 : $i + 1;
file_put_contents(
$dir . '/index.html',
'<h1 id="top">Page ' . $i . '</h1>'
. '<a href="../page-' . $next . '/#top">Next</a>'
. '<a href="../page-1/">Home</a>'
. '<img src="../assets/logo.svg">',
);
}

mkdir($this->outputDir . '/assets', 0o755, true);
file_put_contents($this->outputDir . '/assets/logo.svg', '<svg/>');

$this->checker = new SiteChecker();
}

public function tearDown(): void
{
$this->removeDir($this->outputDir);
}

#[Revs(20)]
#[Iterations(3)]
#[Warmup(1)]
public function benchInternalSiteCheck(): void
{
$this->checker->check($this->outputDir);
}

private function removeDir(string $path): void
{
if (!is_dir($path)) {
return;
}

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST,
);
foreach ($iterator as $item) {
if ($item->isDir()) {
rmdir($item->getPathname());
} else {
unlink($item->getPathname());
}
}

rmdir($path);
}
}
6 changes: 6 additions & 0 deletions config/common/di/content-pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use YiiPress\Build\TemplateResolver;
use YiiPress\Build\ThemeRegistry;
use YiiPress\Console\BuildCommand;
use YiiPress\Console\CheckCommand;
use YiiPress\Console\CleanCommand;
use YiiPress\Console\InitCommand;
use YiiPress\Console\NewCommand;
Expand Down Expand Up @@ -63,6 +64,11 @@
'eventDispatcher' => Reference::to(EventDispatcherInterface::class),
],
],
CheckCommand::class => [
'__construct()' => [
'rootPath' => $workingDirectory,
],
],
CleanCommand::class => [
'__construct()' => [
'rootPath' => $workingDirectory,
Expand Down
1 change: 1 addition & 0 deletions config/console/commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

return [
'build' => Console\BuildCommand::class,
'check' => Console\CheckCommand::class,
'clean|clear' => Console\CleanCommand::class,
'init' => Console\InitCommand::class,
'import' => Console\ImportCommand::class,
Expand Down
15 changes: 15 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ The command:

With `--workers=N` (N > 1), entry rendering and writing is parallelized across N forked processes. With `--workers=auto`, YiiPress uses up to the detected worker count and lets page writers clamp back to sequential mode for smaller workloads. Feeds are generated after entry writing and can be split per collection across workers. Sitemap generation remains serial.

## `check`

Checks generated HTML output for broken local links, missing `src` targets, and missing anchor fragments.

```
./yiipress check [--output-dir=output] [--external]
```

**Options:**

- `--output-dir`, `-o` — path to the generated output directory (default: `output`). Absolute or relative to project root.
- `--external` — also validate external `http://` and `https://` links. This performs network requests, so it is opt-in.

Run `build` first, then `check` against the generated output. Local checks are filesystem-only and validate links such as `./guide/`, `/assets/site.css`, and `#heading-id`.

## `serve`

Starts the preview server for local development.
Expand Down
1 change: 1 addition & 0 deletions roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- [x] Smaller static package by removing unused runtime extension dependencies
- [x] Build diagnostics (warn on broken internal links, missing images, invalid front matter)
- [x] `yiipress clean` command — clear build output and caches
- [x] `yiipress check` command — validate generated links and anchors
- [x] Dry run mode for build — show what would be generated without writing files
- [x] No-write build mode for render-vs-filesystem performance diagnostics
- [x] `serve` overlay button to open the current markdown source in a configured editor
Expand Down
14 changes: 14 additions & 0 deletions src/Build/SiteCheckIssue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace YiiPress\Build;

final readonly class SiteCheckIssue
{
public function __construct(
public string $filePath,
public string $target,
public string $message,
) {}
}
Loading
Loading