fof / sitemap
Generate a sitemap
Fund package maintenance!
Website
Installs: 41 435
Dependents: 2
Suggesters: 6
Security: 0
Stars: 14
Watchers: 5
Forks: 16
Open Issues: 3
Type:flarum-extension
Requires
- php: 8.*
- flarum/core: ^1.3.1
Requires (Dev)
- flarum/phpstan: *
- flarum/tags: *
- fof/pages: *
Suggests
- flarum/tags: List tags in the sitemap
- fof/pages: List pages in the sitemap
Replaces
- dev-master
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.1
- 2.0.0
- 2.0.0-beta.2
- 2.0.0-beta.1
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.7.0
- 0.6.0
- 0.5.4
- 0.5.3
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.1
- 0.1.0
- 0.1.0-beta.1
- dev-dependabot/npm_and_yarn/js/cross-spawn-7.0.6
- dev-dk/on-demand-cached
- dev-luceos-patch-1
- dev-cw/use-named-routes
- dev-dk/multi-file
This package is auto-updated.
Last update: 2024-11-18 23:34:48 UTC
README
This extension simply adds a sitemap to your forum.
It uses default entries like Discussions and Users, but is also smart enough to conditionally add further entries based on the availability of extensions. This currently applies to flarum/tags and fof/pages. Other extensions can easily inject their own Resource information, check Extending below.
Modes
There are two modes to use the sitemap.
Runtime mode
After enabling the extension the sitemap will automatically be available and generated on the fly. It contains all Users, Discussions, Tags and Pages guests have access to.
Applicable to small forums, most likely on shared hosting environments, with discussions, users, tags and pages summed up being less than 10.000 items. This is not a hard limit, but performance will be degraded as the number of items increase.
Cached multi-file mode
For larger forums you can set up a cron job that generates a sitemap index and compressed sitemap files. A first sitemap will be automatically generated after the setting is changed, but subsequent updates will have to be triggered either manually or through the scheduler (see below).
A rebuild can be manually triggered at any time by using:
php flarum fof:sitemap:build
Best for larger forums, starting at 10.000 items.
Risky Performance Improvements
This setting is meant for large enterprise customers.
The optional "Enable risky performance improvements" option modifies the discussion and user SQL queries to limit the number of columns returned. By removing those columns, it significantly reduces the size of the database response but might break custom visibility scopes or slug drivers added by extensions.
This setting only brings noticeable improvements if you have millions of discussions or users. We recommend not enabling it unless the CRON job takes more than an hour to run or that the SQL connection gets saturated by the amount of data.
Scheduling
Consider setting up the Flarum scheduler, which removes the requirement to setup a cron job as advised above. Read more information about this here
The frequency setting for the scheduler can be customized via the extension settings page.
Installation
This extension requires PHP 8.0 or greater.
Install manually with composer:
composer require fof/sitemap
Updating
composer update fof/sitemap php flarum migrate php flarum cache:clear
Nginx issues
If you are using nginx and accessing /sitemap.xml
results in an nginx 404 page, you can add the following rule to your configuration file, underneath your existing location
rule:
location = /sitemap.xml {
try_files $uri $uri/ /index.php?$query_string;
}
This rule makes sure that Flarum will answer the request for /sitemap.xml
when no file exists with that name.
Extending
Register a new Resource
In order to register your own resource, create a class that implements FoF\Sitemap\Resources\Resource
. Make sure
to implement all abstract methods, check other implementations for examples. After this, register your
return [ new \FoF\Sitemap\Extend\RegisterResource(YourResource::class), ];
That's it.
Remove a Resource
In a very similar way, you can also remove resources from the sitemap:
return [ (new \FoF\Sitemap\Extend\RemoveResource(\FoF\Sitemap\Resources\Tag::class)), ];
Register a static URL
Some pages of your forum might not be covered by the default resources. To add those urls to the sitemap there is a
pseudo resource called StaticUrls
. You can use the RegisterStaticUrl
extender to add your own urls. The extender
takes a route name as parameter, which will be resolved to a url using the Flarum\Http\UrlGenerator
class.
return [ (new \FoF\Sitemap\Extend\RegisterStaticUrl('reviews.index')), ];
Force cache mode
If you wish to force the use of cache mode, for example in complex hosted environments, this can be done by calling the extender:
return [ (new \FoF\Sitemap\Extend\ForceCached()), ]
Commissioned
The initial version of this extension was sponsored by profesionalreview.com.