Skip to content

Commit

Permalink
Fix bug, API used to hardcode the slug
Browse files Browse the repository at this point in the history
  • Loading branch information
BafS committed Feb 19, 2016
1 parent 978075b commit c3f2862
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Parvula/Core/Model/Mapper/PagesFlatFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,20 @@ public function read($pageUID, $parse = true, $eval = false) {
* @return bool
*/
public function create($page) {
$pagePath = $page->slug . $this->fileExtension;
if (!isset($page->slug)) {
throw new IOException('Page cannot be created. It must have a slug');
}

$fs = new Files($this->folder);

if (!$fs->isWritable()) {
throw new IOException('Page destination folder is not writable');
}

try {
$slug = $page->slug;
$pagePath = $slug . $this->fileExtension;

try {
if ($fs->exists($pagePath)) {
return false;
}
Expand All @@ -133,12 +137,11 @@ public function create($page) {
if (!$fs->write($pagePath, $data)) {
return false;
}

} catch (IOException $e) {
throw new PageException('Page cannot be created');
}

$this->pages[$page->slug] = $page;
$this->pages[$slug] = $page;

return true;
}
Expand Down
8 changes: 7 additions & 1 deletion Parvula/Core/PageRenderer/FlatFilesPageRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ public function render(Page $page) {

$delimiter = $this->delimiterRender . PHP_EOL;

$metaArr = $page->getMeta();
if (isset($metaArr['slug'])) {
// For flat files DB, the slug is the filename thus we don't need the slug
unset($metaArr['slug']);
}

// Create the front matter
$meta = $delimiter;
$meta .= trim($this->metadataParser->encode($page->getMeta()));
$meta .= trim($this->metadataParser->encode($metaArr));
$meta .= PHP_EOL . $delimiter . PHP_EOL;

// Add the content
Expand Down

0 comments on commit c3f2862

Please sign in to comment.