1
0

Terms rendering

This commit is contained in:
Richard Dern 2024-04-26 13:47:36 +02:00
parent 588f594869
commit bd928ef3cb
11 changed files with 333 additions and 18 deletions

49
app/Classes/Term.php Normal file
View File

@ -0,0 +1,49 @@
<?php
namespace App\Classes;
use Illuminate\Support\Str;
class Term
{
protected Bundle $bundle;
protected string $slug;
protected Link $link;
protected string $path;
public function __construct(
protected string $term,
protected string $subCategory,
protected Bundle $source
) {
$this->slug = Str::slug($term);
$this->path = sprintf('/termes/%s', $this->slug);
$this->bundle = new Bundle($this->path, $source->getDisk());
$this->link = new Link($this->path, $term, $source);
$currentRelations = $this->bundle->metadata('relations')->get($subCategory, []);
if (!in_array($source->getPath(), $currentRelations)) {
$currentRelations[] = $source->getPath();
$this->bundle->metadata('relations')->set($subCategory, collect($currentRelations)->unique()->toArray());
}
$this->bundle->markdown()->set('');
$this->bundle->metadata()->set('title', $term);
$this->bundle->save();
}
public function render()
{
return (string) $this->link->toHtmlElement();
}
public static function register(string $term, string $subCategory, Bundle $source)
{
return new static($term, $subCategory, $source);
}
}

View File

@ -12,6 +12,7 @@ class BundleRendererServiceProvider extends ServiceProvider
\App\Services\BundleRenderers\Renderers\DossierRenderer::class,
\App\Services\BundleRenderers\Renderers\DateBasedListRenderer::class,
\App\Services\BundleRenderers\Renderers\ProductBasedListRenderer::class,
\App\Services\BundleRenderers\Renderers\TermRenderer::class,
];
/**

View File

@ -0,0 +1,41 @@
<?php
namespace App\Services\BundleRenderers\Renderers;
use App\Classes\Bundle;
class TermRenderer extends BaseRenderer
{
/**
* Renders a complete HTML view of the bundle
*/
public function render()
{
$this->prepareRender();
$relations = [];
foreach ($this->bundle->metadata('relations')->all() as $category => $bundles) {
foreach ($bundles as $path) {
$relations[$category][] = new Bundle($path, $this->bundle->getDisk());
}
}
data_set($this->viewData, 'relations', $relations);
return view('term', $this->viewData);
}
/**
* Return a boolean value indicating if this creator in particular can
* create bundles for specified section
*/
public static function handles(Bundle $bundle): bool
{
return $bundle->getSection() && $bundle->getSection()->getPath() === '/termes/';
}
protected function handlePagination()
{
}
}

View File

@ -94,22 +94,6 @@ #article-main {
}
}
blockquote {
border-left: 4px solid #60a5fa;
padding: 0.5rem 1rem;
margin: 1rem auto;
color: #e4f1fe;
background-color: #021127;
text-align: justify;
max-width: var(--design-width);
width: 100%;
border-radius: .5rem;
p + p {
padding-top: 1rem;
}
}
> h2,
> h3,
> h4,
@ -243,4 +227,64 @@ #article-main {
margin-left: .2rem;
}
}
> footer {
font-size: 1rem;
color: #6c7a89;
background: #01010c radial-gradient(at bottom center, #00101f, #000614, #01010c) no-repeat;
box-shadow: 0 1px 1rem #000;
border-radius: .5rem;
border: solid 2px #00101f;
padding: .5rem 1rem;
margin: 1rem auto;
max-width: var(--design-width);
text-align: center;
line-height: 175%;
aside + aside {
padding-top: 1rem;
}
details {
summary {
text-align: left;
cursor: pointer;
display: block;
}
}
h3 {
color: #fff;
}
.two-columns {
display: grid;
grid-template-columns: 1fr 1fr;
gap: .5rem 1rem;
h4 {
text-align: right;
}
div {
text-align: left;
}
}
}
}
blockquote {
border-left: 4px solid #60a5fa;
padding: 0.5rem 1rem;
margin: 1rem auto;
color: #e4f1fe;
background-color: #021127;
text-align: justify;
max-width: var(--design-width);
width: 100%;
border-radius: .5rem;
p + p {
padding-top: 1rem;
}
}

View File

