From 26572b6385ab44b610e2490229adb86d25e53160 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 12 May 2023 10:25:26 +0800 Subject: [PATCH] fix: add state to the exposed variable in the template --- src/api.ts | 4 ++++ src/settings/template.ts | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/api.ts b/src/api.ts index 0e445ef..fd4e51d 100644 --- a/src/api.ts +++ b/src/api.ts @@ -41,6 +41,8 @@ export interface Article { url: string; readAt?: string; wordsCount?: number; + readingProgressPercent: number; + isArchived: boolean; } export interface Label { @@ -105,6 +107,8 @@ export const loadArticles = async ( publishedAt readAt wordsCount + isArchived + readingProgressPercent highlights { id quote diff --git a/src/settings/template.ts b/src/settings/template.ts index 2446f0b..b06b965 100644 --- a/src/settings/template.ts +++ b/src/settings/template.ts @@ -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, @@ -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);