PHP code example of apxcde / markdown-blog

1. Go to this page and download the library: Download apxcde/markdown-blog 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/ */

    

apxcde / markdown-blog example snippets


// config/markdown-blog.php
return [
    'articles_path' => resource_path('markdown/articles'),
    'article_filename' => 'page.md',
    'excerpt_length' => 220,
    'date_format' => 'M j, Y',
    'show_drafts' => env('MARKDOWN_BLOG_SHOW_DRAFTS'),
];

use apxcde\MarkdownBlog\Facades\MarkdownBlog;

$articles = MarkdownBlog::all();
$current = MarkdownBlog::current();
$archived = MarkdownBlog::archived();
$drafts = MarkdownBlog::drafts();
$listed = MarkdownBlog::listed();
$article = MarkdownBlog::findBySlug('infinite-scroll-with-laravel-and-livewire');

use apxcde\MarkdownBlog\MarkdownBlog;

$blog = app(MarkdownBlog::class);

$articles = $blog->all();
$current = $blog->current();
$archived = $blog->archived();
$drafts = $blog->drafts();
$listed = $blog->listed();
$article = $blog->findBySlug('infinite-scroll-with-laravel-and-livewire');
$repository = $blog->repository();

use apxcde\MarkdownBlog\ArticleRepository;

$repository = app(ArticleRepository::class);

$articles = $repository->all();
$article = $repository->findBySlug('infinite-scroll-with-laravel-and-livewire');

use apxcde\MarkdownBlog\Facades\MarkdownBlog;

Route::get('/blog', fn () => view('blog.index', [
    'articles' => MarkdownBlog::listed(),
    'archived' => MarkdownBlog::archived(),
]));

Route::get('/blog/{slug}', function (string $slug) {
    abort_if(! $article = MarkdownBlog::findBySlug($slug), 404);

    return view('blog.show', ['article' => $article]);
});

[
    'slug' => 'infinite-scroll-with-laravel-and-livewire',
    'title' => 'Infinite Scroll with Laravel and Livewire',
    'description' => 'Infinite scrolling is a popular feature for content-heavy pages.',
    'author' => 'Rick Mwamodo',
    'date' => '2024-01-17',
    'formatted_date' => 'Jan 17, 2024',
    'status' => 'archive',
    'content' => 'Article body goes here.',
]
bash
php artisan vendor:publish --tag=markdown-blog-config