Skip to content

Commit

Permalink
Merge pull request #1 from andersundsehr/external_sitemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Apr 13, 2023
2 parents 55523b5 + 336c302 commit 3423c1d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
27 changes: 23 additions & 4 deletions Classes/Middleware/RootSitemapMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,32 @@ private function getSitemapsPerLanguage(Site $site): array
$uri = $this->uriBuilder
->setTargetPageUid($site->getRootPageId())
->setCreateAbsoluteUri(true)
->setArguments([
'type' => '1533906435',
])
->setArguments(['type' => '1533906435'])
->setLanguage((string)$language->getLanguageId())
->buildFrontendUri();

$urls[] = new Uri($uri);
if ($uri) {
$urls[] = new Uri($uri);
}
}

$externalSitemaps = $site->getConfiguration()['external_sitemaps'];
$base = $site->getBase();
foreach (GeneralUtility::trimExplode("\n", $externalSitemaps, true) as $externalSitemap) {
$uri = new Uri($externalSitemap);
if (!$uri->getScheme()) {
$uri = $uri->withScheme($base->getScheme());
}

if (!$uri->getHost()) {
$uri = $uri->withHost($base->getHost());
}

if (!$uri->getPort()) {
$uri = $uri->withPort($base->getPort());
}

$urls[] = $uri;
}

return $urls;
Expand Down
20 changes: 20 additions & 0 deletions Configuration/SiteConfiguration/Overrides/sites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

// Experimental example to add a new field to the site configuration

// Configure a new simple required input field to site
$GLOBALS['SiteConfiguration']['site']['columns']['external_sitemaps'] = [
'label' => 'Additional Sitemaps',
'description' => 'add one external Sitemap per line (starting with /.. or with full https://domain...',
'config' => [
'type' => 'text',
],
];


// And add it to showitem
$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] = str_replace(
'base,',
'base, external_sitemaps, ',
(string) $GLOBALS['SiteConfiguration']['site']['types']['0']['showitem']
);
Binary file added Documentation/external_sitemaps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ This sitemap includes all active language sitemaps like: `/en/?type=1533906435`

You do not need to configure anything.

## Additional sitemaps form e.g. other systems:

if you want to add additional sitemaps from e.g. external Systems like a Shop system:
you can add them in the Sites Configuration:
![Screenshot of sites configuration addition](./Documentation/external_sitemaps.png)

### I want nicer URLS:

Expand Down

0 comments on commit 3423c1d

Please sign in to comment.