work on implementing backend for blog posts + markdown rendering

This commit is contained in:
Niisse 2024-03-04 12:04:45 +01:00
parent b4ea38a6f6
commit 403e3d429b
14 changed files with 422 additions and 18 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Models\BlogPost;
use Illuminate\Http\Request;
class HomeController extends Controller
@ -13,7 +14,7 @@ class HomeController extends Controller
*/
public function __construct()
{
$this->middleware('auth');
// $this->middleware('auth');
}
/**
@ -23,6 +24,8 @@ public function __construct()
*/
public function index()
{
return view('home');
return view('home', [
'blogPosts' => BlogPost::all()
]);
}
}

17
app/Models/BlogPost.php Normal file
View File

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class BlogPost extends Model
{
use HasFactory;
protected $fillable = [
'title',
'article',
'location',
];
}

View File

@ -10,7 +10,8 @@
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8",
"laravel/ui": "^4.4"
"laravel/ui": "^4.4",
"spatie/laravel-markdown": "^2.5"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",

262
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "295871ddd192ba35e61a71d0ff6653f3",
"content-hash": "5ec7065cf4cf1a1ba81f8c4d1dfda63c",
"packages": [
{
"name": "brick/math",
@ -3247,6 +3247,266 @@
],
"time": "2023-11-08T05:53:05+00:00"
},
{
"name": "spatie/commonmark-shiki-highlighter",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/commonmark-shiki-highlighter.git",
"reference": "7d7c4f5f1b387bc3144f7757a85eef6820776929"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/commonmark-shiki-highlighter/zipball/7d7c4f5f1b387bc3144f7757a85eef6820776929",
"reference": "7d7c4f5f1b387bc3144f7757a85eef6820776929",
"shasum": ""
},
"require": {
"league/commonmark": "^2.4.2",
"php": "^8.0",
"spatie/shiki-php": "^2.0",
"symfony/process": "^6.0|^7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.19|^v3.49.0",
"phpunit/phpunit": "^9.5",
"spatie/phpunit-snapshot-assertions": "^4.2.7",
"spatie/ray": "^1.28"
},
"type": "commonmark-extension",
"autoload": {
"psr-4": {
"Spatie\\CommonMarkShikiHighlighter\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"role": "Developer"
}
],
"description": "Highlight code blocks with league/commonmark and Shiki",
"homepage": "https://github.com/spatie/commonmark-shiki-highlighter",
"keywords": [
"commonmark-shiki-highlighter",
"spatie"
],
"support": {
"source": "https://github.com/spatie/commonmark-shiki-highlighter/tree/2.3.0"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2024-02-19T09:14:06+00:00"
},
{
"name": "spatie/laravel-markdown",
"version": "2.5.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-markdown.git",
"reference": "76b0d5fe809c61bb4c2208df3f1115a5db0ceb3b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-markdown/zipball/76b0d5fe809c61bb4c2208df3f1115a5db0ceb3b",
"reference": "76b0d5fe809c61bb4c2208df3f1115a5db0ceb3b",
"shasum": ""
},
"require": {
"illuminate/cache": "^9.0|^10.0|^11.0",
"illuminate/contracts": "^9.0|^10.0|^11.0",
"illuminate/support": "^9.0|^10.0|^11.0",
"illuminate/view": "^9.0|^10.0|^11.0",
"league/commonmark": "^2.4.2",
"php": "^8.1",
"spatie/commonmark-shiki-highlighter": "^2.3",
"spatie/laravel-package-tools": "^1.4.3"
},
"require-dev": {
"brianium/paratest": "^6.2",
"nunomaduro/collision": "^5.3|^6.0",
"orchestra/testbench": "^6.15|^7.0|^8.0",
"pestphp/pest": "^1.22",
"phpunit/phpunit": "^9.3",
"spatie/laravel-ray": "^1.23",
"spatie/pest-plugin-snapshots": "^1.1",
"vimeo/psalm": "^4.8"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Spatie\\LaravelMarkdown\\MarkdownServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Spatie\\LaravelMarkdown\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"role": "Developer"
}
],
"description": "A highly configurable markdown renderer and Blade component for Laravel",
"homepage": "https://github.com/spatie/laravel-markdown",
"keywords": [
"Laravel-Markdown",
"laravel",
"spatie"
],
"support": {
"source": "https://github.com/spatie/laravel-markdown/tree/2.5.0"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2024-02-26T14:24:08+00:00"
},
{
"name": "spatie/laravel-package-tools",
"version": "1.16.2",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-package-tools.git",
"reference": "e62eeb1fe8a8a0b2e83227a6c279c8c59f7d3a15"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/e62eeb1fe8a8a0b2e83227a6c279c8c59f7d3a15",
"reference": "e62eeb1fe8a8a0b2e83227a6c279c8c59f7d3a15",
"shasum": ""
},
"require": {
"illuminate/contracts": "^9.28|^10.0|^11.0",
"php": "^8.0"
},
"require-dev": {
"mockery/mockery": "^1.5",
"orchestra/testbench": "^7.7|^8.0",
"pestphp/pest": "^1.22",
"phpunit/phpunit": "^9.5.24",
"spatie/pest-plugin-test-time": "^1.1"
},
"type": "library",
"autoload": {
"psr-4": {
"Spatie\\LaravelPackageTools\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"role": "Developer"
}
],
"description": "Tools for creating Laravel packages",
"homepage": "https://github.com/spatie/laravel-package-tools",
"keywords": [
"laravel-package-tools",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/laravel-package-tools/issues",
"source": "https://github.com/spatie/laravel-package-tools/tree/1.16.2"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2024-01-11T08:43:00+00:00"
},
{
"name": "spatie/shiki-php",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/shiki-php.git",
"reference": "b4bd54222c40b44800aabce0a4382e0c463b5901"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/shiki-php/zipball/b4bd54222c40b44800aabce0a4382e0c463b5901",
"reference": "b4bd54222c40b44800aabce0a4382e0c463b5901",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": "^7.4|^8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^v3.0",
"pestphp/pest": "^1.8",
"phpunit/phpunit": "^9.5",
"spatie/pest-plugin-snapshots": "^1.1",
"spatie/ray": "^1.10"
},
"type": "library",
"autoload": {
"psr-4": {
"Spatie\\ShikiPhp\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Rias Van der Veken",
"email": "rias@spatie.be",
"role": "Developer"
},
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"role": "Developer"
}
],
"description": "Highlight code using Shiki in PHP",
"homepage": "https://github.com/spatie/shiki-php",
"keywords": [
"shiki",
"spatie"
],
"support": {
"source": "https://github.com/spatie/shiki-php/tree/2.0.0"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2024-02-19T09:00:59+00:00"
},
{
"name": "symfony/console",
"version": "v6.4.3",

View File

@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use App\Models\BlogPost;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
class BlogPostFactory extends Factory
{
protected $model = BlogPost::class;
public function definition(): array
{
return [
'title' => $this->faker->word(),
'article' => $this->faker->word(),
'location' => $this->faker->word(),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
];
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('blog_posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->longText('article');
$table->string('location')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('blog_posts');
}
};

View File

@ -3,6 +3,7 @@
namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\BlogPost;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
@ -12,6 +13,21 @@ class DatabaseSeeder extends Seeder
*/
public function run(): void
{
$article = "**Lorem Ipsum** is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
BlogPost::create([
'title' => 'Test Blog Post 1',
'article' => $article,
'location' => null
]);
BlogPost::create([
'title' => 'Blog Post Test 2',
'article' => $article,
'location' => null
]);
// \App\Models\User::factory(10)->create();
// \App\Models\User::factory()->create([

0
laravel Normal file
View File

16
package-lock.json generated
View File

@ -5,7 +5,8 @@
"packages": {
"": {
"dependencies": {
"bootstrap-icons": "^1.11.3"
"bootstrap-icons": "^1.11.3",
"shiki": "^1.1.7"
},
"devDependencies": {
"@popperjs/core": "^2.11.6",
@ -563,6 +564,11 @@
"win32"
]
},
"node_modules/@shikijs/core": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.1.7.tgz",
"integrity": "sha512-gTYLUIuD1UbZp/11qozD3fWpUTuMqPSf3svDMMrL0UmlGU7D9dPw/V1FonwAorCUJBltaaESxq90jrSjQyGixg=="
},
"node_modules/@types/estree": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
@ -1037,6 +1043,14 @@
"node": ">=14.0.0"
}
},
"node_modules/shiki": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/shiki/-/shiki-1.1.7.tgz",
"integrity": "sha512-9kUTMjZtcPH3i7vHunA6EraTPpPOITYTdA5uMrvsJRexktqP0s7P3s9HVK80b4pP42FRVe03D7fT3NmJv2yYhw==",
"dependencies": {
"@shikijs/core": "1.1.7"
}
},
"node_modules/source-map-js": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",

