23 lines
516 B
PHP
23 lines
516 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace KbAntoraImporter\Antora;
|
|
|
|
final class AntoraParser
|
|
{
|
|
public function pageSlugFromPath(string $path): string
|
|
{
|
|
$name = preg_replace('/\.adoc$/', '', basename($path)) ?: basename($path);
|
|
return 'index' === $name ? '' : sanitize_title($name);
|
|
}
|
|
|
|
public function moduleFromPath(string $path): string
|
|
{
|
|
if (preg_match('#^modules/([^/]+)/#', $path, $matches)) {
|
|
return $matches[1];
|
|
}
|
|
|
|
return 'ROOT';
|
|
}
|
|
}
|