next-sitemap icon indicating copy to clipboard operation
next-sitemap copied to clipboard

Some SSR pages not being added to XML output

Open avcohen opened this issue 2 years ago • 0 comments

Describe the bug Only some SSR Pages are being included in the sitemap XML output.

In my case, I have two paths that generate SSR pages: /learn/index.tsx /products/[slug].tsx

While the /learn/index.tsx page appears within the XML output, /products/[slug].tsx pages do not.

Both of these files are exporting getServerSideProps.

To Reproduce Steps to reproduce the behavior:

// next-sitemap.js
module.exports = {
    siteUrl: process.env.WEBSITE_URL,
    generateRobotsTxt: true,
    exclude: ['/api/*'],
    robotsTxtOptions: {
        policies: [
            {
                userAgent: '*',
                allow: '/',
                disallow: '/api/*',
            },
        ],
    },
};

Pages truncated + logic contrived:

// pages/learn/index.tsx

export const getServerSideProps: GetServerSideProps = async ({ query, preview = false }) => {
    const tag = query.tag;
    const pageQuery = groq`...`;
    const data = await getPage(pageQuery, { tag: tag || '' }, preview);

    return {
        props: {
            data,
            preview,
        },
    };
};

function BlogIndex({ data, preview }: Props) {
    const { site, page } = data;

    return (
        <Layout site={site} page={page} preview={preview}>
            <Modules modules={page.modules} site={site} />
        </Layout>
    );
}

export default BlogIndex;

export const getServerSideProps: GetServerSideProps = async ({ params, preview = false }) => {
    const slug = params?.slug;
    const slugs = [`/${slug}`, slug, `/${slug}/`];
    const pageQuery = groq`...`;
    const data = await getPage(pageQuery, { slugs }, preview);

    const gid = encode('Product', data.page.store.id);
    const productData: ShopifyProduct = await shopifyClient.product.fetch(gid);

    const product = {
        id: decode(productData.id).id,
        variants: productData.variants.map((v) => ({ id: decode(v.id).id, available: v.available })),
    };

    return {
        props: {
            data,
            product,
            preview,
        },
    };
};

function Product({ data, product, preview }: Props) {
    const { site, page } = data;

    return (
        <Layout site={site} page={page} preview={preview}>
            <Modules modules={page.modules} site={site} />
        </Layout>
    );
}

export default Product;

Expected behavior I would expect all SSR pages to be included.

avcohen avatar Aug 21 '22 16:08 avcohen