Skip to content

Can I put the props of an island in a separate js file instead of the HTML file? #202

Answered by ElMassimo
ouuan asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Yufan!

This is an interesting use case. In îles props are inlined in HTML, there's no built-in way to store them as JS instead.

You can get the data of useDocuments using an internal API, by adding an import like the following inside a script that you import from the island:

import documents from '/@islands/documents?pattern=~/pages/{post/**/*,about}.{md,mdx}'

That way, that data would be stored in JS, and you could even use a dynamic import to load it asynchronously.


If you want to get more control by creating a Vite plugin, you can use the pages API to get the frontmatter, meta, and excerpt, and read the raw file as you are doing now.

The downside of this search technique, is that t…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ouuan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants