-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added auto generated sitemap to website (#1216)
Added auto generated sitemap to website page
- Loading branch information
1 parent
19e8c26
commit 69a6039
Showing
13 changed files
with
236 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ build/ | |
vendor/ | ||
var/ | ||
public/assets | ||
public/*.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
presta_sitemap: | ||
defaults: | ||
priority: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# robots.txt for https://flow-php.com | ||
|
||
# Allow all web crawlers to index the site | ||
User-agent: * | ||
Disallow: | ||
|
||
# Allow assets required for rendering the page, such as JavaScript and CSS | ||
Allow: /assets/controllers/ | ||
Allow: /assets/styles/ | ||
Allow: /assets/images/ | ||
|
||
# Sitemap location | ||
Sitemap: https://flow-php.com/sitemap.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
web/landing/src/Flow/Website/EventListener/SitemapSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\Website\EventListener; | ||
|
||
use Flow\Website\Blog\Posts; | ||
use Flow\Website\Service\Documentation\DSLDefinitions; | ||
use Flow\Website\Service\Examples; | ||
use Presta\SitemapBundle\Event\SitemapPopulateEvent; | ||
use Presta\SitemapBundle\Sitemap\Url\UrlConcrete; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
final class SitemapSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private readonly Examples $examples, | ||
private readonly Posts $posts, | ||
private readonly DSLDefinitions $dslDefinitions, | ||
) { | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
SitemapPopulateEvent::class => 'populate', | ||
]; | ||
} | ||
|
||
public function populate(SitemapPopulateEvent $event) : void | ||
{ | ||
$this->populateExamples($event); | ||
$this->populateBlogPosts($event); | ||
$this->populateDocumentation($event); | ||
} | ||
|
||
private function populateBlogPosts(SitemapPopulateEvent $event) : void | ||
{ | ||
$posts = $this->posts->all(); | ||
|
||
foreach ($posts as $post) { | ||
$event->getUrlContainer()->addUrl( | ||
new UrlConcrete( | ||
$event->getUrlGenerator()->generate( | ||
'blog_post', | ||
['date' => $post->date->format('Y-m-d'), 'slug' => $post->slug], | ||
UrlGeneratorInterface::ABSOLUTE_URL | ||
), | ||
changefreq: 'weekly' | ||
), | ||
'blog' | ||
); | ||
} | ||
} | ||
|
||
private function populateDocumentation(SitemapPopulateEvent $event) : void | ||
{ | ||
$modules = $this->dslDefinitions->modules(); | ||
|
||
foreach ($modules as $module) { | ||
$event->getUrlContainer()->addUrl( | ||
new UrlConcrete( | ||
$event->getUrlGenerator()->generate( | ||
'documentation_dsl', | ||
['module' => \mb_strtolower($module->name)], | ||
UrlGeneratorInterface::ABSOLUTE_URL | ||
), | ||
changefreq: 'weekly' | ||
), | ||
'documentation' | ||
); | ||
|
||
foreach ($this->dslDefinitions->fromModule($module)->all() as $definition) { | ||
$event->getUrlContainer()->addUrl( | ||
new UrlConcrete( | ||
$event->getUrlGenerator()->generate( | ||
'documentation_dsl_function', | ||
['module' => \mb_strtolower($module->name), 'function' => $definition->slug()], | ||
UrlGeneratorInterface::ABSOLUTE_URL | ||
), | ||
changefreq: 'weekly' | ||
), | ||
'documentation' | ||
); | ||
} | ||
} | ||
} | ||
|
||
private function populateExamples(SitemapPopulateEvent $event) : void | ||
{ | ||
$topics = $this->examples->topics(); | ||
|
||
foreach ($topics as $topic) { | ||
$event->getUrlContainer()->addUrl( | ||
new UrlConcrete( | ||
$event->getUrlGenerator()->generate( | ||
'topic', | ||
['topic' => $topic], | ||
UrlGeneratorInterface::ABSOLUTE_URL | ||
), | ||
changefreq: 'weekly' | ||
), | ||
'examples' | ||
); | ||
|
||
$examples = $this->examples->examples($topic); | ||
|
||
foreach ($examples as $example) { | ||
$event->getUrlContainer()->addUrl( | ||
new UrlConcrete( | ||
$event->getUrlGenerator()->generate( | ||
'example', | ||
['topic' => $topic, 'example' => $example], | ||
UrlGeneratorInterface::ABSOLUTE_URL | ||
), | ||
changefreq: 'weekly' | ||
), | ||
'examples' | ||
); | ||
} | ||
} | ||
} | ||
} |