jlarmstrongiv / astro-i18n-aut

The i18n integration for Astro 🧑‍🚀
https://www.npmjs.com/package/astro-i18n-aut
MIT License
125 stars 12 forks source link

add default excluding rule for consistency with Astro #30

Closed MarvinXu closed 1 year ago

MarvinXu commented 1 year ago

close #29

jlarmstrongiv commented 1 year ago

Have you tested that exclusion?

I guess the reason I’m worried is that the exclusion applies to the build command, where astro-i18n-aut duplicates the pages directory, using the include and exclude globs.

The reason astro-i18n-aut is strict about pages is because the pages directory duplicated for every locale on build—it’s better for other files like image, tests, and utility files to live somewhere else (preferably a components, utilities, or tests directory on the same level as pages).

It also means that if _files are in the exclude glob, they would not be copied for each locale pages directory. If a page imports an _file, there would be a cryptic error that _file does not exist and cannot be found, because it was excluded from each locale directory copy.


In summary, Astro uses pages prefixed with _ to:

You can use this to temporarily disable pages, and also to put tests, utilities, and components in the same folder as their related pages.

However, due to astro-i18n-aut internals, I strongly recommend putting tests, utilities, and components in a different directory.

A case could be made for excluding pages that start with _, but then there would be cryptic error messages when none of the utilities and components exist.


What are your thoughts? I think the solution may be updating the README stating that excluding pages with _ is not supported.

jlarmstrongiv commented 1 year ago

@MarvinXu I added a compatibility note in the README

https://github.com/jlarmstrongiv/astro-i18n-aut#excluding-pages

I wish I could make this integration fully compatible, but I am limited by the APIs and support Astro core provides. I hope the clarification helps!

MarvinXu commented 1 year ago

Thanks for the reply! I'm sorry this is just a quick PR and is immature, but I just wanted to get involved and learn from your ideas.

It seems astro-i18n-aut is taken over the dev and build steps rather than adding some configs to its original behavior.

but I am limited by the APIs and support Astro core provides

Is it because of this?

jlarmstrongiv commented 1 year ago

@MarvinXu no worries! Creating an issue is a good first step and PRs are always appreciated. Too bad the fix wasn’t that simple.

If you’re interested in the internals, this library depends on the injectRoute Astro Integration API. Unfortunately, injectRoute has changed its behavior in minor updates, making it difficult to use in this library. For example, injectRoute broke dev mode in 2.x because their module resolution changed, and the same entry point can no longer be used for multiple patterns. Plus, injectRoute behaves differently with the dev command vs the build command. Still, at least it works, unlike the other workarounds I tried.

Feel free to read the source code too