Skip to content

Commit

Permalink
Merge pull request #218 from LibreCodeCoop/feature/sitemap
Browse files Browse the repository at this point in the history
sitemap
  • Loading branch information
vitormattos authored Jul 22, 2024
2 parents ca2896e + 71985f4 commit 20a2e75
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/.vscode/
npm-debug.log
yarn-error.log

/source/assets/sitemap.xml
# Optional ignores
# /build_staging/
# /build_production/
Expand Down
2 changes: 2 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
* // Your code here
* });
*/

$events->afterBuild(App\Listeners\GenerateSitemap::class);
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"gregwar/captcha": "^1.2",
"libresign/espeak": "dev-main",
"nesbot/carbon": "^3.3",
"elaborate-code/jigsaw-localization": "dev-main"
"elaborate-code/jigsaw-localization": "dev-main",
"samdark/sitemap": "^2.4"
},
"autoload": {
"psr-4": {
Expand Down
61 changes: 60 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions listeners/GenerateSitemap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php namespace App\Listeners;

use TightenCo\Jigsaw\Jigsaw;
use samdark\sitemap\Sitemap;

class GenerateSitemap
{
public function handle(Jigsaw $jigsaw)
{
$baseUrl = trim(file_get_contents('CNAME'));
$sitemap = new Sitemap($jigsaw->getDestinationPath() . '/sitemap.xml');

collect($jigsaw->getOutputPaths())->each(function ($path) use ($baseUrl, $sitemap) {
if (! $this->isAsset($path)) {
$sitemap->addItem('https://'.$baseUrl . $path, time(), Sitemap::DAILY);
}
});

$sitemap->write();
}

public function isAsset($path)
{
return str_starts_with($path, '/assets');
}
}

0 comments on commit 20a2e75

Please sign in to comment.