Skip to content

Commit

Permalink
fix: drafts cannot be fetched and should be re-published every time
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime1992 committed Aug 31, 2019
1 parent 9243c85 commit 37d23f8
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,28 @@ export class Article {

let remoteArticleBodyMarkdown: string | null;

try {
remoteArticleBodyMarkdown = await this.fetchArticleBodyMarkdown(this.articleConfig.id);
} catch (error) {
return {
updateStatus: UpdateStatus.ERROR as UpdateStatus.ERROR,
articleId: this.articleConfig.id,
articleTitle: frontMatter.title,
error,
published: frontMatter.published,
};
}
// if it's a draft, the article cannot be fetched so we just re-publish drafts
if (frontMatter.published) {
try {
remoteArticleBodyMarkdown = await this.fetchArticleBodyMarkdown(this.articleConfig.id);
} catch (error) {
return {
updateStatus: UpdateStatus.ERROR as UpdateStatus.ERROR,
articleId: this.articleConfig.id,
articleTitle: frontMatter.title,
error,
published: frontMatter.published,
};
}

if (remoteArticleBodyMarkdown && remoteArticleBodyMarkdown.trim() === body.body_markdown.trim()) {
return {
articleId: this.articleConfig.id,
updateStatus: UpdateStatus.ALREADY_UP_TO_DATE as UpdateStatus.ALREADY_UP_TO_DATE,
articleTitle: frontMatter.title,
published: frontMatter.published,
};
if (remoteArticleBodyMarkdown && remoteArticleBodyMarkdown.trim() === body.body_markdown.trim()) {
return {
articleId: this.articleConfig.id,
updateStatus: UpdateStatus.ALREADY_UP_TO_DATE as UpdateStatus.ALREADY_UP_TO_DATE,
articleTitle: frontMatter.title,
published: frontMatter.published,
};
}
}

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

0 comments on commit 37d23f8

Please sign in to comment.