@@ -7,7 +7,7 @@ import { LiquidNode } from './types.js'
77
88const LIQUID_BLOCK_REGEX = / { % - ? .* ?- ? % } / gs
99const LIQUID_COMMENTS_REGEX = / { % - ? \s * c o m m e n t \s * - ? % } [ \S \s ] * ?{ % - ? \s * e n d c o m m e n t \s * - ? % } / gi
10- const LIQUID_RENDER_REGEX = / \s r e n d e r \s + ' ( [ ^ ' ] + ) ' / gs
10+ const LIQUID_RENDER_REGEX = / \s (?: r e n d e r | i n c l u d e ) \s + ' ( [ ^ ' ] + ) ' / gs
1111const ASSET_URL_REGEX = / { { \s * ' ( [ ^ ' ] + \. j s ) ' \s * \| \s * a s s e t _ u r l \s * } } / g
1212const SCRIPT_TAG_REGEX = / < s c r i p t [ ^ > ] * > [ \S \s ] * ?< \/ s c r i p t > / g
1313const SCRIPT_IMPORT_REGEX = / i m p o r t \s + [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / g
@@ -119,10 +119,27 @@ export async function getCollectionNodes(collectionDir: string): Promise<LiquidN
119119 return Promise . all ( [ ...collectionSnippets , ...collectionComponents , ...collectionAssets , ...collectionScripts , ...collectionSetup ] )
120120}
121121
122+ function findThemeFolder ( file : string , themeDir : string ) : LiquidNode [ 'themeFolder' ] {
123+ const themeFolders = new Set < LiquidNode [ 'themeFolder' ] > ( [ 'layout' , 'sections' , 'blocks' , 'templates' ] )
124+ let currentDir = path . dirname ( file )
125+
126+ while ( currentDir !== themeDir && currentDir !== path . dirname ( themeDir ) ) {
127+ const folderName = path . basename ( currentDir )
128+ if ( themeFolders . has ( folderName as LiquidNode [ 'themeFolder' ] ) ) {
129+ return folderName as LiquidNode [ 'themeFolder' ]
130+ }
131+
132+ currentDir = path . dirname ( currentDir )
133+ }
134+
135+ // Fallback to the immediate parent directory if no theme folder is found
136+ return path . basename ( path . dirname ( file ) ) as LiquidNode [ 'themeFolder' ]
137+ }
138+
122139export async function getThemeNodes ( themeDir : string ) : Promise < LiquidNode [ ] > {
123140 const entryNodes = globSync ( path . join ( themeDir , '{layout,sections,blocks,templates}' , '**/*.liquid' ) , { absolute : true } )
124141 . map ( file => {
125- const parentFolderName = path . basename ( path . dirname ( file ) ) as LiquidNode [ 'themeFolder' ]
142+ const parentFolderName = findThemeFolder ( file , themeDir )
126143 return generateLiquidNode ( file , 'entry' , parentFolderName )
127144 } )
128145 const themeSnippets = globSync ( path . join ( themeDir , 'snippets' , '**/*.liquid' ) , { absolute : true } )
0 commit comments