nystudio107 / craft-seomatic

SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
https://nystudio107.com/plugins/seomatic
Other
165 stars 70 forks source link

[FR] Manually generate sitemaps (cli and/or CP) #267

Closed timkelty closed 5 years ago

timkelty commented 6 years ago

It would be great is Seomatic shipped with a CLI command to regenerate sitemaps, instead of having to trigger it via save/request.

khalwat commented 5 years ago

Sure, probably with a setting to disable the automatic generation as well.

timkelty commented 5 years ago

Sure, probably with a setting to disable the automatic generation as well.

Indeed!

Is it currently tied into seomatic.config.environment at all?

khalwat commented 5 years ago

There will be a global Automatically Generate Sitemaps that you can enable/disable via the multi-environment config.

If you disable it, it's up to you to ensure that the sitemaps get regenerated, either via GUI or via CLI

ryanmasuga commented 5 years ago

We are very much on board with this.

We have a client that manages almost all their content in Airtable, and then imports to Craft. This triggers the sitemaps, and on channels that have 1000's of entries, which is simply taking too long, and happening too frequently.

I could suggest that sitemaps aren’t important enough to warrant updating them more than 1 time a day, in the middle of the night, for example. So, the proposed solution sounds good to me.

khalwat commented 5 years ago

So that should not happen if you set the scenario of the elements you're importing to Element::SCENARIO_ESSENTIALS the way Craft does for resaving elements:

$element->setScenario(Element::SCENARIO_ESSENTIALS);

https://github.com/craftcms/cms/blob/develop/src/queue/jobs/ResaveElements.php#L72

khalwat commented 5 years ago

The problem with "once a day, during the middle of the night" is that it requires cron in the mix. Which I'm cool with if you're advanced enough to want to set that up, and this issue should solve it. You can just run the sitemap generation via CLI command.

For everyone else, I think the automatic solution needs to be in there.

ryanmasuga commented 5 years ago

I agree on that. We're happy to set up a cron job, but for as many people as use this plugin, there should be something automatic.

khalwat commented 5 years ago

I've added the ability to disable the automatic sitemap regeneration via Seomatic->Settings in the build in dev-develop. It still invalidates the cache, so subsequent loads of the sitemap itself will cause it to regenerate, unless runQueueAutomatically is false

I just need to:

khalwat commented 5 years ago

Added to the docs:

.....

Sitemap Generation

Because XML sitemaps can be quite time-intensive to generate as the number of entries scales up, SEOmatic creates your sitemaps via a Queue job, and caches the result. The cache is automatically broken whenever something in that sitemap is changed, and a new Queue job is created to regenerate it.

If runQueueAutomatically is set to false in General Config Settings the Queue job to create the sitemap will not be run during the http request for the sitemap. You'll need to run it manually via whatever means you use to run the Queue.

Normally SEOmatic will regenerate the sitemap for a Section, Category Group, or Product any time you save an element. However, if you are importing a large number of elements, or prefer to regenerate the sitemap manually you can set disable the Regenerate Sitemaps Automatically option in SEOmatic's Plugin Settings.

You can then regenerate the sitemap via CLI. This will regenerate all sitemaps:

./craft seomatic/sitemap/generate

You can also limit it to a specific Section, Category Group, or Product handle:

./craft seomatic/sitemap/generate --handle=blog

...or you can regenerate all sitemaps for a specific siteId:

./craft seomatic/sitemap/generate --siteId=1

...or both:

./craft seomatic/sitemap/generate --handle=blog --siteId=1

N.B.: If you do disable Regenerate Sitemaps Automatically sitemaps will not be updated unless you do so manually via the CLI, or clear SEOmatic's sitemap caches via Utilities->Clear Caches.

khalwat commented 5 years ago

Implemented in https://github.com/nystudio107/craft-seomatic/commit/ddb75303c5ea5a9910f592cfd472dd7faac98597

khalwat commented 5 years ago

Implemented in https://github.com/nystudio107/craft-seomatic/releases/tag/3.1.31

Please see the docs here: https://github.com/nystudio107/craft-seomatic#sitemap-generation

timkelty commented 5 years ago

If runQueueAutomatically is set to false in General Config Settings the Queue job to create the sitemap will not be run during the http request for the sitemap.

But the job will still be added, just not run, yes?

khalwat commented 5 years ago

Correct. If the Craft General.php preference runQueueAutomatically is true it will create the job when elements are changed, or the sitemap is accessed and doesn't have a cache, but it will not run it. That's on you.

However, if you set the preference Regenerate Sitemaps Automatically to false then it will not even create the job to regenerate a sitemap after an element has been saved.