Skip to content

Commit

Permalink
fix: show-pages build option
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Nov 27, 2024
1 parent ff00d79 commit 3469297
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Command/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
$builder->build($options);
$output->writeln('Done 🎉');

// show built pages as table
if ($input->getOption('show-pages')) {
$pagesAsArray = [];
foreach (
$this->getBuilder()->getPages()->filter(function (\Cecil\Collection\Page\Page $page) {
return $page->getVariable('published');
})->usort(function (\Cecil\Collection\Page\Page $pageA, \Cecil\Collection\Page\Page $pageB) {
return strnatcmp($pageA['language'], $pageB['language']);
}) as $page
) {
/** @var \Cecil\Collection\Page\Page $page */
$pagesAsArray[] = [
$page->getId(),
$page->getVariable('language'),
\sprintf("%s %s", $page->getType(), $page->getType() !== \Cecil\Collection\Page\Type::PAGE->value ? "(" . \count($page->getPages() ?: []) . ")" : ''),
$page->getParent()?->getId(),
$page->isVirtual() ? 'False' : 'true',
$page->getSection(),
$page->isVirtual() ? 'true' : 'false',
];
}
$table = new Table($output);
$table
->setHeaderTitle(\sprintf("Built pages (%s)", \count($pagesAsArray)))
->setHeaders(['ID', 'Lang', 'Type', 'Parent', 'File'])
->setHeaders(['ID', 'Lang', 'Type', 'Section', 'Virtual'])
->setRows($pagesAsArray)
;
$table->setStyle('box')->render();
Expand Down

0 comments on commit 3469297

Please sign in to comment.