-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from tony-sull/fix/blok-name-resolution
fix: supports blok names that aren't valid JS variable names
- Loading branch information
Showing
4 changed files
with
51 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
--- | ||
import components from "virtual:storyblok-components"; | ||
import camelcase from "camelcase"; | ||
const { blok, ...props } = Astro.props; | ||
const Component = components[blok.component]; | ||
/** | ||
* convert blok components to camel case to match vite-plugin-storyblok | ||
*/ | ||
const key = camelcase(blok.component); | ||
if (!(key in components)) { | ||
/** | ||
* Component not found! Log an error with details on the blok name that could not be found | ||
* TODO: Add support for a placeholder component as a fallback? | ||
*/ | ||
throw new Error( | ||
`Component could not be found for blok "${blok.component}"! Is it defined in astro.config.mjs?` | ||
); | ||
} | ||
const Component = components[key]; | ||
--- | ||
|
||
<Component blok={blok} {...props} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.