From 6472a36fed6babf38b8267c9b3d627bd4ea480a5 Mon Sep 17 00:00:00 2001 From: Richard Dern Date: Fri, 26 Apr 2024 23:43:54 +0200 Subject: [PATCH] Command to list dead links --- app/Console/Commands/Bundle/DeadLinks.php | 62 +++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 app/Console/Commands/Bundle/DeadLinks.php diff --git a/app/Console/Commands/Bundle/DeadLinks.php b/app/Console/Commands/Bundle/DeadLinks.php new file mode 100644 index 0000000..426e278 --- /dev/null +++ b/app/Console/Commands/Bundle/DeadLinks.php @@ -0,0 +1,62 @@ +argument('path') ?? '/'; + + if ($this->option('recursive')) { + $bundles = Bundle::findBundles($disk, $path, true); + } else { + $bundles = [new Bundle($path, $disk)]; + } + + foreach ($bundles as $bundle) { + $bundle->load(); + + $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(); + } + } + } +}