diff --git a/app/Console/Commands/Bundle/DeadLinks.php b/app/Console/Commands/Bundle/DeadLinks.php deleted file mode 100644 index ec0dfd1..0000000 --- a/app/Console/Commands/Bundle/DeadLinks.php +++ /dev/null @@ -1,78 +0,0 @@ -argument('path') ?? '/'; - - if ($this->option('recursive')) { - $bundles = Bundle::findBundles($disk, $path, true); - } else { - $bundles = [new Bundle($path, $disk)]; - } - - foreach ($bundles as $bundle) { - $bundle->load(); - - if ($this->option('clear')) { - $bundle->metadata('links')->clear(); - $bundle->metadata('links')->save(); - - continue; - } - - $deadLinks = []; - - foreach ($bundle->metadata('links')->all() as $url => $data) { - if ($data['isDead']) { - $deadLinks[$url] = $data['reason']; - } - } - - if (!empty($deadLinks)) { - $this->output->write(sprintf('Looking in %s... ', $bundle->getPath())); - $this->error('Dead links'); - - foreach ($deadLinks as $url => $reason) { - $this->line(sprintf(' - [%s]: %s', $url, $reason)); - } - - $this->newLine(); - } - } - - if ($this->option('clear')) { - $this->call('cache:clear'); - $this->comment('links.json file(s) have been removed.'); - $this->line('Remember to re-render bundles to check for dead links.'); - } - } -} diff --git a/app/Console/Commands/Markdown/Lint.php b/app/Console/Commands/Markdown/Lint.php deleted file mode 100644 index e9de976..0000000 --- a/app/Console/Commands/Markdown/Lint.php +++ /dev/null @@ -1,41 +0,0 @@ -argument('path'))); - - $content = Storage::disk(env('CONTENT_DISK'))->get($this->argument('path')); - $lint = new Linter($content); - $result = $lint->format(); - - if ($result !== $content) { - Storage::disk(env('CONTENT_DISK'))->put($this->argument('path'), $result); - } - } -} diff --git a/app/Console/Commands/RestoreFiles.php b/app/Console/Commands/RestoreFiles.php deleted file mode 100644 index 1030d0c..0000000 --- a/app/Console/Commands/RestoreFiles.php +++ /dev/null @@ -1,187 +0,0 @@ -argument('path'))) { - $directories[] = $this->argument('path'); - } else { - // Trouver tous les dossiers contenant un fichier `index.html` - $directories = $disk->listContents('/', true) - ->filter(fn (StorageAttributes $attributes) => ($attributes->isDir() && $disk->exists($attributes->path() . '/index.html'))) - ->map(fn (StorageAttributes $attributes) => $attributes->path()) - ->toArray(); - } - - // Afficher les résultats - $this->info('Répertoires contenant un index.html :'); - foreach ($directories as $folder) { - $this->processIndexHtml($disk, $folder); - } - - $this->newLine(); - $this->line('Récapitulatif'); - $this->newLine(); - - foreach ($this->noBodyButAttachments as $path => $attachments) { - $this->newLine(); - $this->line($path); - foreach ($attachments as $index => $file) { - $this->line(sprintf(' > %s', $file)); - } - } - } - - private function loadArticleMetadata($folder) - { - $jsonContent = Storage::disk(env('CONTENT_DISK'))->get($folder . '/data/index.json'); - $data = json_decode($jsonContent, true); - - return $data ?? []; // Retourne la référence de l'image d'en-tête si disponible - } - - private function findAttachmentDetails($folder, $reference) - { - $types = ['images', 'videos', 'sounds']; // Les différents types d'attachments - - foreach ($types as $type) { - $jsonPath = $folder . '/data/' . $type . '.json'; // Chemin vers le fichier JSON - - if (Storage::disk(env('CONTENT_DISK'))->exists($jsonPath)) { - $jsonContent = Storage::disk(env('CONTENT_DISK'))->get($jsonPath); - $data = json_decode($jsonContent, true); - - if (isset($data['files'][$reference])) { - return $data['files'][$reference]['filename']; // Retourne le 'filename' si la référence est trouvée - } - } - } - - return null; // Retourne null si la référence n'est trouvée dans aucun fichier - } - - private function extractReferencesFromMarkdown($markdownContent) - { - preg_match_all('//', $markdownContent, $matches); - - return $matches[1]; // Retourne un tableau des références trouvées - } - - private function processIndexHtml($disk, $folder) - { - $htmlContent = $disk->get($folder . '/index.html'); - $markdownContent = Storage::disk(env('CONTENT_DISK'))->get($folder . '/index.md'); - - $hasNoBody = false; - $hasAttachments = false; - $attachments = []; - - $this->newLine(); - $this->line($folder); - - if (empty($markdownContent)) { - $this->comment(' > Article has no body'); - $hasNoBody = true; - } - - $references = $this->extractReferencesFromMarkdown($markdownContent); - $cover = $this->loadArticleMetadata($folder)['cover'] ?? null; - $logo = $this->loadArticleMetadata($folder)['logo'] ?? null; - - if ($cover) { - array_unshift($references, $cover); - } - - if ($logo) { - array_push($references, $logo); - } - - $dom = new \DOMDocument(); - - // Charger le HTML et supprimer les erreurs pour éviter les avertissements - @$dom->loadHTML($htmlContent); - - $xpath = new \DOMXPath($dom); - $figureNodes = $xpath->query('//figure'); - - $index = 0; - - foreach ($figureNodes as $index => $figure) { - // Traiter les images - $imageLinks = (new \DOMXPath($dom))->query('.//a[starts-with(@href, "/storage")]', $figure); - $this->processLinks($imageLinks, $references, $index, $folder, $attachments, 'image'); - - // Traiter les vidéos - $videoSources = (new \DOMXPath($dom))->query('.//video/source[starts-with(@src, "/storage")]', $figure); - $this->processLinks($videoSources, $references, $index, $folder, $attachments, 'video'); - - // Traiter les sons - $audioSources = (new \DOMXPath($dom))->query('.//audio/source[starts-with(@src, "/storage")]', $figure); - $this->processLinks($audioSources, $references, $index, $folder, $attachments, 'audio'); - } - - foreach ($attachments as $source => $destination) { - $copied = false; - $contents = file_get_contents($source); - - if (!empty($contents)) { - $copied = Storage::disk(env('CONTENT_DISK'))->put($destination, $contents); - } - - if ($copied) { - $this->info(sprintf(' > %s > %s', $source, $destination)); - } else { - $this->error(sprintf(' > %s > %s', $source, $destination)); - } - } - - if ($hasAttachments && $hasNoBody) { - $this->noBodyButAttachments[$folder] = $attachments; - } - } - - private function processLinks($nodes, $references, &$index, $folder, &$attachments, $type) - { - foreach ($nodes as $node) { - $pathAttribute = ($type === 'image' ? 'href' : 'src'); - $href = $node->getAttribute($pathAttribute); - $realPath = Str::replace('/storage', 'storage/app/public', $href); - $reference = $references[$index] ?? 'Unknown'; - - if ($reference !== 'Unknown') { - $filename = $this->findAttachmentDetails($folder, $reference); - $filename = $folder . '/data/' . $filename; - } else { - $filename = $folder . '/data/attachments/' . $type . 's/' . basename($realPath); - } - - // if (empty($attachments[$realPath]) || !in_array($realPath, $attachments[$reference])) { - $attachments[$realPath] = $filename; - // } - - $index++; - } - } -}