Skip to content

Commit

Permalink
fix: include user-defined components.fileExtension in list of compo…
Browse files Browse the repository at this point in the history
…nent file extensions to scan for
  • Loading branch information
cossssmin committed Nov 29, 2024
1 parent 218c1c3 commit 005e2ee
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
20 changes: 19 additions & 1 deletion src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,25 @@ export default async (config = {}) => {

const html = await readFile(templatePath, 'utf8')

const rendered = await render(html, config)
/**
* Render the markup.
*
* Merging a custom `components` object to make sure that file extensions from both
* `build.content` * and * `components.fileExtension` are used for components.
*/
const userComponentFileExtensions = get(config, 'components.fileExtension', ['html'])

const rendered = await render(html, merge(
{
components: {
fileExtension: [
...outputExtensions,
...(new Set([].concat(userComponentFileExtensions))),
],
}
},
config
))

/**
* Generate plaintext
Expand Down
2 changes: 1 addition & 1 deletion src/posthtml/defaultComponentsConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
root: './',
tag: 'component',
fileExtension: 'html',
fileExtension: ['html'],
folders: [
'layouts',
'emails',
Expand Down
31 changes: 19 additions & 12 deletions src/posthtml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,32 @@ export async function process(html = '', config = {}) {
)
)

const componentsConfig = merge(
{
expressions: merge(
{ locals },
expressionsOptions,
)
},
componentsUserOptions,
defaultComponentsConfig
)

// Ensure `fileExtension` is array and has no duplicates
componentsConfig.fileExtension = [...new Set(
Array.isArray(componentsConfig.fileExtension)
? componentsConfig.fileExtension
: [componentsConfig.fileExtension]
)]

return posthtml([
...get(config, 'posthtml.plugins.before', []),
envTags(config.env),
envAttributes(config.env),
expandLinkTag,
postcssPlugin,
fetchPlugin,
components(
merge(
{
expressions: merge(
{ locals },
expressionsOptions,
)
},
componentsUserOptions,
defaultComponentsConfig
)
),
components(componentsConfig),
expandLinkTag,
postcssPlugin,
envTags(config.env),
Expand Down

0 comments on commit 005e2ee

Please sign in to comment.