WithCandour / statamic-aardvark-seo

Candour's SEO addon for Statamic
https://statamic.com/marketplace/addons/aardvark-seo
11 stars 18 forks source link

Generating Sitemap XML files for SSG (Static Site Generator) #92

Open bradfloodx opened 3 years ago

bradfloodx commented 3 years ago

Hi :)

I'm yet to find information on exporting the sitemap XML files for a static site using Statamic's SSG package.

When I run php please ssg:generate the outputted static files have no sitemaps, which makes sense because they are dynamically generated.

But I've tried including the routes in the SSG config, such as /sitemap.xml in config/statamic/ssg.php => urls array, but that doesn't help.

It's looking like I will have to write a custom script to fetch the /sitemap.xml, parse it and fetch other sitemap files too, and then write them to file in the SSG output folder.

Am I missing something? I imagine I'm not the only one using Aardvark SEO and SSG together?

Cheers and thank you for your time. 🍻

AndrewHaine commented 3 years ago

Hey @bradleyflood ,

Thank you for flagging this for us, we've not done a massive amount of testing with the SSG package but you're absolutely right that this is something that should be supported by Aardvark so I'll schedule in some time on our end to take a look into this.

Thanks, Andrew

bradfloodx commented 3 years ago

Thanks @AndrewHaine

This might help you, or someone else. I wrote a Node script that is run during the composer build step which fetches the sitemap files from my local Statamic instance, replaces the paths to production paths, and then writes them to file in the SSG output directory.

See gist here https://gist.github.com/bradleyflood/b77944f5ef486c2da3ce5038cb348146

Cheers. Love your work! Aardvark is great.

AndrewHaine commented 3 years ago

Hey @bradleyflood ,

Thank you for sending that over. I've been digging into the SSG addon a bit and it looks like we're able to register custom callbacks for when the SSG command is executed, i've opened a task internally for us to schedule some time in to write an integration for Aardvark - will reply here once we've got something in place!

Thanks, Andrew

bradfloodx commented 3 years ago

Cool thanks @AndrewHaine. If you need a beta tester I'm available. Cheers.

tao commented 3 years ago

There is a simple way to merge the sitemap urls with SSG, just need to find out how any assets or other files might need to be required... but I'm still experimenting with the addon.

<?php

namespace App\Providers;

use WithCandour\AardvarkSeo\Sitemaps\Sitemap;
use Statamic\StaticSite\SSG;

class AppServiceProvider extends ServiceProvider
{
     public function boot() {
        SSG::addUrls(function () {

            // get an array with local urls ['sitemap.xml', 'sitemap_articles.xml', 'etc']
            // sitemaps will still include APP_URL in the results
            $sitemaps = collect(Sitemap::all())->pluck('route')->push('sitemap.xml', 'aardvark-sitemap.xsl')->all();

            return array_merge(
                $sitemaps,
                // my other urls
            );
        });
     }

     ...
}

It seems like the vendor files are copied over automatically:

storage/app/static/vendor/aardvark-seo
├── css
│   └── aardvark-seo.css
└── js
    └── aardvark-seo.js
devonbeard commented 2 years ago

Have there been any updates on this?