Skip to content

Commit

Permalink
https://github.com/elmsln/issues/issues/1013
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Aug 26, 2022
1 parent 6a92da6 commit 8d74a29
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions system/backend/php/lib/HAXCMSSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public function newSite(
$siteBasePath,
$name,
$gitDetails,
$domain = null
$domain = null,
$pageSchema = null
) {
// calls must set basePath internally to avoid page association issues
$this->basePath = $siteBasePath;
Expand Down Expand Up @@ -124,7 +125,36 @@ public function newSite(
$this->manifest->metadata->node->fields = new stdClass();
// create an initial page to make sense of what's there
// this will double as saving our location and other updated data
$this->addPage(null, 'Welcome to a new HAXcms site!', 'init');
// accept a schema which can generate an array of pages to start
if ($pageSchema == null) {
$this->addPage(null, 'Welcome to a new HAXcms site!', 'init');
}
else {
// loop through an array and make multiple pages
/*$pageSchema = array(
array(
"parent" => null,
"title" => "Lesson 1",
"template" => "init",
"slug" => "lesson-1"
),
array(
"parent" => null,
"title" => "Lesson 2",
"template" => "default",
"slug" => "lesson-2"
),
array(
"parent" => null,
"title" => "Glossary",
"template" => "glossary",
"slug" => "glossary"
),
);*/
for ($i=0; $i < count($pageSchema); $i++) {
$this->addPage($pageSchema[$i]['parent'], $pageSchema[$i]['title'], $pageSchema[$i]['template'], $pageSchema[$i]['slug']);
}
}
// put this in version control :) :) :)
$git = new Git();
$repo = $git->create($directory . '/' . $tmpname);
Expand Down Expand Up @@ -425,7 +455,7 @@ public function gitSetRemote($gitDetails)
*
* @return $page repesented as JSONOutlineSchemaItem
*/
public function addPage($parent = null, $title = 'New page', $template = "default")
public function addPage($parent = null, $title = 'New page', $template = "default", $slug = 'welcome')
{
// draft an outline schema item
$page = new JSONOutlineSchemaItem();
Expand All @@ -444,7 +474,7 @@ public function addPage($parent = null, $title = 'New page', $template = "defaul
$page->order = count($this->manifest->items);
// location is the html file we just copied and renamed
$page->location = 'pages/' . $page->id . '/index.html';
$page->slug = 'welcome';
$page->slug = $slug;
$page->metadata->created = time();
$page->metadata->updated = time();
$location = $this->directory . '/' .
Expand All @@ -455,6 +485,12 @@ public function addPage($parent = null, $title = 'New page', $template = "defaul
case 'init':
$this->recurseCopy(HAXCMS_ROOT . '/system/boilerplate/page/init', $location);
break;
case 'lesson':
$this->recurseCopy(HAXCMS_ROOT . '/system/boilerplate/page/lesson', $location);
break;
case 'glossary':
$this->recurseCopy(HAXCMS_ROOT . '/system/boilerplate/page/glossary', $location);
break;
default:
$this->recurseCopy(HAXCMS_ROOT . '/system/boilerplate/page/default', $location);
break;
Expand Down

0 comments on commit 8d74a29

Please sign in to comment.