-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💡 RFC: Allow exports from astro components #1142
Comments
This is a pattern that's already used in 'astro/www' but with a hand-rolled index page rather than with support for collections! |
This is actually possible and intentionally disabled right now. you can see the filtering happening in
I think the only question would be: what should the response object format look like? Right now, because its always Markdown it's always the same object, complete with markdown frontmatter as properties on the object. If a proposal could include a design for the |
It'd be great to both allow the object to contain the exports from the astro file + synthetic exports like .headings and .content and .content.raw like markdown that would be generated by astro! |
I still want to experiment with the idea of everything exported getting pulled out of the component instance scope and into the module scope! But right now, since exports aren't supported, there's not much we can do here. |
I don't have much of an opinion in terms of a proposal, but I would really love to see this feature as well. I'm currently building more complicated posts/pages in a |
I don't think parsing out synthetic things from an astro component would be possible. An imported component is different from a rendered component. We wouldn't know things like headings until it's been rendered. But I am still +1 for the more narrowly focused proposal to allow exports from Astro components and then expose those. |
For sure, simply getting support for exports from astro files would be superb! |
Astro.fetchContent
for astro pages.
@jasikpark just updated your title, would love to work with you on this proposal if you're interested @jasikpark! For the record there was some previous discussion in #619 that we can borrow from. This exact feature was out of scope for that proposal, so now that we've aligned on component script scoping I'd love to focus on this more specifically. Naively, I love the idea of "all exports hoisted out of the component scope" + "a lint pass to make sure that nothing in the component scope is referenced from a hoisted export, and error if it does". We need this for |
Absolutely! I am not equipped with the knowledge of how to implement this, but I would love to be able to bring this to fruition! |
This issue is titled "Allow exports from astro pages" but I'm assuming this applies to exports from any |
yes! updated. Also @jasikpark I made some additions to the issue but have not yet cleaned it up or proposed a full design |
RFC Discussion Notes:
Decision: approved! (but obviously needs docs) |
The TC39 Spec on top-level await, since it's relevant to any caveats in the new compiler |
Example of it working! https://codesandbox.io/s/serene-wright-gwc6q?file=/src/components/AllowsExports.astro |
I wonder if |
I'm just beginning to check out astro and I came across this while looking for how a page that is used for a listing might either filter pages that were created via a dynamic route or share the data that was loaded in I don't think this is really equivalent, but something along the lines of how Hugo can list from |
Hey everyone! This RFC is still accepted, and it has been moved to https://github.com/withastro/rfcs/blob/main/active-rfcs/support-exports-from-astro-components.md In an effort to improve our RFC process, we made some changes to better organize things, which include a dedicated RFC repository. |
FYI, anyone looking now, here is a permalink, as the one above is outdated: https://github.com/withastro/rfcs/blob/58749fdcc29f4da9c160a428b907c2b03780aa12/active-rfcs/0005-support-exports-from-astro-components.md |
Background & Motivation
Related to #491
I think an interesting pattern we could support is allowing astro files to export data:
Astro.fetchContent("**/*.astro")
would return a similar object toAstro.fetchContent("**/*.md")
allowing components in markdown without too much effort..import {...} from './SomeComponent.astro'
would return these exports.Proposed Solution
getStaticPaths()
today).import {someExportedConst} from './Main.astro';
)Astro.fetchContent
to now support Astro components and pages as well.Possible solutions
Alternatives considered
Risks, downsides, and/or tradeoffs
Open Questions
I think I remember #309 ending with a comment that scoping would be complicated to solve?
Detailed Design
No response
Help make it happen!
The text was updated successfully, but these errors were encountered: