Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app/BlogPosts/TableOfContents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\BlogPosts;
use Illuminate\Support\Str;

class TableOfContents {

public $raw;
public $_toc;
public $_parsedHtml;

public function __construct ($html)
{
$this->raw = $html;
$this->_process();
}

public function toc ()
{
return $this->_toc;
}

public function html ()
{
return $this->_parsedHtml;
}

private function _process ()
{
$this->_toc = [];

$html = preg_replace_callback("/<h([\d])([\w.:=\"\'_\-,;\?\s#\(\)\/]*)>([^<]+)<\/h/", function($matches) {
$id = Str::random(8);
$this->_toc[] = (object) [
'priority' => intval($matches[1]),
'id' => $id,
'text' => $matches[3]
];
return '<h'.$matches[1].$matches[2].' id="'.$id.'">'.$matches[3].'</h';
}, $this->raw);

$this->_parsedHtml = $html;
}
}
18 changes: 16 additions & 2 deletions app/Http/Controllers/Website/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Models\BlogPost;
use Illuminate\Http\Request;
use Spatie\SchemaOrg\Schema;

class BlogController extends Controller
{
Expand All @@ -17,17 +18,30 @@ public function index(): \Illuminate\Contracts\View\View

public function detail(BlogPost $blog): \Illuminate\Contracts\View\View
{
if (! auth()->user()?->emailIsFromCodex()) {
abort_if(! $blog->is_visible, 404);
if (!auth()->user()?->emailIsFromCodex()) {
abort_if(!$blog->is_visible, 404);
}

$blogIds = collect($blog->related_blogs);

$otherBlogs = BlogPost::query()->whereIn('id', $blogIds)->get();

$schema = Schema::blogPosting()
Comment thread
RuliLG marked this conversation as resolved.
->headline($blog->title)
->articleBody($blog->markdown_content)
->author(Schema::person()->name(config('codex.blog_author')))
->datePublished($blog->published_at->toIso8601String())
->dateModified($blog->updated_at->toIso8601String())
->mainEntityOfPage(Schema::webPage()->url(url()->current()))
->publisher(Schema::organization()
->name('CodexAtlas Blog')
->logo(Schema::imageObject()->url(asset('images/logo.png'))))
->image($blog->image_url);

return view('blog.blog-detail', [
'blog' => $blog,
'otherBlogs' => $otherBlogs,
'schema' => $schema,
]);
}
}
9 changes: 9 additions & 0 deletions app/Models/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Models;

use App\BlogPosts\TableOfContents;
use App\Models\Traits\HasUserFeedback;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;

Expand Down Expand Up @@ -105,4 +107,11 @@ public function getTailGraphUrl(): string

return $image;
}

public function transformedContent(): Attribute
{
return Attribute::make(
get: fn () => new TableOfContents(Str::markdown($this->markdown_content))
);
}
}
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"borah/knowledge-base-laravel": "^0.7",
"borahlabs/aws-marketplace-saas-laravel": "^1.0",
"convertkit/convertkitapi": "^1.3",
"diglactic/laravel-breadcrumbs": "^9.0",
"filament/filament": "^3.2",
"filament/forms": "^3.2",
"graham-campbell/bitbucket": "^10.4",
Expand All @@ -30,8 +31,9 @@
"lorisleiva/laravel-actions": "^2.8",
"openai-php/laravel": "^0.8",
"spatie/laravel-sitemap": "^7.2",
"wire-elements/modal": "^2.0",
"spatie/laravel-sluggable": "^3.6"
"spatie/laravel-sluggable": "^3.6",
"spatie/schema-org": "^3.23",
"wire-elements/modal": "^2.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.13",
Expand Down
199 changes: 198 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading