iamvishnusankar / next-sitemap

Sitemap generator for next.js. Generate sitemap(s) and robots.txt for all static/pre-rendered/dynamic/server-side pages.
https://next-sitemap.iamvishnusankar.com
MIT License
3.28k stars 127 forks source link

Some SSR pages not being added to XML output #470

Closed avcohen closed 1 year ago

avcohen commented 2 years ago

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.

distributeddev commented 1 year ago

I am having same issue, Can someone please help?

f2016862 commented 1 year ago

Same issue, only few pages are added as sitemap, rest are not

mihanc commented 1 year ago

Same issue, only few pages are added as sitemap, rest are not

I'm facing the same issue. Have you found a solution?

github-actions[bot] commented 1 year ago

Closing this issue due to inactivity.

razzeee commented 1 year ago

I'm also puzzled by this and can't see any difference in what I'm doing on the pages, where this works, vs the ones where it doesn't

github-actions[bot] commented 1 year ago

Closing this issue due to inactivity.

razzeee commented 1 year ago

I can still reproduce this

noutijo commented 1 year ago

I am having the same issue, only a few pages are added as a sitemap, rest are not.

OneX commented 1 year ago

Still an issue.

github-actions[bot] commented 1 year ago

Closing this issue due to inactivity.