@ -1,5 +1,5 @@
figure {
width: var(--design-width);
max-width: var(--design-width);
margin: 1rem auto;
img,

View File

@ -5,6 +5,7 @@ body > footer {
nav {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;

View File

@ -52,9 +52,29 @@ class="{!! $mainLink['classes'] !!}"
</section>
@endif
@if(!empty($bundle->virtualMetadata()->all()))
<footer>
@dump($bundle->virtualMetadata()->all())
<details open>
<summary>Informations détaillées</summary>
@if(!empty($bundle->metadata()->get('wikidataEntityId')))
<blockquote>
<p>Les informations complémentaires visibles ici proviennent de
{!! (new \App\Classes\Link('https://www.wikidata.org/wiki/' . $bundle->metadata()->get('wikidataEntityId'), 'Wikidata', $bundle))->toHtmlElement() !!}.
Malgré le soin apporté par la communauté Wikidata à la constitution
de ces données, elles peuvent s'avérer incomplètes et des erreurs
peuvent s'être glissées.</p>
@if(!empty($bundle->metadata('wikidata/entity')->get('modified')))
<p>Dernière mise à jour des données : {{ Carbon\Carbon::parse($bundle->metadata('wikidata/entity')->get('modified'))->isoFormat('LL') }}</p>
@endif
</blockquote>
@endif
@foreach($bundle->virtualMetadata()->all() as $category => $data)
@include('components.asides.generic', compact('category', 'data', 'bundle'))
@endforeach
</details>
</footer>
@endif
</article>
@if (!empty($pagination['items']))

View File

@ -0,0 +1,15 @@
@props(['subCategory', 'items', 'bundle'])
<h4>{!! $subCategory !!}</h4>
<div class="two-columns">
@foreach($items as $people => $data)
<h4>{!! \App\Classes\Term::register($people, 'Distribution', $bundle)->render() !!}</h4>
<div>
@foreach($data as $type => $roles)
@foreach($roles as $role)
<p>{{ $role }}</p>
@endforeach
@endforeach
</div>
@endforeach
</div>

View File

@ -0,0 +1,43 @@
@props(['category', 'data', 'bundle'])
<aside>
<h3>{!! $category !!}</h3>
@foreach($data as $subCategory => $items)
@if($category === 'Liens')
@include('components.asides.links', compact('subCategory', 'items', 'bundle'))
@elseif($category === 'Distribution')
@include('components.asides.distribution', compact('subCategory', 'items', 'bundle'))
@else
<div class="two-columns">
<h4>{!! $subCategory !!}</h4>
<div>
@if(is_string($items) || is_numeric($items))
<p>{{ strval($items) }}</p>
@else
@foreach($items as $key => $item)
@if($category === 'Dates')
@if(is_string($item))
<p>{{ Carbon\Carbon::parse($item)->format('d/m/Y') }}</p>
@else
<p>{{ Carbon\Carbon::parse($key)->format('d/m/Y') }}
@if(!empty($item['Lieu de publication'][0]))
({{ $item['Lieu de publication'][0] }})
@endif
</p>
@endif
@else
@if(is_numeric($item))
<p>{{ strval($item) }}</p>
@elseif(is_string($item))
<p>{!! \App\Classes\Term::register($item, $subCategory, $bundle)->render() !!}</p>
@else
<p>{!! \App\Classes\Term::register($key, $subCategory, $bundle)->render() !!}</p>
@endif
@endif
@endforeach
@endif
</div>
</div>
@endif
@endforeach
</aside>

View File

@ -0,0 +1,29 @@
@props(['subCategory', 'items', 'bundle'])
@php
$index = 0;
@endphp
<div class="two-columns">
<h4>{!! $subCategory !!}</h4>
<div>
@foreach($items as $key => $item)
@if(is_string($item))
@if(Str::contains($item, '://'))
{!! (new \App\Classes\Link($item, '[1]', $bundle))->toHtmlElement() !!}
@else
<p>{{ $item }}</p>
@endif
@else
@php
$index++;
@endphp
@if(Str::contains($key, '://'))
{!! (new \App\Classes\Link($key, '[' . $index . ']', $bundle))->toHtmlElement() !!}
@else
{{ $key }}
@endif
@endif
@endforeach
</div>
</div>

View File

@ -0,0 +1,72 @@
@extends('layouts.main')
@section('main')
<article id="article-main">
<header>
@if (empty($bundle->metadata()->get('hide_title')))
<h1>{{ $articleTitle }}</h1>
@endif
@if (!empty($cover))
{!! $cover !!}
@endif
</header>
@if (!empty($body) || (isset($showToc) && $showToc) || !empty($relations))
<section id="article-body">
@if(isset($showToc) && $showToc)
<details class="drop down">
<summary>Sommaire</summary>
<nav>
@include('components.table-of-contents', ['toc' => $dossier->getDirectChildren()])
</nav>
</details>
@endif
{!! $body !!}
@if (!empty($relations))
@foreach($relations as $category => $bundles)
<h2>{!! $category !!}</h2>
<section class="article-list">@foreach ($bundles as $subBundle){!! $subBundle->renderCard() !!}@endforeach</section>
@endforeach
@endif
@if(isset($showToc) && $showToc)
<details class="drop up">
<summary>Sommaire</summary>
<nav>
@include('components.table-of-contents', ['toc' => $dossier->getDirectChildren()])
</nav>
</details>
@endif
</section>
@endif
@if(!empty($bundle->virtualMetadata()->all()))
<footer>
<details open>
<summary>Informations détaillées</summary>
@if(!empty($bundle->metadata()->get('wikidataEntityId')))
<blockquote>
<p>Les informations complémentaires visibles ici proviennent de
{!! (new \App\Classes\Link('https://www.wikidata.org/wiki/' . $bundle->metadata()->get('wikidataEntityId'), 'Wikidata', $bundle))->toHtmlElement() !!}.
Malgré le soin apporté par la communauté Wikidata à la constitution
de ces données, elles peuvent s'avérer incomplètes et des erreurs
peuvent s'être glissées.</p>
@if(!empty($bundle->metadata('wikidata/entity')->get('modified')))
<p>Dernière mise à jour des données : {{ Carbon\Carbon::parse($bundle->metadata('wikidata/entity')->get('modified'))->isoFormat('LL') }}</p>
@endif
</blockquote>
@endif
@foreach($bundle->virtualMetadata()->all() as $category => $data)
@include('components.asides.generic', compact('category', 'data', 'bundle'))
@endforeach
</details>
</footer>
@endif
</article>
@endsection