Ext: sg_seo

License: GNU GPL, Version 2

Repository: https://gitlab.sgalinski.de/typo3/sg_seo

Please report bugs here: https://gitlab.sgalinski.de/typo3/sg_seo

TYPO3 version: >9.5

About

This extension provides a Google sitemap implementation with additional features like:

  • ignoring pages with canonical links to other pages
  • respecting noindex & nofollow options
  • ignoring shortcuts and status pages

Usage

Simply call http://example.com/index.php?eID=sg_seo to generate the sitemap or map it with the typeNum way.

'sitemap.xml' => [
    'keyValues' => [
        'type' => 165165,
    ],
],

Scheduler

There are two scheduler tasks for this extension

  1. A scheduler task to generate a sitemap for each language
  2. A scheduler task to generate webp versions of the processed files

Sitemap generation

This scheduler task can be activated to create static sitemaps of each language, which then can be delivered instead of a dynamic process which could take a long time.

The task takes 3 arguments:

  1. relativePathToSitemap: Describes where to save the generated sitemap files in the file system. This defaults to the project root.
  2. siteRootId: The id of the site root, where the sitemap will start
  3. enableFilter: Switch to add hidden pages (does not affect "NOT_IN_MENU") to the sitemap

WebP generation

This scheduler task can generate webp versions of the images in processed folders. It uses the PHP builtin function imagewebp and thus relies on the gd-extension to be installed (default requirement of TYPO3).

The task takes 5 arguments:

  1. storageUid: The uid of the file storage to process. Defaults to 1 which usually is the fileadmin
  2. savingPercentage: Define the minimum percentage of filesize savings the process has to achieve. By default, it is set to 10
  3. imageQuality: Define the image quality. This is set to 80 by default.
  4. batchSize: The number of files to process in one go (Note: The task will not stop after the amount of files, but fetch the amount of files, then process them before fetching the next batch. If it crashes, the task can be executed again, and it will continue with the batch it last worked on.) Defaults to 500.
  5. processGif: Include gif images in the processing, defaults to 0, which means no

Apache .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteCond %{DOCUMENT_ROOT}/$1.$2.webp -f
    RewriteRule ^(fileadmin/.+)\.(png|jpe?g)$ $1.$2.webp [L]
</IfModule>

<IfModule mod_headers.c>
    Header append Vary Accept env=REDIRECT_accept
</IfModule>

AddType image/webp .webp

nginx

Add a map directive in your global nginx configuration:

map $http_accept $webp_suffix {
    default   "";
    "~*webp"  ".webp";
}

and add these rules to your server configuration:

location ~* ^/fileadmin/.+\.(png|jpg|jpeg)$ {
        add_header Vary Accept;
        try_files $uri$webp_suffix $uri =404;
}
location ~* ^/other-storage/.+\.(png|jpg|jpeg)$ {
        add_header Vary Accept;
        try_files $uri$webp_suffix $uri =404;
}

Make sure that there are no other rules that already apply to the specified image formats and prevent further execution!

Extensions

You can hook into the process to extend the sitemap easily.

Example: Services.yaml

services:
    MyExt\Event\Listener\SeoAccessPageListEventListener:
        tags:
            -   name: event.listener
                identifier: 'accessPageListEvent'
                event: SGalinski\SgSeo\Events\AccessPageListEvent

EventListener class:

class SeoAccessPageListEventListener {
    public function __invoke(\SGalinski\SgSeo\Events\AccessPageListEvent $event) {
        $pageList = $event->getPageList();
        // ... do something with the list and write it back to the event
        $pageList[] = [
            'url' => 'MY FURTHER URL',
            'title' => ''
        ];
        $event->setPageList($pageList);
    }
}