Skip to content

Catalog feeds for Yandex and Avito

The products the owner edits in Seamlet the site gives to advertising and marketplaces: Яндекс Директ (Yandex Direct, Yandex’s ad network, with its product campaigns), Яндекс Бизнес (Yandex Business) and Маркет (Yandex Market) take a catalog in the YML format, and Авито (Avito, a Russian classifieds marketplace) takes an autoload file. The site builds the feeds itself, at every build, from the published content: change a price in Seamlet and publish — the feed is updated.

It needs @seamlet/astro 1.5 or newer.

src/pages/feeds/yandex.xml.ts
import { productOffersOf, yandexFeedOf } from "@seamlet/astro/feeds";
import site from "../../seamlet";
import { productPages } from "../../schema";
const SITE_URL = "https://example.ru";
export async function GET() {
const content = await site.loadPublishedContent();
const offers = productOffersOf(content.catalog.products, {
siteUrl: SITE_URL,
pathOf: productPages.pathOf,
});
const feed = yandexFeedOf(
{
name: "Моя мастерская",
company: "ООО «Ромашка»",
url: SITE_URL,
},
offers,
new Date(),
);
return new Response(feed, {
headers: { "Content-Type": "application/xml; charset=utf-8" },
});
}

The file appears at https://example.ru/feeds/yandex.xml — that is the address you give in Direct or Business.

productOffersOf works with records of productFields: it takes the name, the price, the photos (the first is the main one), the description (or the summary if there is no description) and the address of the product’s page. Hidden products («Скрыть с сайта», Hide from the site) do not go into the feed, nor do products without a price: Yandex does not accept them. If the products have no pages of their own, pass catalogPath: "/catalog" instead of pathOf. Categories come through categoryOf, for example the name of a category from a reference to a record. categoryOf gets a product with the fields of productFields and none of yours, so your own field is read from the record with the same id:

productOffersOf(products, {
siteUrl: SITE_URL,
pathOf: productPages.pathOf,
categoryOf: (product) => {
const categoryId = products.find(({ id }) => id === product.id)?.category;
return content.categories.find(({ id }) => id === categoryId)?.name;
},
});

Turn a catalog of other fields — not productFields — into offers yourself: a FeedOffer is an id, a name, a url, a price, a description, pictures and an optional category.

src/pages/feeds/avito.xml.ts
import { avitoFeedOf, productOffersOf } from "@seamlet/astro/feeds";
// …as for Yandex, then:
const feed = avitoFeedOf(
{
address: "Киров, ул. Лесная, 1",
contactPhone: "+7 912 000-00-00",
category: "Ремонт и строительство",
},
offers,
() => ({ GoodsType: "Готовые строения", AdType: "Товар от производителя" }),
);

Every category of Avito has its own required fields — the autoload reference in Avito’s account lists them. The third argument adds them to every ad: fixed ones or ones from the record’s fields. Avito cuts a title to 50 characters — avitoFeedOf cuts it at a word, and takes no more than ten photos.

On a static hosting the feeds are built together with the pages. If the site is rebuilt at every publication in Seamlet (publishing), the feeds have the same prices as the site.