public function register() { $this->app->singleton('markdb', function ($app) { $markdb = new MarkDb(env('MARKDB_PATH')); /** * converts collection of arrays into */ $markdb->setArrayFilter(function ($array, $page, $limit) use($markdb) { return new \Illuminate\Pagination\LengthAwarePaginator(array_slice($markdb->articles, ($page - 1) * $limit, $limit), count($markdb->articles), $limit); }); return $markdb; }); }
/** * @param $str * @return string * creates a slug out of a path without converting / into - */ public static function sluggify($str) { $explode = explode("/", $str); array_walk($explode, function (&$item, $keyi) { $item = MarkDb::to_slug($item); }); return implode('/', $explode); }
public function content() { return MarkDb::markdown($this->content); }
/** * Set library settings based on path or existance of .markdb in directory */ public function settings() { if (is_file($this->path . '/.markdb')) { $attributes = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($this->path . '/.markdb')); $this->attributes = $attributes; foreach ($attributes as $key => $value) { if (empty($this->{$key})) { $this->{$key} = $value; } } } if (!isset($this->slug)) { $this->slug = $this->name; } $this->base = empty($this->base) ? $this->parent() ? $this->parent()->base : false : $this->base; $this->slug = new Slug(MarkDb::sluggify(implode('/', array_filter([$this->parent ? $this->parent->slug : null, $this->slug]))), $this->base); if (!empty($this->date)) { $this->date = \Carbon\Carbon::createFromTimestamp(strtotime($this->date)); } }