View File

@ -14,6 +14,7 @@
"vite": "^5.0.0"
},
"dependencies": {
"bootstrap-icons": "^1.11.3"
"bootstrap-icons": "^1.11.3",
"shiki": "^1.1.7"
}
}

View File

@ -2,6 +2,6 @@
$body-bg: #ffffff;
// Typography
$font-family-sans-serif: 'nunito', sans-serif;
$font-family-sans-serif: 'Noto Sans', serif;
$font-size-base: 0.9rem;
$line-height-base: 1.6;

View File

@ -1,5 +1,6 @@
// Fonts
@import url('https://fonts.bunny.net/css?family=Nunito');
//@import url('https://fonts.bunny.net/css?family=Nunito');
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap');
@import url('/node_modules/bootstrap-icons/font/bootstrap-icons.css');
// Variables
@ -9,6 +10,7 @@ $font-size-base: 1rem;
// Navbar overrides
$navbar-light-color: var(--bs-blue);
$navbar-light-hover-color: var(--bs-blue);
$nav-link-font-size: 1.1rem;
// Bootstrap
@ -17,7 +19,7 @@ $nav-link-font-size: 1.1rem;
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}

View File

@ -4,13 +4,48 @@
<div class="container">
<div class="row">
<div class="col-md-9 px-4">
@include('home.photo-partial')
@foreach($blogPosts as $post)
@include('home.blog-partial')
<h2 class="mt-3">{{$post->title}}</h2>
@include('home.blog-partial')
<div class="mt-3 pr-2">
<x-markdown>
{{$post->article}}
</x-markdown>
</div>
<div>
<br>
<a href="/">Continue reading...</a>
</div>
@include('home.blog-partial')
<div class="text-secondary mt-3">
<div class="d-inline-flex flex-row gap-3">
<div>
<i class="bi bi-journal-text"></i> Blog Entry
</div>
<div>
<i class="bi bi-calendar-week"></i> {{$post->created_at->format('Y-m-d')}}
</div>
<div>
<i class="bi bi-tags-fill"></i>
<a class="text-secondary" href="/">Tag 1</a>,
<a class="text-secondary" href="/">Tag 2</a>
</div>
</div>
<div class="pt-2">
<hr>
</div>
</div>
@endforeach
{{-- @include('home.photo-partial')--}}
{{-- @include('home.blog-partial')--}}
{{-- @include('home.blog-partial')--}}
{{-- @include('home.blog-partial')--}}
</div>
<div class="col-md-3">

View File

@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;
/*
@ -12,11 +13,9 @@
| be assigned to the "web" middleware group. Make something great!
|
*/
//Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/', function () {
return view('home');
});
Auth::routes();
//Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/', [HomeController::class, 'index'])->name('home');