Skip to content

Commit 37d23f8

Browse files
committed
fix: drafts cannot be fetched and should be re-published every time
1 parent 9243c85 commit 37d23f8

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/article.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,28 @@ export class Article {
8080

8181
let remoteArticleBodyMarkdown: string | null;
8282

83-
try {
84-
remoteArticleBodyMarkdown = await this.fetchArticleBodyMarkdown(this.articleConfig.id);
85-
} catch (error) {
86-
return {
87-
updateStatus: UpdateStatus.ERROR as UpdateStatus.ERROR,
88-
articleId: this.articleConfig.id,
89-
articleTitle: frontMatter.title,
90-
error,
91-
published: frontMatter.published,
92-
};
93-
}
83+
// if it's a draft, the article cannot be fetched so we just re-publish drafts
84+
if (frontMatter.published) {
85+
try {
86+
remoteArticleBodyMarkdown = await this.fetchArticleBodyMarkdown(this.articleConfig.id);
87+
} catch (error) {
88+
return {
89+
updateStatus: UpdateStatus.ERROR as UpdateStatus.ERROR,
90+
articleId: this.articleConfig.id,
91+
articleTitle: frontMatter.title,
92+
error,
93+
published: frontMatter.published,
94+
};
95+
}
9496

95-
if (remoteArticleBodyMarkdown && remoteArticleBodyMarkdown.trim() === body.body_markdown.trim()) {
96-
return {
97-
articleId: this.articleConfig.id,
98-
updateStatus: UpdateStatus.ALREADY_UP_TO_DATE as UpdateStatus.ALREADY_UP_TO_DATE,
99-
articleTitle: frontMatter.title,
100-
published: frontMatter.published,
101-
};
97+
if (remoteArticleBodyMarkdown && remoteArticleBodyMarkdown.trim() === body.body_markdown.trim()) {
98+
return {
99+
articleId: this.articleConfig.id,
100+
updateStatus: UpdateStatus.ALREADY_UP_TO_DATE as UpdateStatus.ALREADY_UP_TO_DATE,
101+
articleTitle: frontMatter.title,
102+
published: frontMatter.published,
103+
};
104+
}
102105
}
103106

104107
return got(`https://dev.to/api/articles/${this.articleConfig.id}`, {

0 commit comments

Comments
 (0)