1
0
Fork 0

Infrastructure to build website

This commit is contained in:
Richard Dern 2024-04-26 16:09:33 +02:00
parent 5d88107449
commit 0ea7f593d9
11 changed files with 140 additions and 75 deletions

2
.gitignore vendored
View File

@ -17,3 +17,5 @@ yarn-error.log
/.fleet
/.idea
/.vscode
/dist
.DS_Store

View File

@ -3,6 +3,7 @@
namespace App\Console\Commands\Bundle;
use App\Classes\Bundle;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
@ -27,8 +28,9 @@ class Repair extends Command
*/
public function handle()
{
$disk = Storage::disk(env('CONTENT_DISK'));
$path = $this->argument('path') ?? '/';
$bundles = Bundle::findBundles(Storage::disk(env('CONTENT_DISK')), $path, true);
$bundles = Bundle::findBundles($disk, $path, true);
foreach ($bundles as $bundle) {
$this->output->write(sprintf('Repairing %s... ', $bundle->getPath()));
@ -37,5 +39,58 @@ public function handle()
$this->info('OK');
}
foreach (['blog', 'liens-interessants'] as $section) {
$this->createIntermediateBundles($section);
}
}
protected function createIntermediateBundles($parent)
{
$disk = Storage::disk(env('CONTENT_DISK'));
foreach ($disk->directories($parent) as $dir) {
if (basename($dir) === 'data') {
continue;
}
$bundle = new Bundle($dir, $disk);
if (!$bundle->exists()) {
$bundle->markdown()->set('');
$parts = preg_split('#/#', $bundle->getPath(), -1, PREG_SPLIT_NO_EMPTY);
$count = count($parts);
switch ($count) {
case 2:
// A year is specified
$date = sprintf('%s-%s-%s', $parts[1], '01', '01');
$date = Carbon::parse($date);
$articleTitle = sprintf('Publiés en %s', $date->isoFormat('YYYY'));
break;
case 3:
// A month is specified
$date = sprintf('%s-%s-%s', $parts[1], $parts[2], '01');
$date = Carbon::parse($date);
$articleTitle = sprintf('Publiés en %s', $date->isoFormat('MMMM YYYY'));
break;
case 4:
// A day is specified
$date = sprintf('%s-%s-%s', $parts[1], $parts[2], $parts[3]);
$date = Carbon::parse($date);
$articleTitle = sprintf('Publiés le %s', $date->isoFormat('DD MMMM YYYY'));
break;
}
if (!empty($articleTitle)) {
$bundle->metadata()->set('title', $articleTitle);
}
$bundle->save();
$this->createIntermediateBundles($bundle->getPath());
}
}
}
}

View File

