Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bradfloodx opened this issue Jul 14, 2021 · 6 comments
Open

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

bradfloodx opened this issue Jul 14, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@bradfloodx
Copy link

bradfloodx commented Jul 14, 2021

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
Copy link
Contributor

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

@AndrewHaine AndrewHaine added the bug Something isn't working label Jul 16, 2021
@bradfloodx
Copy link
Author

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
Copy link
Contributor

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

@AndrewHaine AndrewHaine added enhancement New feature or request and removed bug Something isn't working labels Jul 23, 2021
@bradfloodx
Copy link
Author

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

@tao
Copy link

tao commented Sep 9, 2021

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
Copy link

Have there been any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants