Marketing

Storefront sitemaps for GoCommerce

A Go package that publishes the storefront’s sitemap from the live catalogue — every active product and collection, and every published page when the cms module is installed. It needs one setting: where the storefront lives.

What it does

The module serves a sitemap index at /x/sitemaps/sitemap.xml and the files it points at: products.xml, collections.xml and, with the cms module installed, pages.xml. Every URL carries the day the thing it names last changed.

The engine does not know where its storefront lives, so, as the package doc puts it, the address is a setting — and so are the paths, because storefronts differ on whether a product lives at /products/{slug} or /p/{slug}. A storefront serves /sitemap.xml by proxying or redirecting to the index.

The files are generated on request from the live catalogue and cacheable for an hour. Each carries a stylesheet instruction, so a person who opens one in a browser sees a table of what is listed rather than raw XML; crawlers ignore it.

Configuration

One setting is required: the storefront’s URL. With it in Config the module starts switched on; otherwise switch it on and fill it in on the Plugins screen, which wins where both say something.

Sitemaps module settings — 4 settings, 1 required
SettingEnvironment variableRequiredWhat it does
StorefrontURL
Storefront URL
STOREFRONT_URL Yes Where the pages live, e.g. https://shop.example. Until it is set the sitemap answers 409 and says so; while the plugin is off, 404.
ProductPath
Product page path
— No The product page’s path with {slug} in it. Defaults to /products/{slug}; set it on the Plugins screen — see the limits.
CollectionPath
Collection page path
— No The collection page’s path. Defaults to /collections/{slug}.
PagePath
Content page path
— No The content page’s path, used when the cms module is installed. Defaults to /pages/{slug}.

The module reads its Config struct, not the environment. The variable names are the ones the package’s own example or the reference binary uses; in your own main() you choose where each value comes from. Where a setting has a panel label, the admin’s settings drawer can hold it too, and a value typed there wins over Config.

Setting it up

  1. Install the moduleImport it and pass sitemaps.New to gocommerce.New, as below — or run the reference binary with -sitemaps, which reads STOREFRONT_URL.
  2. Set the storefront and pathsThe storefront URL, and the product, collection and page paths if your storefront’s differ from the defaults, on the Plugins screen.
  3. Point /sitemap.xml at itHave the storefront proxy or redirect /sitemap.xml to /x/sitemaps/sitemap.xml — and /x/sitemaps/ too, since the index links to the files there.
  4. Check it, then submit itOpen the index in a browser: the stylesheet shows what is listed. Then submit the storefront’s /sitemap.xml to the search engines.

main.go

import (
	"os"

	"github.com/itswadesh/gocommerce/core"
	"github.com/itswadesh/gocommerce/ext/sitemaps"
)

app, err := gocommerce.New(cfg,
	sitemaps.New(sitemaps.Config{StorefrontURL: os.Getenv("STOREFRONT_URL")}),
)

As the repository’s examples/store/main.go wires it, with its imports; cfg is your gocommerce.Config. The package doc itself has no example. Import path github.com/itswadesh/gocommerce/ext/sitemaps.

How it works

What it does not do

Read these before an order depends on it. No store is known to run GoCommerce in production yet, so these come from the code, not from anyone’s experience.

FAQ

Questions about the Sitemaps module

Why is the sitemap served by the API and not the storefront?

Because the catalogue lives there. The engine builds the files from live data; the storefront serves /sitemap.xml by proxying or redirecting to /x/sitemaps/sitemap.xml, as the package doc describes.

My product pages are at /p/{slug}. What do I change?

The product page path, on the Plugins screen. Set it there rather than in Config: the panel’s default of /products/{slug} is read first, so a path in Config is never used.

Does it list content pages?

When the cms module is installed. The index then includes pages.xml, with every published page; without the cms module, pages.xml answers 404 and the index leaves it out.

How fresh is it?

As fresh as the catalogue: every file is built on request, and marked cacheable for an hour.

Does it need Svelte Commerce?

No. Any storefront that can proxy or redirect /sitemap.xml can use it; the paths are settings precisely because storefronts differ.

Source

Everything on this page is read from ext/sitemaps in the GoCommerce repository, MIT licensed. When this page and the code disagree, the code is right and this page is out of date.

Try it against a store of your own

The one-command stack gives you GoCommerce’s API and admin on your own machine in minutes. Add this module to it and try it on test orders before a real one depends on it.

Chat on WhatsApp