Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion scripts/cross-post-devto.mts
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,24 @@ function loadFromFile(filePath: string): ArticleInput {

const raw = readFileSync(absPath, "utf-8");
const { frontmatter, body } = parseFrontmatter(raw);
const slug = basename(absPath, ".md");
const slug = deriveSlug(absPath);

return { slug, frontmatter, body };
}

// Derive a manifest key from the file path. When the markdown file follows the
// convention {article-slug}/devto.md, basename() alone gives "devto", which
// collides across articles and causes silent overwrites in --update mode.
// Fall back to the parent directory name for generic filenames; otherwise use
// the filename as before (backwards-compatible for standalone .md files).
function deriveSlug(absPath: string): string {
const base = basename(absPath, ".md");
if (base === "devto" || base === "qiita") {
return basename(dirname(absPath));
}
return base;
}

function loadFromDir(dirPath: string): ArticleInput[] {
const absDir = resolve(dirPath);
if (!existsSync(absDir)) {
Expand Down
15 changes: 14 additions & 1 deletion scripts/cross-post-qiita.mts
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,24 @@ function loadFromFile(filePath: string): ArticleInput {

const raw = readFileSync(absPath, "utf-8");
const { frontmatter, body } = parseFrontmatter(raw);
const slug = basename(absPath, ".md");
const slug = deriveSlug(absPath);

return { slug, frontmatter, body };
}

// Derive a manifest key from the file path. When the markdown file follows the
// convention {article-slug}/qiita.md, basename() alone gives "qiita", which
// collides across articles and causes silent overwrites in --update mode.
// Fall back to the parent directory name for generic filenames; otherwise use
// the filename as before (backwards-compatible for standalone .md files).
function deriveSlug(absPath: string): string {
const base = basename(absPath, ".md");
if (base === "devto" || base === "qiita") {
return basename(dirname(absPath));
}
return base;
}

function loadFromDir(dirPath: string): ArticleInput[] {
const absDir = resolve(dirPath);
if (!existsSync(absDir)) {
Expand Down
Loading