Skip to content

Commit

Permalink
Always initialize empty namespace for collectables
Browse files Browse the repository at this point in the history
Fixes #117
  • Loading branch information
allejo committed Jan 13, 2020
1 parent 667cd26 commit 0430124
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ collections:
folder: _posts
- name: books
folder: _books
- name: empty-collection
folder: _empty-collection

categories:
- features
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions example/_pages/empty-category.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Empty Collection Page
collection: empty-collection
permalink: /empty/%title/
---

{{ this.title }}
1 change: 1 addition & 0 deletions src/allejo/stakx/Manager/CollectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public function parseCollections($collections)
sprintf('/\.(%s)$/', implode('|', $this->markupEngineManager->getSupportedExtensions())),
];

$this->declareTrackingNamespace($collection['name']);
$this->scanTrackableItems($def, [
'namespace' => $collection['name'],
]);
Expand Down
1 change: 1 addition & 0 deletions src/allejo/stakx/Manager/DataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public function parseDataSets($dataSets)
$this->eventDispatcher->dispatch(DatasetDefinitionAdded::NAME, $event);

$def = new FileExplorerDefinition($folder);
$this->declareTrackingNamespace($dataSet['name']);
$this->scanTrackableItems($def, [
'namespace' => $dataSet['name'],
]);
Expand Down
1 change: 1 addition & 0 deletions src/allejo/stakx/Manager/PageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public function trackNewPageView(BasePageView $pageView)
$event = new PageViewAdded($pageView);
$this->eventDispatcher->dispatch(PageViewAdded::NAME, $event);

$this->declareTrackingNamespace($namespace);
$this->addObjectToTracker($pageView, $namespace);
}

Expand Down
13 changes: 13 additions & 0 deletions src/allejo/stakx/Manager/TrackingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ public function refreshItem($filePath)
// Internal object handling
///

/**
* Initialize a namespace that will be tracked.
*
* @param string $namespace
*/
protected function declareTrackingNamespace($namespace)
{
if (!isset($this->trackedItems[$namespace]))
{
$this->trackedItems[$namespace] = [];
}
}

protected function addFileToTracker(File &$file)
{
$this->trackedItemsFlattened[$file->getRelativeFilePath()] = &$file;
Expand Down

0 comments on commit 0430124

Please sign in to comment.