#Parse links from generated HTML files in integration

3 messages · Page 1 of 1 (latest)

covert sail
#

I am in the process of creating an integration that requires links between pages. Since some of these links only exist after the page thas been compiled/built, I would need to add a hook in the astro:build:done step.

However, I'd want to have the build process run again (with my now complete script) so the site is properly built. How would I do this programatically? (The settings of the build should be the same!)

waxen wigeonBOT
#

Hi @covert sail. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Astro provides hooks that integrations can implement to execute during certain parts of Astro’s lifecycle. In your case, you can use the astro:build:generated hook which is executed after a static production build has finished generating routes and assets. This hook allows you to access generated routes and assets before build artifacts are cleaned up.

Here is how you can define this hook in your integration:

'astro:build:generated'?: (options: { dir: URL }) => void | Promise<void>;

However, this is a very uncommon use case and Astro recommends using astro:build:done unless you really need to access the generated files before cleanup.

As for running the build process again programmatically with the same settings, Astro does not provide a built-in way to do this. You would need to manually trigger the build process again from your script.

Please note that the paths of the generated files change based on the OS where the code runs.

For more information, you can refer to the Astro Integration API documentation (https://docs.astro.build/en/reference/integrations-reference/#astrobuildgenerated).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: