PHP code example of rockstarcode / markdb

1. Go to this page and download the library: Download rockstarcode/markdb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rockstarcode / markdb example snippets


$MarkDb = new MarkDB\MarkDB('/path/to/files/','base/path/to/form/relative/slugs');

$slug = 'path/to/some/article'; 

$article = $MarkDb->get($slug); # (object) Article 
   
   $article->slug           # url friendly path that identifies article in MarkDB
   $article->{$property}    # properties extracted from YAML processing of the article
   $article->content()      # processed MarkDown of content of article
   $article->read_time()    # helper to calculate words in article and average read time
   $article->summary()      # Extract certain percentage of content for preview 

$find = $MarkDb->where(['author'=>'Author Name','category'=>'Books Ive Read']);  (Array)[Articles]

foreach($MarkDb->libraries as $library){
     $library->articles     # list of articles within library
     $library->libraries    # list of child libraries
     $library->index        # list of all libraries/articles by slug
     $library->slug         # slug which identifies library
     
}

# .env
MARKDB_PATH=/path/to/blog-cms

# config/app.php
    
    'providers'=>[
        ...
        \MarkDb\Support\Laravel\MarkDBServiceProvider::class,
    ],
    
    'aliases' => [
        ...
        'MarkDb' => \MarkDB\Support\Laravel\MarkDBFacade::class,
    ]

#routes.php
  Route::get('/posts, ['as'=>'posts','uses'=>function($slug){
          
          $markdb= app()->make('markdb');
          
          $articles = $cms->articles( /*optional*/ ['page'=>1, 'limit'=>10]);
           
          return view('index',['articles'=>$articles]); 
           
    }])->where('slug','(.*)');
    
  Route::get('/posts/{slug}', ['as'=>'post','uses'=>function($slug){
        
        $article = \MarkDB::get($slug);
         
        return view('article',['article'=>$article]); 
         
  }])->where('slug','(.*)');