@ -13,6 +13,8 @@ abstract class BaseRenderer implements RendersBundle
{
protected array $viewData = [];
protected ?array $subBundles;
public function __construct(protected Bundle $bundle)
{
$bundle->load();
@ -20,14 +22,42 @@ public function __construct(protected Bundle $bundle)
$this->shareCommonDataWithView();
}
public function getSubBundles()
{
if (!isset($this->subBundles)) {
$this->subBundles = $this->collectSubBundles();
}
return $this->subBundles;
}
/**
* Renders a complete HTML view of the bundle
*/
public function render()
{
$this->prepareRender();
$result = [];
$totalPages = count(array_chunk($this->getSubBundles(), config('pagination.itemsPerPage')));
return view('article', $this->viewData);
if ($totalPages > 1) {
for ($currentPage = 1; $currentPage <= $totalPages; $currentPage++) {
$this->prepareRender($currentPage);
if ($currentPage === 1) {
$result[$this->bundle->getPath()] = (string) view('article', $this->viewData);
}
$page = sprintf('%spage/%s/', $this->bundle->getPath(), $currentPage);
$result[$page] = (string) view('article', $this->viewData);
}
} else {
$this->prepareRender(1);
$result[$this->bundle->getPath()] = (string) view('article', $this->viewData);
}
return $result;
}
/**
@ -51,7 +81,7 @@ public static function make(Bundle $bundle): RendersBundle
/**
* Renders a complete HTML view of the bundle
*/
protected function prepareRender()
protected function prepareRender(int $currentPage = 1)
{
$this->bundle->markdown()->lint();
@ -71,7 +101,7 @@ protected function prepareRender()
data_set($this->viewData, 'cover', $cover ? $cover->render() : null);
data_set($this->viewData, 'body', $this->bundle->markdown()->render());
$this->handlePagination();
$this->handlePagination($currentPage);
}
/**
@ -115,11 +145,10 @@ protected function shareCommonDataWithView(): void
}
}
protected function handlePagination()
protected function handlePagination(int $currentPage = 1)
{
$itemsPerPage = config('pagination.itemsPerPage');
$currentPage = $this->bundle->getCurrentPage();
$subBundles = $this->collectSubBundles();
$subBundles = $this->getSubBundles();
if (!$this->bundle->exists() && empty($subBundles)) {
throw new Exception(sprintf(

View File

@ -7,48 +7,6 @@
class DateBasedListRenderer extends ListRenderer
{
/**
* Renders a complete HTML view of the bundle
*/
public function render()
{
$this->prepareRender();
$parts = preg_split('#/#', $this->bundle->getPath(), -1, PREG_SPLIT_NO_EMPTY);
$count = count($parts);
switch ($count) {
case 2:
// A year is specified
$date = sprintf('%s-%s-%s', $parts[1], '01', '01');
$date = Carbon::parse($date);
$articleTitle = $date->isoFormat('YYYY');
$siteTitle = sprintf('Articles publiés en %s', $date->isoFormat('YYYY'));
break;
case 3:
// A month is specified
$date = sprintf('%s-%s-%s', $parts[1], $parts[2], '01');
$date = Carbon::parse($date);
$articleTitle = $date->isoFormat('MMMM YYYY');
$siteTitle = sprintf('Articles publiés en %s %s', $date->isoFormat('MMMM'), $date->isoFormat('YYYY'));
break;
case 4:
// A day is specified
$date = sprintf('%s-%s-%s', $parts[1], $parts[2], $parts[3]);
$date = Carbon::parse($date);
$articleTitle = $date->isoFormat('DD MMMM YYYY');
$siteTitle = sprintf('Articles publiés le %s %s %s', $date->isoFormat('DD'), $date->isoFormat('MMMM'), $date->isoFormat('YYYY'));
break;
}
if (!empty($articleTitle)) {
data_set($this->viewData, 'articleTitle', $articleTitle);
data_set($this->viewData, 'siteTitle', $siteTitle);
}
return view('article', $this->viewData);
}
/**
* Return a boolean value indicating if this creator in particular can
* create bundles for specified section

View File

@ -42,7 +42,12 @@ public static function handles(Bundle $bundle): bool
return $bundle->getSection() && $bundle->getSection()->getPath() === '/dossiers/';
}
protected function handlePagination()
protected function handlePagination(int $currentPage = 1)
{
}
protected function collectSubBundles()
{
return [];
}
}

View File

@ -7,12 +7,22 @@
class ProductBasedListRenderer extends ListRenderer
{
/**
* Renders a complete HTML view of the bundle
* Return a boolean value indicating if this creator in particular can
* create bundles for specified section
*/
public function render()
public static function handles(Bundle $bundle): bool
{
$this->prepareRender();
$parts = preg_split('#/#', $bundle->getPath(), -1, PREG_SPLIT_NO_EMPTY);
$count = count($parts);
$sections = ['collections'];
return $count > 0
&& in_array($parts[0], $sections)
&& $count < 4;
}
protected function prepareRender(int $currentPage = 1)
{
$parts = preg_split('#/#', $this->bundle->getPath(), -1, PREG_SPLIT_NO_EMPTY);
$count = count($parts);
@ -40,22 +50,7 @@ public function render()
data_set($this->viewData, 'siteTitle', $siteTitle);
}
return view('article', $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
{
$parts = preg_split('#/#', $bundle->getPath(), -1, PREG_SPLIT_NO_EMPTY);
$count = count($parts);
$sections = ['collections'];
return $count > 0
&& in_array($parts[0], $sections)
&& $count < 4;
parent::prepareRender($currentPage);
}
protected function handleFilters($subBundles)

View File

@ -23,7 +23,7 @@ public function render()
data_set($this->viewData, 'relations', $relations);
return view('term', $this->viewData);
return [$this->bundle->getPath() => view('term', $this->viewData)];
}
/**
@ -35,7 +35,12 @@ public static function handles(Bundle $bundle): bool
return $bundle->getSection() && $bundle->getSection()->getPath() === '/termes/';
}
protected function handlePagination()
protected function handlePagination(int $currentPage = 1)
{
}
protected function collectSubBundles()
{
return [];
}
}

View File

@ -36,6 +36,18 @@
'throw' => false,
],
'dist' => [
'driver' => 'local',
'root' => base_path(env('DIST_PATH')),
'throw' => false,
],
'local_public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'throw' => false,
],
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
@ -76,7 +88,9 @@
*/
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('storage') => storage_path('app/public'),
base_path('dist/storage') => storage_path('app/public'),
base_path('dist/build') => public_path('build'),
],
];

View File

@ -29,6 +29,7 @@ services:
volumes:
- '.:/var/www/html'
- '../contenu:/content'
- '~/.ssh:/home/sail/.ssh:ro'
networks:
- sail
depends_on:

View File

@ -2,7 +2,7 @@ ARG PHP_VERSION=8.0
FROM sail-${PHP_VERSION}/app as base
RUN apt-get update \
&& apt-get -y install cron imagemagick php8.3-imagick
&& apt-get -y install cron imagemagick php8.3-imagick rsync
COPY crontab /etc/cron.d/laravel-scheduler
RUN chmod 0644 /etc/cron.d/laravel-scheduler

View File

@ -3,9 +3,10 @@
use App\Classes\Bundle;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
Route::get('{any}', function () {
$bundle = new Bundle(request()->path(), Storage::disk('content'));
return $bundle->render();
return $bundle->render()[Str::start(Str::finish(request()->path(), '/'), '/')];
})->where('any', '.*');