Fryuni / inox-tools

Oxygen-free tools for Astronauts.
https://inox-tools.fryuni.dev
MIT License
48 stars 1 forks source link

Sitemap await not... well, waiting... #141

Open petethered opened 1 month ago

petethered commented 1 month ago

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?

Fryuni commented 1 month ago

Nothing immediately jumps to me as missing or wrong; that should be working.

I'll try to reproduce it locally and fix it. Thanks for reporting 😄

petethered commented 4 weeks ago

Thanks!

I can throw together a small project to be a full replication if you'd like. It's really just the one line

const response = await fetch(`http://server/staticGenerator/items?allId=1`);

That's the issue and not running during the build.

I BELIEVE i tried copying the fetch call directly into the sitemap(async instead of using external, but the external is getting invoked just there's no wait for the promise... it just bails out silently.

Fryuni commented 4 weeks ago

Is the server the project being built or something external?

petethered commented 4 weeks ago

It's an external URL (ie http://example.com/staticGenerator/items?allId=1)

I've tried building on both local and having cloudflare build it.

I've made sure no experimental flags are enabled.

I upgraded to the latest astro.

    "@astrojs/tailwind": "^5.1.0",
    "@faker-js/faker": "^7.3.0",
    "astro": "^4.14.2",
    "daisyui": "^4.4.23",
    "globby": "^11.0.4",
    "prettier": "^2.8.8",
    "prettier-plugin-astro": "^0.0.12"
  },
  "dependencies": {
    "@astrojs/cloudflare": "^11.0.4",
    "@astrojs/preact": "^3.5.1",
    "@astrojs/react": "^3.6.2",
    "@astrojs/sitemap": "^3.1.6",
    "@inox-tools/sitemap-ext": "^0.3.2",
    "@preact/signals": "^1.3.0",
    "@types/react": "^18.0.10",
    "@types/react-dom": "^18.0.5",
    "astro-tabs": "^0.1.8",
    "astro-vtbot": "^1.8.4",
    "preact": "^10.23.1",
    "sass": "^1.69.5"
  }
import preact from "@astrojs/preact";
import tailwind from "@astrojs/tailwind";

//import sitemap from "@astrojs/sitemap";
import sitemap from '@inox-tools/sitemap-ext';

// https://astro.build/config
import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
  // Enable React to support React JSX components.
  experimental: {
  //  contentCollectionCache: true
  },
  site: 'https://recentmusic.com',
  integrations: [preact(), tailwind({
    config: {
      path: "./tailwind.config.js"
    }
  }), sitemap({
    includeByDefault: true,
  })],
  output: "server",
  adapter: cloudflare()
});
petethered commented 3 weeks ago

https://github.com/petethered/sitemap-ext-test-case

Here you go, full replication case.

https://github.com/petethered/sitemap-ext-test-case/blob/main/src/pages/divisions/%5Bid%5D.astro