design article title and add author virtual page

This commit is contained in:
isUnknown 2024-03-09 16:34:09 +01:00
parent 6fe73efbcf
commit 2114fbbb8e
12 changed files with 129 additions and 25 deletions

View file

@ -7,6 +7,7 @@ columns:
- width: 1/3
sections:
texts:
label: Textes
type: pages
templates:
- linear

View file

@ -3,12 +3,6 @@ description: Un administrateur a tous les droits.
image:
icon: star-filled
columns:
- width: 1/2
fields:
link:
label: Lien
- width: 1/2
fields:
presentation:
type: writer
fields:
presentation:
type: writer

View file

@ -19,12 +19,6 @@ permissions:
users:
*: false
columns:
- width: 1/2
fields:
link:
label: Lien
- width: 1/2
fields:
presentation:
type: writer
fields:
presentation:
type: writer

View file

@ -1,5 +1,7 @@
<?php
use Kirby\Uuid\Uuid;
return [
'debug' => true,
'panel' => [
@ -44,5 +46,25 @@ return [
'comments',
'system'
]
]
],
'routes' => [
[
'pattern' => 'auteur/(:any)',
'action' => function ($slug) {
$kirby = kirby();
$author = getAuthorBySlug($slug);
return Page::factory([
'slug' => '',
'template' => 'author',
'model' => 'authors',
'content' => [
'title' => $author->name(),
'presentation' => $author->presentation(),
'uuid' => Uuid::generate(),
]
]);
}
]
]
];

View file

@ -0,0 +1,37 @@
<?php
function setTitleFontSizeClass($title, $level = 'h1')
{
$length = strlen($title);
if ($level === 'h1') {
switch (true) {
case ($length < 35):
return 'fs-xxl';
break;
case ($length < 70):
return 'fs-xl';
break;
default:
return 'fs-l';
break;
}
}
}
function getAuthorBySlug($slug)
{
$kirby = kirby();
$author = '';
foreach ($kirby->users() as $user) {
if (Str::slug($user->name()) === $slug) {
$author = $user;
}
}
return $author;
}

View file

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><?= $site->title() ?><?= e($page->url() !== $site->url(), '-' . $page->title()) ?></title>
<link rel="stylesheet" href="<?= url('assets') ?>/css/style.css" />
<link rel="stylesheet" href="<?= url('assets') ?>/css/style.css?version-cache-prevent<?= rand(0, 1000)?>" />
<script src="<?= url('assets') ?>/js/script.js" defer></script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<meta name="robots" content="noindex">

24
site/templates/author.php Normal file
View file

@ -0,0 +1,24 @@
<?php snippet('header'); ?>
<header id="header" class="minimized">
<div id="logo" >
<a href="/" class="no-line">
<h2 id="actuel">actuel</h2>
<h2 id="inactuel">inactuel</h2>
</a>
</div>
</header>
<main id="<?= $page->template() ?>">
<article>
<div class="article-header">
<h1 class="main-title title-center <?= setTitleFontSizeClass($page->title()) ?>"><?= $page->title() ?></h1>
<p></p>
</div>
<?php snippet('tabs', [
'left' => [
'label' => 'Présentation',
'content' => $page->presentation()
]
]) ?>
</article>
</main>

View file

@ -8,13 +8,18 @@
</div>
</header>
<main id="<?= $page->template() ?>">
<article>
<div class="article-header">
<h1 class="main-title title-center <?= setTitleFontSizeClass($page->title()) ?>"><?= $page->title() ?></h1>
<p>Par <a href="/auteur/<?= Str::slug($page->author()->toUser()->name()) ?>" title="Voir les articles d'<?= $page->author()->toUser()->name() ?>"><?= $page->author()->toUser()->name() ?></a></p>
</div>
<?php snippet('tabs', [
'left' => [
'label' => 'Édito ' . $page->parent()->title(),
'content' => $page->parent()->edito()
]
]) ?>
<h1 class="title-center"><?= $page->title() ?></h1>
</article>
</main>
<?php snippet('footer') ?>