-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 55523b5
Showing
13 changed files
with
327 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Tasks | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
lint-php: | ||
name: "php: ${{ matrix.php }} TYPO3: ${{ matrix.typo3 }}" | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: [ '8.1', '8.2' ] | ||
typo3: [ '11', '12' ] | ||
steps: | ||
- name: Setup PHP with PECL extension | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: ~/.composer/cache/files | ||
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.php }}-composer- | ||
- run: composer require typo3/minimal="^${{ matrix.typo3 }}" --dev --ignore-platform-req=php+ | ||
- run: composer install --no-interaction --no-progress --ignore-platform-req=php+ | ||
- run: ./vendor/bin/grumphp run --ansi |
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,4 @@ | ||
public/ | ||
vendor/ | ||
composer.lock | ||
var/ |
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,98 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AUS\RootSitemap\Middleware; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use TYPO3\CMS\Core\Http\HtmlResponse; | ||
use TYPO3\CMS\Core\Http\Uri; | ||
use TYPO3\CMS\Core\Site\Entity\Site; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Core\Utility\PathUtility; | ||
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; | ||
|
||
class RootSitemapMiddleware implements MiddlewareInterface | ||
{ | ||
public function __construct(private readonly UriBuilder $uriBuilder) | ||
{ | ||
} | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
if ($request->getUri()->getPath() !== '/sitemap.xml') { | ||
return $handler->handle($request); | ||
} | ||
|
||
$site = $request->getAttribute('site'); | ||
assert($site instanceof Site, 'This middleware needs the site attribute'); | ||
$sitemapUrls = $this->getSitemapsPerLanguage($site); | ||
foreach ($sitemapUrls as $sitemapUrl) { | ||
if ($sitemapUrl->getHost() !== $request->getUri()->getHost()) { | ||
continue; | ||
} | ||
|
||
if ($sitemapUrl->getPath() !== $request->getUri()->getPath()) { | ||
continue; | ||
} | ||
|
||
return $handler->handle($request); | ||
} | ||
|
||
$renderHtml = $this->renderHtml($sitemapUrls); | ||
return (new HtmlResponse($renderHtml)) | ||
->withAddedHeader('Content-Type', 'application/xml;charset=utf-8') | ||
->withAddedHeader('X-Robots-Tag', 'noindex'); | ||
} | ||
|
||
/** | ||
* @return array<Uri> | ||
*/ | ||
private function getSitemapsPerLanguage(Site $site): array | ||
{ | ||
$urls = []; | ||
$languages = $site->getAllLanguages(); | ||
foreach ($languages as $language) { | ||
if (!$language->enabled()) { | ||
continue; | ||
} | ||
|
||
$uri = $this->uriBuilder | ||
->setTargetPageUid($site->getRootPageId()) | ||
->setCreateAbsoluteUri(true) | ||
->setArguments([ | ||
'type' => '1533906435', | ||
]) | ||
->setLanguage((string)$language->getLanguageId()) | ||
->buildFrontendUri(); | ||
|
||
$urls[] = new Uri($uri); | ||
} | ||
|
||
return $urls; | ||
} | ||
|
||
/** | ||
* @param array<Uri> $urls | ||
*/ | ||
private function renderHtml(array $urls): string | ||
{ | ||
$locs = []; | ||
foreach ($urls as $url) { | ||
$locs[] = ' <sitemap> | ||
<loc>' . htmlentities((string)$url) . '</loc> | ||
</sitemap>'; | ||
} | ||
|
||
$xsl = PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName('EXT:seo/Resources/Public/CSS/Sitemap.xsl')); | ||
|
||
return '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="' . $xsl . '"?> | ||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
' . implode("\n", $locs) . ' | ||
</sitemapindex> | ||
'; | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
use AUS\RootSitemap\Middleware\RootSitemapMiddleware; | ||
|
||
return [ | ||
'frontend' => [ | ||
'a-u-s/root-sitemap/root-sitemap-middleware' => [ | ||
'target' => RootSitemapMiddleware::class, | ||
'after' => [ | ||
'typo3/cms-frontend/site', | ||
'typo3/cms-core/normalized-params-attribute', | ||
], | ||
'before' => [ | ||
'typo3/cms-frontend/tsfe', | ||
'typo3/cms-frontend/authentication', | ||
], | ||
], | ||
], | ||
]; |
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,8 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
AUS\RootSitemap\: | ||
resource: '../Classes/*' | ||
exclude: '../Classes/Domain/Model/*' |
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,39 @@ | ||
# TYPO3 EXT:root_sitemap | ||
|
||
`composer req andersundsehr/root-sitemap` | ||
|
||
## What dose this Extension do? | ||
|
||
if you have your languages like this: `/en/` and this: `/de/` | ||
**and not a single language configured like this: `/`** | ||
Than this Extension is for you. | ||
|
||
It adds the endpoint `/sitemap.xml` to all your Sites. | ||
This sitemap includes all active language sitemaps like: `/en/?type=1533906435` and `/de/?type=1533906435`. | ||
|
||
You do not need to configure anything. | ||
|
||
|
||
### I want nicer URLS: | ||
|
||
you can configure a routeEnhancer like this: | ||
file: `config/sites/.../config.yaml` | ||
````yml | ||
routeEnhancers: | ||
PageTypeSuffix: | ||
type: PageType | ||
# if you want to have trailing slashes for all pages: | ||
default: '/' | ||
index: '' | ||
map: | ||
/: 0 | ||
sitemap.xml: 1533906435 | ||
```` | ||
|
||
# with ♥️ from anders und sehr GmbH | ||
|
||
> If something did not work 😮 | ||
> or you appreciate this Extension 🥰 let us know. | ||
|
||
> We are hiring https://www.andersundsehr.com/karriere/ | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,37 @@ | ||
{ | ||
"name": "andersundsehr/root-sitemap", | ||
"description": "/sitemap.xml will show all language sitemaps", | ||
"type": "typo3-cms-extension", | ||
"license": [ | ||
"GPL-2.0-or-later" | ||
], | ||
"require": { | ||
"typo3/cms-core": "^11.5 || ^12.0", | ||
"typo3/cms-seo": "^11.5 || ^12.0", | ||
"php": "~8.1 || ~8.2" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"AUS\\RootSitemap\\": "Classes/" | ||
} | ||
}, | ||
"extra": { | ||
"typo3/cms": { | ||
"extension-key": "root_sitemap" | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"typo3/class-alias-loader": true, | ||
"typo3/cms-composer-installers": true, | ||
"phpro/grumphp": true, | ||
"phpstan/extension-installer": true, | ||
"pluswerk/grumphp-config": true | ||
} | ||
}, | ||
"require-dev": { | ||
"saschaegerer/phpstan-typo3": "^1.8.2", | ||
"ssch/typo3-rector": "^1.1.3", | ||
"pluswerk/grumphp-config": "^6.4" | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
/** @var string $_EXTKEY */ | ||
$EM_CONF[$_EXTKEY] = [ | ||
'title' => 'root_sitemap', | ||
'description' => '/sitemap.xml will show all language sitemaps', | ||
'constraints' => [ | ||
'depends' => [ | ||
'typo3' => '11.0.0-12.4.99', | ||
], | ||
], | ||
'autoload' => [ | ||
'psr-4' => [ | ||
'AUS\\RootSitemap\\' => 'Classes/', | ||
], | ||
], | ||
]; |
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,16 @@ | ||
imports: | ||
- { resource: vendor/pluswerk/grumphp-config/grumphp.yml } | ||
parameters: | ||
convention.process_timeout: 240 | ||
convention.security_checker_blocking: true | ||
convention.jsonlint_ignore_pattern: { } | ||
convention.xmllint_ignore_pattern: { } | ||
convention.yamllint_ignore_pattern: { } | ||
convention.phpcslint_ignore_pattern: { } | ||
convention.phpcslint_exclude: { } | ||
convention.xlifflint_ignore_pattern: { } | ||
convention.rector_ignore_pattern: { } | ||
convention.rector_enabled: true | ||
convention.rector_config: rector.php | ||
convention.rector_clear-cache: false | ||
convention.phpstan_level: null |
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,2 @@ | ||
parameters: | ||
ignoreErrors: [] |
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,7 @@ | ||
includes: | ||
- phpstan-baseline.neon | ||
- vendor/andersundsehr/phpstan-git-files/extension.php | ||
|
||
parameters: | ||
level: 8 | ||
reportUnmatchedIgnoredErrors: false |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PLUS\GrumPHPConfig\RectorSettings; | ||
use Rector\Config\RectorConfig; | ||
use Rector\Caching\ValueObject\Storage\FileCacheStorage; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->parallel(); | ||
$rectorConfig->importNames(); | ||
$rectorConfig->importShortClasses(); | ||
$rectorConfig->cacheClass(FileCacheStorage::class); | ||
$rectorConfig->cacheDirectory('./var/cache/rector'); | ||
|
||
$rectorConfig->paths( | ||
array_filter(explode("\n", (string)shell_exec("git ls-files | xargs ls -d 2>/dev/null | grep '\.php$'"))) | ||
); | ||
|
||
// define sets of rules | ||
$rectorConfig->sets( | ||
[ | ||
...RectorSettings::sets(true), | ||
...RectorSettings::setsTypo3(false), | ||
] | ||
); | ||
|
||
// remove some rules | ||
// ignore some files | ||
$rectorConfig->skip( | ||
[ | ||
...RectorSettings::skip(), | ||
...RectorSettings::skipTypo3(), | ||
|
||
/** | ||
* rector should not touch these files | ||
*/ | ||
//__DIR__ . '/src/Example', | ||
//__DIR__ . '/src/Example.php', | ||
] | ||
); | ||
}; |