Skip to content

Commit

Permalink
fix: add state to the exposed variable in the template
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed May 12, 2023
1 parent ffdcd92 commit 26572b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface Article {
url: string;
readAt?: string;
wordsCount?: number;
readingProgressPercent: number;
isArchived: boolean;
}

export interface Label {
Expand Down Expand Up @@ -105,6 +107,8 @@ export const loadArticles = async (
publishedAt
readAt
wordsCount
isArchived
readingProgressPercent
highlights {
id
quote
Expand Down
20 changes: 20 additions & 0 deletions src/settings/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,27 @@ export interface ArticleView {
dateRead?: string;
wordsCount?: number;
readLength?: number;
state: string;
enum ArticleState {
Inbox = "INBOX",
Reading = "READING",
Completed = "COMPLETED",
Archived = "ARCHIVED",
}

const getArticleState = (article: Article): string => {
if (article.isArchived) {
return ArticleState.Archived;
}
if (article.readingProgressPercent > 0) {
return article.readingProgressPercent === 100
? ArticleState.Completed
: ArticleState.Reading;
}

return ArticleState.Inbox;
};

export const renderFilename = (
article: Article,
filename: string,
Expand Down Expand Up @@ -194,6 +213,7 @@ export const renderArticleContnet = async (
dateRead,
wordsCount,
readLength,
state: getArticleState(article),
};
// Build content string based on template
let content = Mustache.render(template, articleView);
Expand Down

0 comments on commit 26572b6

Please sign in to comment.