Skip to content

Commit

Permalink
✨ inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti committed Mar 27, 2023
0 parents commit 55523b5
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/tasks.yml
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public/
vendor/
composer.lock
var/
98 changes: 98 additions & 0 deletions Classes/Middleware/RootSitemapMiddleware.php
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>
';
}
}
19 changes: 19 additions & 0 deletions Configuration/RequestMiddlewares.php
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',
],
],
],
];
8 changes: 8 additions & 0 deletions Configuration/Services.yaml
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/*'
39 changes: 39 additions & 0 deletions README.md
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/

10 changes: 10 additions & 0 deletions Resources/Public/Icons/Extension.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions composer.json
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"
}
}
17 changes: 17 additions & 0 deletions ext_emconf.php
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/',
],
],
];
16 changes: 16 additions & 0 deletions grumphp.yml
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
2 changes: 2 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors: []
7 changes: 7 additions & 0 deletions phpstan.neon
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
42 changes: 42 additions & 0 deletions rector.php
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',
]
);
};

0 comments on commit 55523b5

Please sign in to comment.