Skip to content

Commit f4820b2

Browse files
Merge pull request #1 from JonasDoebertin/note/n-scale-stuff
Add XML Sitemap
2 parents 6c09b88 + 77fedb6 commit f4820b2

20 files changed

+360
-19
lines changed

.husky/pre-commit

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ if [ $RECTOR_EXIT_CODE -ne 0 ]; then
1212
exit 1
1313
fi
1414

15+
# Run Pint
16+
echo "➡️ Running Pint..."
17+
vendor/bin/pint
18+
PINT_EXIT_CODE=$?
19+
20+
if [ $PINT_EXIT_CODE -ne 0 ]; then
21+
echo "❌ Pint failed"
22+
exit 1
23+
fi
24+
1525
# Add all modified files to the git working tree
1626
MODIFIED_FILES=$(git diff --name-only -- "*.php")
1727

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jonasdoebertin.github.io.iml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Listeners/GenerateSitemap.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Listeners;
6+
7+
use samdark\sitemap\Sitemap;
8+
use TightenCo\Jigsaw\Jigsaw;
9+
10+
class GenerateSitemap
11+
{
12+
private const array EXCLUDE = [
13+
'/apple-touch-icon.png',
14+
'/assets/*',
15+
'/favicon*',
16+
'/humans.txt',
17+
'/images/*',
18+
'/robots.txt',
19+
'/site.webmanifest',
20+
'/web-app-manifest-*',
21+
'*/404*',
22+
];
23+
24+
public function handle(Jigsaw $jigsaw): void
25+
{
26+
$baseUrl = $jigsaw->getConfig('baseUrl');
27+
28+
$sitemap = new Sitemap($jigsaw->getDestinationPath() . '/sitemap.xml');
29+
30+
collect($jigsaw->getOutputPaths())
31+
->reject(
32+
fn (string $path): bool => $this->isExcluded($path)
33+
)
34+
->each(
35+
function (string $path) use ($baseUrl, $sitemap): void {
36+
$uri = rtrim((string) $baseUrl, '/') . $path;
37+
$sitemap->addItem($uri, time(), Sitemap::DAILY);
38+
}
39+
);
40+
41+
$sitemap->write();
42+
}
43+
44+
public function isExcluded($path): bool
45+
{
46+
return str($path)->is(self::EXCLUDE, true);
47+
}
48+
}

app/Markdown/ExtendedMarkdownParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct()
3131

3232
$this->code_class_prefix = 'highlighting language-';
3333

34-
$this->code_block_content_func = (fn(string $content, string $language): string => $this->highlightFencedCodeBlock($content, $language));
34+
$this->code_block_content_func = (fn (string $content, string $language): string => $this->highlightFencedCodeBlock($content, $language));
3535
}
3636

3737
private function highlightFencedCodeBlock(
@@ -41,7 +41,7 @@ private function highlightFencedCodeBlock(
4141
$content = strtr($content, ["<{{'?php'}}" => '<?php']);
4242

4343
try {
44-
if($language !== '' && $language !== '0') {
44+
if ($language !== '' && $language !== '0') {
4545
return $this->highlighter->highlight($language, $content)->value;
4646
} else {
4747
return $this->highlighter->highlightAuto($content)->value;

bootstrap.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22

3+
use App\Listeners\GenerateSitemap;
34
use App\Markdown\ExtendedMarkdownParser;
45
use Illuminate\Container\Container;
6+
use TightenCo\Jigsaw\Events\EventBus;
57
use TightenCo\Jigsaw\Parsers\MarkdownParserContract;
68

79
/** @var Container $container */
810
$container->bind(MarkdownParserContract::class, ExtendedMarkdownParser::class);
911

10-
/** @var \TightenCo\Jigsaw\Events\EventBus $events */
12+
/** @var EventBus $events */
13+
$events->afterBuild(GenerateSitemap::class);
14+
1115
/*
1216
* You can run custom code at different stages of the build process by
1317
* listening to the 'beforeBuild', 'afterCollections', and 'afterBuild' events.

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
},
1515
"require": {
1616
"php": "^8.4",
17+
"illuminate/collections": "^12.19",
18+
"illuminate/support": "^12.19",
19+
"samdark/sitemap": "^2.4",
1720
"scrivo/highlight.php": "^9.18",
1821
"tightenco/jigsaw": "^1.8"
1922
},
2023
"require-dev": {
24+
"laravel/pint": "^1.22",
2125
"rector/rector": "^2.0",
2226
"roave/security-advisories": "dev-latest",
2327
"shipmonk/composer-dependency-analyser": "^1.8"

composer.lock

Lines changed: 136 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use Spatie\CommonMarkHighlighter\FencedCodeRenderer;
4-
53
return [
64
'production' => false,
75
'baseUrl' => 'http://localhost:8000/',
@@ -13,5 +11,8 @@
1311
'path' => 'notes',
1412
'sort' => '-date',
1513
],
14+
'projects' => [
15+
'sort' => 'priority',
16+
],
1617
],
1718
];

0 commit comments

Comments
 (0)