Skip to content

Commit 3d55f88

Browse files
committed
feat(reader): store and display author
1 parent d584d37 commit 3d55f88

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

src/base/node/feed.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const parseRss = (xml: any): Omit<Feed, 'url'> => {
1818
url: gettrim(v, 'link[0]'),
1919
content: gettrim(v, 'content:encoded[0]') || gettrim(v, 'description[0]'),
2020
pubTime: gettrim(v, 'pubDate[0]'),
21+
author: gettrim(v, 'author[0]', '') || gettrim(v, 'dc:creator[0]', ''),
2122
})),
2223
}
2324
}
@@ -30,10 +31,11 @@ const parseAtom = (xml: any): Omit<Feed, 'url'> => {
3031
description: '',
3132
link: '',
3233
items: (feed.entry || []).map((v: any) => ({
33-
title: gettrim(v, 'title[0]'),
34+
title: gettrim(v, 'title[0]._') || gettrim(v, 'title[0]'),
3435
url: gettrim(v, 'link[0].$.href', ''),
35-
content: gettrim(v, 'content[0]_', ''),
36+
content: gettrim(v, 'content[0]._', ''),
3637
pubTime: gettrim(v, 'published[0]') || gettrim(v, 'updated[0]'),
38+
author: gettrim(v, 'author[0].name[0]') || gettrim(v, 'author[0]', '') || '',
3739
})),
3840
}
3941
}

src/main/reader/db.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { exec } from '@/services/db/electron-main/db'
1+
import { exec, get } from '@/services/db/electron-main/db'
22
import { logger } from '@/services/logger/electron-main/logger'
33

44
const sql = `
@@ -26,9 +26,20 @@ const sql = `
2626
);
2727
`
2828

29+
const alterSql = `
30+
ALTER TABLE articles
31+
ADD COLUMN author NVARCHAR(50);
32+
`
33+
2934
export const init = async () => {
3035
try {
3136
await exec(sql)
37+
38+
const row = await get('select * from sqlite_schema where name = "articles" and sql like "%author%"')
39+
40+
if (!row) {
41+
await exec(alterSql)
42+
}
3243
} catch (e) {
3344
logger.error('[Reader] Create Reader table error:', e)
3445
}

src/services/reader/electron-main/article.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Article, Tab } from '@/types/reader'
44
export const upsert = (articles: Article | Article[]) => new Promise<void>((resolve, reject) => {
55
const items = Array.isArray(articles) ? articles : [articles]
66

7-
const cols = ['title', 'url', 'content', 'pubTime', 'feedId'] as const
7+
const cols = ['title', 'url', 'content', 'pubTime', 'author', 'feedId'] as const
88
const keys = cols.map((k) => `$${k}`)
99
const sets = cols.map((k, index) => `${k}=${keys[index]}`)
1010

src/types/reader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type Article = {
66
url: string
77
content: string
88
pubTime?: string
9+
author?: string
910
starred?: 0 | 1
1011
read?: 0 | 1
1112
feedId?: number

src/ui/apps/reader/MainPanel/Article/content.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function Content() {
6868
content,
6969
feedId,
7070
pubTime,
71+
author,
7172
} = activeArticle
7273
const feed = feeds.find((v) => v.id === feedId)!
7374

@@ -102,6 +103,11 @@ function Content() {
102103
<div className="mr-7">
103104
{feed.title}
104105
</div>
106+
{author !== feed.title && (
107+
<div className="mr-7">
108+
{author}
109+
</div>
110+
)}
105111
<div>
106112
{formatTime(pubTime!, 'MM/dd/yy hh:mm')}
107113
</div>

0 commit comments

Comments
 (0)