From 5e2bf9e9f8749a76e1ac55d4ebe7c6adc735c00b Mon Sep 17 00:00:00 2001
From: Abdessamad Bettal | Freelancer
<93977120+abdessamadbettal@users.noreply.github.com>
Date: Sat, 14 Dec 2024 10:21:15 +0000
Subject: [PATCH] Add sitemap generation command and update related files;
modify robots.txt and site manifest for SEO improvements
---
.gitignore | 1 +
app/Console/Commands/GenerateSitemap.php | 66 ++++++++++++++++++++++++
public/browserconfig.xml | 9 ++++
public/robots.txt | 3 +-
public/site.webmanifest | 6 +--
public/sitemap.xml | 11 ----
routes/console.php | 2 +
7 files changed, 82 insertions(+), 16 deletions(-)
create mode 100644 app/Console/Commands/GenerateSitemap.php
create mode 100644 public/browserconfig.xml
delete mode 100644 public/sitemap.xml
diff --git a/.gitignore b/.gitignore
index ed1e623..ee3c307 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@ Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
+/public/sitemap.xml
/.fleet
/.idea
/.vscode
diff --git a/app/Console/Commands/GenerateSitemap.php b/app/Console/Commands/GenerateSitemap.php
new file mode 100644
index 0000000..6175959
--- /dev/null
+++ b/app/Console/Commands/GenerateSitemap.php
@@ -0,0 +1,66 @@
+shouldCrawl(function (UriInterface $url) {
+ return $this->shouldIndex($url->getPath());
+ })
+ ->hasCrawled(function (Url $url) {
+ if ($this->shouldNotIndex($url->path())) {
+ return;
+ }
+
+ return $url;
+ })
+ ->writeToFile(public_path('sitemap.xml'));
+
+ $this->info('Sitemap generated');
+ }
+
+ private function shouldNotIndex(string $path): bool
+ {
+ return Str::is($this->noIndexPaths, $path);
+ }
+
+ private function shouldIndex(string $path): bool
+ {
+ return ! $this->shouldNotIndex($path);
+ }
+}
diff --git a/public/browserconfig.xml b/public/browserconfig.xml
new file mode 100644
index 0000000..8eabd6e
--- /dev/null
+++ b/public/browserconfig.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+ #2b5797
+
+
+
diff --git a/public/robots.txt b/public/robots.txt
index c3f1283..eb05362 100644
--- a/public/robots.txt
+++ b/public/robots.txt
@@ -1,3 +1,2 @@
User-agent: *
-Allow: /
-Sitemap: https://laravel-starter.com/sitemap.xml
+Disallow:
diff --git a/public/site.webmanifest b/public/site.webmanifest
index ccf313a..64b4174 100644
--- a/public/site.webmanifest
+++ b/public/site.webmanifest
@@ -1,6 +1,6 @@
{
- "name": "MyWebSite",
- "short_name": "MySite",
+ "name": "Laravel Starter",
+ "short_name": "Laravel Starter",
"icons": [
{
"src": "/web-app-manifest-192x192.png",
@@ -18,4 +18,4 @@
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
-}
\ No newline at end of file
+}
diff --git a/public/sitemap.xml b/public/sitemap.xml
deleted file mode 100644
index 31f6c4d..0000000
--- a/public/sitemap.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- http://localhost
-
-
-
- http://localhost/about
-
-
-
diff --git a/routes/console.php b/routes/console.php
index eff2ed2..f9f3425 100644
--- a/routes/console.php
+++ b/routes/console.php
@@ -6,3 +6,5 @@
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote')->hourly();
+
+Schedule::command('generate-sitemap')->daily();