1. Go to this page and download the library: Download cassarco/markdown-tools 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/ */
namespace App\Actions;
use Cassarco\MarkdownTools\Contracts\MarkdownFileRules as MarkdownFileRulesContract;
class MarkdownFileRules implements MarkdownFileRulesContract
{
public function __invoke(): array
{
return [
'uuid' => '
namespace App\Actions;
use App\Models\Article;
use Cassarco\MarkdownTools\Contracts\MarkdownFileHandler as MarkdownFileHandlerContract;
use Cassarco\MarkdownTools\MarkdownFile;
use function Laravel\Prompts\info;
class MarkdownFileHandler implements MarkdownFileHandlerContract
{
public function __invoke(MarkdownFile $file): void
{
Article::updateOrCreate([
'uuid' => $file->frontMatter()['uuid'],
], [
'uuid' => $file->frontMatter()['uuid'],
'title' => $file->frontMatter()['title'],
]);
info("Processed: {$file->pathname()}");
}
}
$file->frontMatter() // Front-matter as a PHP array
$file->markdown() // Raw markdown content
$file->html() // HTML without table of contents
$file->toc() // Table of contents HTML
$file->htmlWithToc() // HTML with embedded table of contents
$file->pathname() // File path
namespace App\Actions;
use App\Models\Article;
use Cassarco\MarkdownTools\Contracts\MarkdownFileHandler as MarkdownFileHandlerContract;
use Cassarco\MarkdownTools\MarkdownFile;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use function Laravel\Prompts\info;
class MarkdownFileHandler implements MarkdownFileHandlerContract
{
public function __invoke(MarkdownFile $file): void
{
Article::updateOrCreate([
'uuid' => $file->frontMatter()['uuid'],
], [
'uuid' => $file->frontMatter()['uuid'],
'title' => $file->frontMatter()['title'],
'slug' => $file->frontMatter()['slug'] ?? Str::slug($file->frontMatter()['title']),
'description' => $file->frontMatter()['description'],
'table_of_contents' => $file->toc(),
'content' => $file->html(),
'image' => $file->frontMatter()['image'],
'tags' => collect($file->frontMatter()['tags']),
'published_at' => Carbon::make($file->frontMatter()['published_at']),
'deleted_at' => Carbon::make($file->frontMatter()['deleted_at']),
'created_at' => Carbon::make($file->frontMatter()['created_at']),
'updated_at' => Carbon::make($file->frontMatter()['updated_at']),
]);
info("Processing {$file->frontMatter()['title']}");
}
}