示例#1
0
 protected function getPageType($page)
 {
     $type = $page->type();
     $typedef = Type::definition($type);
     $type = array_replace_recursive(['name' => $type, 'ext' => 'html', 'content' => ['visible' => true, 'type' => $page->ext() == 'md' ? 'markdown' : 'html'], 'meta' => []], (array) $typedef);
     return $type;
 }
示例#2
0
 /**
  * @return string
  */
 public function layout()
 {
     if (!$this->layout) {
         $typedef = Type::definition($this->type());
         $this->layout = $this->meta('layout', $typedef['layout']);
     }
     return $this->layout;
 }
示例#3
0
 public function createPage()
 {
     $root = $this->app->param('root');
     $meta = $this->app->param('meta', []);
     $root = ltrim($root, '/');
     $meta = array_merge(['title' => '', 'slug' => '', 'type' => 'html'], $meta);
     if (!$meta['title']) {
         return false;
     }
     $meta['slug'] = $this->app->helper('utils')->sluggify($meta['slug'] ? $meta['slug'] : $meta['title']);
     $type = $meta['type'];
     $typedef = Type::definition($type);
     $type = array_replace_recursive(['name' => $type, 'ext' => 'html', 'content' => ['visible' => true, 'type' => isset($typedef, $typedef['ext']) && $typedef['ext'] == 'md' ? 'markdown' : 'html'], 'meta' => []], (array) $typedef);
     $contentfolder = copi::path('content:');
     $pagepath = $contentfolder . ($root == 'home' ? '' : $root . '/' . $meta['slug']) . '/' . 'index.' . ($type['ext'] == 'md' ? 'md' : 'html');
     $time = date('Y-m-d H:i:s', time());
     $content = $this->app->helper('yaml')->toYAML(["uid" => uniqid('pid-'), "type" => $meta['type'], "created" => $time, "modified" => $time, "title" => $meta['title']]) . "\n===\n\n";
     $this->app->helper('fs')->write($pagepath, $content);
     $url = '/' . str_replace([copi::path('site:'), '//'], ['', '/'], $pagepath);
     $page = copi::page($pagepath);
     $this->app->trigger('copilot.createpage', [$page->toArray()]);
     return json_encode(['relpath' => $url]);
 }