Skip to content
Snippets Groups Projects
Commit 1613261b authored by Mateusz Charytoniuk's avatar Mateusz Charytoniuk
Browse files

chore: stricter static pages types

parent 4c25116d
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Distantmagic\Resonance;
use Distantmagic\Resonance\InputValidatedData\FrontMatter;
use RuntimeException;
use Symfony\Component\Finder\SplFileInfo;
readonly class StaticPage
......@@ -25,12 +26,21 @@ readonly class StaticPage
return mb_strtolower($this->frontMatter->title) <=> mb_strtolower($other->frontMatter->title);
}
/**
* @return non-empty-string
*/
public function getBasename(): string
{
$relativePath = $this->file->getRelativePath();
if (empty($relativePath)) {
return $this->file->getFilenameWithoutExtension();
$filename = $this->file->getFilenameWithoutExtension();
if (empty($filename)) {
throw new RuntimeException('Unable to determine filename');
}
return $filename;
}
return sprintf(
......@@ -40,6 +50,9 @@ readonly class StaticPage
);
}
/**
* @return non-empty-string
*/
public function getHref(): string
{
if ('index' === $this->file->getFilenameWithoutExtension()) {
......@@ -55,6 +68,9 @@ readonly class StaticPage
return '/'.$this->getBasename().'.html';
}
/**
* @return non-empty-string
*/
public function getOutputDirectory(): string
{
return sprintf(
......@@ -64,6 +80,9 @@ readonly class StaticPage
);
}
/**
* @return non-empty-string
*/
public function getOutputPathname(): string
{
return sprintf(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment