Commit c2630ba7 authored by Tobias Buckdahn's avatar Tobias Buckdahn

Generate part pages

parent 2dcce0a2
......@@ -6,4 +6,6 @@ data/form-files/**
data/tntsearch/**
pages/images/tax-part/**
!pages/images/tax-part/dummy.md
!pages/images/tax-part/.gitkeep
\ No newline at end of file
!pages/images/tax-part/.gitkeep
pages/23.part/**
!pages/23.part/dummy.md
\ No newline at end of file
---
title: Dummy
published: false
tntsearch:
index: false
sitemap:
ignore: true
---
\ No newline at end of file
......@@ -5,6 +5,7 @@ use Grav\Common\Grav;
use Grav\Common\Plugin;
use Grav\Common\Uri;
use Grav\Plugin\BrickCamp\Techs;
use Grav\Plugin\BrickCamp\Terms;
use Grav\Plugin\BrickCamp\TermsTwigExtension;
use RocketTheme\Toolbox\Event\Event;
......@@ -45,6 +46,7 @@ class BrickCampPlugin extends Plugin
'onFormInitialized' => ['onFormInitialized', 0],
// 'onFormProcessed' => ['onFormProcessed', 0],
'onPageProcessed' => ['onPageProcessed', 0],
'onPagesInitialized' => ['onPagesInitialized', 0],
'onCollectionProcessed' => ['onCollectionProcessed', 0],
]);
}
......@@ -81,6 +83,11 @@ class BrickCampPlugin extends Plugin
}
}
public function onPagesInitialized(Event $event)
{
Terms::initTermPages('part', '/part');
}
/**
* Edit collections based on URI
*
......
......@@ -2,6 +2,7 @@
namespace Grav\Plugin\BrickCamp;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
abstract class Terms
{
......@@ -108,4 +109,38 @@ abstract class Terms
return ucwords($term);
}
}
public static function initTermPages($taxonomy, $parent) {
$pages = Grav::instance()['pages'];
$path = $pages->find($parent)->path();
$terms = self::get($taxonomy);
foreach ($terms as $term) {
// check whether term page already exists
$route = $parent . '/' . $term;
$page = $pages->find($route);
if ($page) {
continue;
}
// create file for page
$page = new Page;
$page->filePath($path . DIRECTORY_SEPARATOR . $term . DIRECTORY_SEPARATOR . 'collection.md');
$page->header( array(
'title' => self::getTitle($taxonomy, $term),
'icon' => self::getImage($taxonomy, $term)->path(),
'content' => array(
'items' => array(
'@taxonomy.' . $taxonomy => $term
),
'limit' => 12,
'pagination' => true
)
));
// add to pages
$pages->addPage($page, $route);
$page->save();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment