1- import { sep , resolve , join } from 'path' ;
1+ import { sep , resolve , join , parse } from 'path' ;
22import tildify from 'tildify' ;
33import Theme from '../theme' ;
44import Source from './source' ;
5- import { exists } from 'hexo-fs' ;
5+ import { exists , readdir } from 'hexo-fs' ;
66import { magenta } from 'picocolors' ;
77import { deepMerge } from 'hexo-util' ;
88import validateConfig from './validate_config' ;
@@ -12,12 +12,13 @@ export = async (ctx: Hexo): Promise<void> => {
1212 if ( ! ctx . env . init ) return ;
1313
1414 const baseDir = ctx . base_dir ;
15- const configPath = ctx . config_path ;
15+ let configPath = ctx . config_path ;
1616
17- const configExists = await exists ( configPath ) ;
18- if ( ! configExists ) return ;
17+ const path = await exists ( configPath ) ? configPath : await findConfigPath ( configPath ) ;
18+ if ( ! path ) return ;
19+ configPath = path ;
1920
20- let config = await ctx . render . render ( { path : configPath } ) ;
21+ let config = await ctx . render . render ( { path } ) ;
2122 if ( ! config || typeof config !== 'object' ) return ;
2223
2324 ctx . log . debug ( 'Config loaded: %s' , magenta ( tildify ( configPath ) ) ) ;
@@ -63,3 +64,11 @@ export = async (ctx: Hexo): Promise<void> => {
6364 ctx . theme_script_dir = join ( ctx . theme_dir , 'scripts' ) + sep ;
6465 ctx . theme = new Theme ( ctx , { ignored } ) ;
6566} ;
67+
68+ async function findConfigPath ( path : string ) : Promise < string > {
69+ const { dir, name } = parse ( path ) ;
70+
71+ const files = await readdir ( dir ) ;
72+ const item = files . find ( item => item === name + '.json' ) ;
73+ if ( item != null ) return join ( dir , item ) ;
74+ }
0 commit comments