Skip to content

Commit

Permalink
fix(knowledge): Don't add non-public pages
Browse files Browse the repository at this point in the history
  • Loading branch information
zooley committed Aug 8, 2023
1 parent 2b76a00 commit cb1239e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/Modules/Knowledge/Listeners/PageCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ public function subscribe(Dispatcher $events)
* @param GenerateSitemap $event
* @return void
*/
public function handleGenerateSitemap(GenerateSitemap $event)
public function handleGenerateSitemap(GenerateSitemap $event): void
{
$this->pages(0, $event);
}

/**
* Recursively get pages
*
* @param int $parent_id
* @param GenerateSitemap $event
* @return void
*/
private function pages(int $parent_id, GenerateSitemap $event): void
{
$p = (new Page)->getTable();
$a = (new Associations)->getTable();
Expand All @@ -39,11 +51,18 @@ public function handleGenerateSitemap(GenerateSitemap $event)
->join($a, $a . '.page_id', $p . '.id')
->select($p . '.*', $a . '.level', $a . '.lft', $a . '.rgt', $a . '.id AS assoc_id', $a . '.path AS assoc_path')
->where($a . '.state', '=', 1)
->whereIn($a . '.access', [1])
->where($a . '.parent_id', '=', $parent_id)
->orderBy($a . '.lft', 'asc')
->get();

foreach ($options as $page)
{
if ($page->assoc_path == '-separator-')
{
continue;
}

$priority = 0.5;

if ($page->level == 0)
Expand All @@ -66,6 +85,8 @@ public function handleGenerateSitemap(GenerateSitemap $event)
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority($priority)
);

$this->pages($page->assoc_id, $event);
}
}
}
5 changes: 5 additions & 0 deletions app/Modules/Knowledge/Listeners/RouteCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function handleCollectingRoutes(CollectingRoutes $event): void

foreach ($options as $page)
{
if ($page->assoc_path == '-separator-')
{
continue;
}

$indent = str_repeat('|— ', $page->level);

$event->addRoute(
Expand Down

0 comments on commit cb1239e

Please sign in to comment.