Skip to content

Commit

Permalink
Merge pull request #22 from illegalstudio/collection-public-page
Browse files Browse the repository at this point in the history
Collection public page
  • Loading branch information
nahime0 authored Apr 23, 2023
2 parents b011ff1 + c0b99a3 commit 25f0cf1
Show file tree
Hide file tree
Showing 37 changed files with 250 additions and 51 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
- Scrape of external URL for page content type
- Check uniqueness of both the custom and the generated slug

# v0.2.3

**Release date**: 2023-04-23

- Introduced renderer for each type of content
- Introduced public page for collections
- Fixed a bug that allowed to view a content also if it was not published

# v0.2.2

**Release date**: 2023-04-02
Expand Down
1 change: 0 additions & 1 deletion public/build/assets/app-6aff0756.css

This file was deleted.

5 changes: 5 additions & 0 deletions public/build/assets/app-938b9eea.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions public/build/assets/app-955162cc.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/app-f0520beb.css

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions public/build/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"resources/js/app.css": {
"file": "assets/app-6aff0756.css",
"src": "resources/js/app.css"
"resources/css/app.scss": {
"file": "assets/app-f0520beb.css",
"isEntry": true,
"src": "resources/css/app.scss"
},
"resources/js/app.js": {
"css": [
"assets/app-6aff0756.css"
],
"file": "assets/app-955162cc.js",
"file": "assets/app-938b9eea.js",
"isEntry": true,
"src": "resources/js/app.js"
}
Expand Down
2 changes: 0 additions & 2 deletions resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import '../css/app.scss';

/**
* Alpine JS
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
<div class="max-w-xl">
@include('linky::profile.partials.update-profile-information-form')
@include('linky::auth.profile.partials.update-profile-information-form')
</div>
</div>

<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
<div class="max-w-xl">
@include('linky::profile.partials.update-password-form')
@include('linky::auth.profile.partials.update-password-form')
</div>
</div>

<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
<div class="max-w-xl">
@include('linky::profile.partials.delete-user-form')
@include('linky::auth.profile.partials.delete-user-form')
</div>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions resources/views/components/layout.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<html lang="en">
<head>
<title>Linky</title>
<meta name="viewport" content="width=device-width, initial-scale=1">


@vite('resources/js/app.js', 'vendor/linky')
@livewireScripts
{{ Vite::useHotFile(base_path() . '/vendor/illegal/linky/public/hot')->useBuildDirectory('vendor/illegal/linky')->withEntryPoints([ 'resources/css/app.scss' ]) }}
@livewireStyles
</head>
<body>
Expand All @@ -15,5 +14,7 @@
{{ $slot }}
</div>

{{ Vite::useHotFile(base_path() . '/vendor/illegal/linky/public/hot')->useBuildDirectory('vendor/illegal/linky')->withEntryPoints([ 'resources/js/app.js' ]) }}
@livewireScripts
</body>
</html>
12 changes: 12 additions & 0 deletions resources/views/public/collection/_layout.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html lang="en">
<head>
<title>@yield('title', 'Linky')</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

{{ Vite::useHotFile(base_path() . '/vendor/illegal/linky/public/hot')->useBuildDirectory('vendor/illegal/linky')->withEntryPoints([ 'resources/css/app.scss' ]) }}
</head>
<body>
@yield('body')
@vite('resources/js/app.js', 'vendor/illegal/linky')
</body>
</html>
14 changes: 14 additions & 0 deletions resources/views/public/collection/default.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@extends('linky::public.collection._layout')
@section('title')
{{$collection->content->name}}
@endsection
@section('body')
<div class="flex flex-col w-full h-full justify-center gap-4 bg-gray-50">
@foreach($collection->contents as $content )
<a class="w-[360px] max-w-[100%] mx-auto bg-indigo-500 p-4 text-white rounded-md border-indigo-900 border-2 drop-shadow-md hover:bg-indigo-600"
href="/{{ $content->slug }}" target="_blank">
{{ $content->name ?: $content->slug }}
</a>
@endforeach
</div>
@endsection
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Illegal\Linky\Abstracts;
namespace Illegal\Linky\Contracts;

use Illegal\InsideAuth\InsideAuth;
use Illegal\InsideAuth\Models\User;
Expand All @@ -9,7 +9,7 @@
use Illegal\Linky\Services\SlugGenerator;
use Illuminate\Database\Eloquent\Model;

abstract class AbstractRepository
abstract class AbstractContentableRepository
{
/**
* @param SlugGenerator $slugGenerator The slug generator service
Expand Down
18 changes: 18 additions & 0 deletions src/Contracts/AbstractRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Illegal\Linky\Contracts;

use Illegal\Linky\Models\Content;
use Illuminate\Http\Request;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;

/**
* This is the abstract renderer class.
* It should be extended by all renderers.
* A renderer is responsible for rendering a specific content type.
*/
abstract class AbstractRenderer
{
abstract public function handle(Request $request, Content $content): RedirectResponse|Response;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Illegal\Linky\Traits;
namespace Illegal\Linky\Contracts;

use Illegal\Linky\Models\Content;
use Illuminate\Database\Eloquent\Relations\MorphOne;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

namespace Illegal\Linky\Traits\Livewire;

use Illegal\Linky\Models\Contentable\Link;
namespace Illegal\Linky\Contracts\Livewire;

trait Sortable
{
Expand Down
24 changes: 24 additions & 0 deletions src/Enums/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,33 @@

namespace Illegal\Linky\Enums;

use Illegal\Linky\Http\Renderers\AbortRenderer;
use Illegal\Linky\Http\Renderers\CollectionRenderer;
use Illegal\Linky\Http\Renderers\LinkRenderer;
use Illegal\Linky\Http\Renderers\PageRenderer;
use Illegal\Linky\Models\Content;
use Illuminate\Http\Request;

enum ContentType: string
{
case Link = "link";
case Collection = "collection";
case Page = "page";

/**
* Render the content.
* This function will return the rendered content, using the
* appropriate renderer - based on the content type - or abort with a 404 if the content type is not supported.
*/
public function render(Request $request, Content $content)
{
$renderer = match ($this) {
self::Link => LinkRenderer::class,
self::Collection => CollectionRenderer::class,
self::Page => PageRenderer::class,
default => AbortRenderer::class,
};

return (new $renderer)->handle($request, $content);
}
}
17 changes: 8 additions & 9 deletions src/Http/Controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illegal\Linky\Enums\ContentType;
use Illegal\Linky\Models\Content;
use Illegal\Linky\Models\Contentable\Collection;
use Illegal\Linky\Repositories\HitRepository;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\RedirectResponse;
Expand Down Expand Up @@ -32,17 +33,15 @@ public function catchAll(Request $request, string $slug = null)
/**
* If the content is not found, abort with a 404.
*/
if (!$content) {
if (!$content || !$content->public) {
abort(404);
}

switch ($content->type) {
case ContentType::Link:
return Redirect::to($content->contentable->url);
case ContentType::Page:
return Response::make($content->contentable->body);
default:
abort(404);
}
/**
* Use the content type to render the content.
* If the content type is not supported, abort with a 404.
* The content type render function will call the correct renderer.
*/
return $content->type->render($request, $content);
}
}
2 changes: 1 addition & 1 deletion src/Http/Livewire/CollectionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Illegal\Linky\Http\Livewire;

use Exception;
use Illegal\Linky\Contracts\Livewire\Sortable;
use Illegal\Linky\Models\Content;
use Illegal\Linky\Models\Contentable\Collection;
use Illegal\Linky\Repositories\CollectionRepository;
use Illegal\Linky\Traits\Livewire\Sortable;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Livewire/LinkList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Illegal\Linky\Http\Livewire;

use Exception;
use Illegal\Linky\Contracts\Livewire\Sortable;
use Illegal\Linky\Models\Content;
use Illegal\Linky\Models\Contentable\Link;
use Illegal\Linky\Repositories\LinkRepository;
use Illegal\Linky\Traits\Livewire\Sortable;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Livewire/PageList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Illegal\Linky\Http\Livewire;

use Exception;
use Illegal\Linky\Contracts\Livewire\Sortable;
use Illegal\Linky\Models\Content;
use Illegal\Linky\Models\Contentable\Page;
use Illegal\Linky\Repositories\PageRepository;
use Illegal\Linky\Traits\Livewire\Sortable;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
Expand Down
23 changes: 23 additions & 0 deletions src/Http/Renderers/AbortRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Illegal\Linky\Http\Renderers;

use Illegal\Linky\Contracts\AbstractRenderer;
use Illegal\Linky\Models\Content;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

/**
* This is the abort renderer class.
* It is responsible for rendering a 404 page if the
* content type is not supported.
*/
class AbortRenderer extends AbstractRenderer
{

public function handle(Request $request, Content $content): Response|RedirectResponse
{
abort(404);
}
}
23 changes: 23 additions & 0 deletions src/Http/Renderers/CollectionRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Illegal\Linky\Http\Renderers;

use Illegal\Linky\Contracts\AbstractRenderer;
use Illegal\Linky\Models\Content;
use Illegal\Linky\Models\Contentable\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Http\Response as IlluminateResponse;

class CollectionRenderer extends AbstractRenderer
{

public function handle(Request $request, Content $content): IlluminateResponse
{
/** @var Collection $collection */
$collection = $content->contentable;
return Response::make(view('linky::public.collection.default', [
'collection' => $collection,
]));
}
}
21 changes: 21 additions & 0 deletions src/Http/Renderers/LinkRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Illegal\Linky\Http\Renderers;

use Illegal\Linky\Contracts\AbstractRenderer;
use Illegal\Linky\Models\Content;
use Illegal\Linky\Models\Contentable\Link;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;

class LinkRenderer extends AbstractRenderer
{

public function handle(Request $request, Content $content): RedirectResponse
{
/** @var Link $link */
$link = $content->contentable;
return Redirect::to($link->url);
}
}
21 changes: 21 additions & 0 deletions src/Http/Renderers/PageRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Illegal\Linky\Http\Renderers;

use Illegal\Linky\Contracts\AbstractRenderer;
use Illegal\Linky\Models\Content;
use Illegal\Linky\Models\Contentable\Page;
use Illuminate\Http\Request;
use Illuminate\Http\Response as IlluminateResponse;
use Illuminate\Support\Facades\Response;

class PageRenderer extends AbstractRenderer
{

public function handle(Request $request, Content $content): IlluminateResponse
{
/** @var Page $page */
$page = $content->contentable;
return Response::make($page->body);
}
}
8 changes: 8 additions & 0 deletions src/Models/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class Content extends Model
{
use HasPrefix;

/**
* This is just a placeholder, has the name will be set by
* the HasPrefix trait.
*
* @var string The table name.
*/
protected $table = "linky_contents";

/**
* Override the db prefix for this model.
*/
Expand Down
Loading

0 comments on commit 25f0cf1

Please sign in to comment.