File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -480,11 +480,24 @@ function loadFromFile(filePath: string): ArticleInput {
480480
481481 const raw = readFileSync ( absPath , "utf-8" ) ;
482482 const { frontmatter, body } = parseFrontmatter ( raw ) ;
483- const slug = basename ( absPath , ".md" ) ;
483+ const slug = deriveSlug ( absPath ) ;
484484
485485 return { slug, frontmatter, body } ;
486486}
487487
488+ // Derive a manifest key from the file path. When the markdown file follows the
489+ // convention {article-slug}/devto.md, basename() alone gives "devto", which
490+ // collides across articles and causes silent overwrites in --update mode.
491+ // Fall back to the parent directory name for generic filenames; otherwise use
492+ // the filename as before (backwards-compatible for standalone .md files).
493+ function deriveSlug ( absPath : string ) : string {
494+ const base = basename ( absPath , ".md" ) ;
495+ if ( base === "devto" || base === "qiita" ) {
496+ return basename ( dirname ( absPath ) ) ;
497+ }
498+ return base ;
499+ }
500+
488501function loadFromDir ( dirPath : string ) : ArticleInput [ ] {
489502 const absDir = resolve ( dirPath ) ;
490503 if ( ! existsSync ( absDir ) ) {
Original file line number Diff line number Diff line change @@ -295,11 +295,24 @@ function loadFromFile(filePath: string): ArticleInput {
295295
296296 const raw = readFileSync ( absPath , "utf-8" ) ;
297297 const { frontmatter, body } = parseFrontmatter ( raw ) ;
298- const slug = basename ( absPath , ".md" ) ;
298+ const slug = deriveSlug ( absPath ) ;
299299
300300 return { slug, frontmatter, body } ;
301301}
302302
303+ // Derive a manifest key from the file path. When the markdown file follows the
304+ // convention {article-slug}/qiita.md, basename() alone gives "qiita", which
305+ // collides across articles and causes silent overwrites in --update mode.
306+ // Fall back to the parent directory name for generic filenames; otherwise use
307+ // the filename as before (backwards-compatible for standalone .md files).
308+ function deriveSlug ( absPath : string ) : string {
309+ const base = basename ( absPath , ".md" ) ;
310+ if ( base === "devto" || base === "qiita" ) {
311+ return basename ( dirname ( absPath ) ) ;
312+ }
313+ return base ;
314+ }
315+
303316function loadFromDir ( dirPath : string ) : ArticleInput [ ] {
304317 const absDir = resolve ( dirPath ) ;
305318 if ( ! existsSync ( absDir ) ) {
You can’t perform that action at this time.
0 commit comments