inox-tools icon indicating copy to clipboard operation
inox-tools copied to clipboard

Sitemap await not... well, waiting...

Open petethered opened this issue 6 months ago • 5 comments

I'm trying to convert a SSG to SSR and found your extension which has been solving some of my sitemap issues. Thanks!

That being said, I'm running into issues trying to pull a list of ids to include in the sitemap for

During build, the await for fetch doesn't seem to be waiting.

[id].astro

import { fetchIds } from "../../data/items";
import sitemap from 'sitemap-ext:config';
sitemap(async ({ addToSitemap }) => {
  console.log("PreFetch");
  const ids = await fetchIds();
  console.log(ids);
  addToSitemap(
    ids?.data?.ids?.map((post) => ({
      id: post,
    }))
  );
});

items.ts

  try {
    console.log(`http://server/staticGenerator/items?allId=1`);
    const response = await fetch(`http://server/staticGenerator/items?allId=1`);
    console.log("Res: ", response);
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    const data = await response.json();
    return data;
  } catch (error) {
    console.error("Error", error);
    return {};
  }
};

Running build shows the "PreFetch", and the url in the console log, but nothing happens... the request isn't made.

Mind telling me what I'm missing?

petethered avatar Aug 13 '24 19:08 petethered