@@ -7,7 +7,9 @@ import { zExportSchema } from "./exportBookmarks";
7
7
8
8
export interface ParsedBookmark {
9
9
title : string ;
10
- url ?: string ;
10
+ content ?:
11
+ | { type : BookmarkTypes . LINK ; url : string }
12
+ | { type : BookmarkTypes . TEXT ; text : string } ;
11
13
tags : string [ ] ;
12
14
addDate ?: number ;
13
15
notes ?: string ;
@@ -36,9 +38,10 @@ export async function parseNetscapeBookmarkFile(
36
38
} catch ( e ) {
37
39
/* empty */
38
40
}
41
+ const url = $a . attr ( "href" ) ;
39
42
return {
40
43
title : $a . text ( ) ,
41
- url : $a . attr ( "href" ) ,
44
+ content : url ? { type : BookmarkTypes . LINK as const , url } : undefined ,
42
45
tags,
43
46
addDate : typeof addDate === "undefined" ? undefined : parseInt ( addDate ) ,
44
47
} ;
@@ -64,9 +67,10 @@ export async function parsePocketBookmarkFile(
64
67
} catch ( e ) {
65
68
/* empty */
66
69
}
70
+ const url = $a . attr ( "href" ) ;
67
71
return {
68
72
title : $a . text ( ) ,
69
- url : $a . attr ( "href" ) ,
73
+ content : url ? { type : BookmarkTypes . LINK as const , url } : undefined ,
70
74
tags,
71
75
addDate : typeof addDate === "undefined" ? undefined : parseInt ( addDate ) ,
72
76
} ;
@@ -86,14 +90,25 @@ export async function parseHoarderBookmarkFile(
86
90
) ;
87
91
}
88
92
89
- return parsed . data . bookmarks . map ( ( bookmark ) => ( {
90
- title : bookmark . title ?? "" ,
91
- url :
92
- bookmark . content ?. type == BookmarkTypes . LINK
93
- ? bookmark . content . url
94
- : undefined ,
95
- tags : bookmark . tags ,
96
- addDate : bookmark . createdAt ,
97
- notes : bookmark . note ?? undefined ,
98
- } ) ) ;
93
+ return parsed . data . bookmarks . map ( ( bookmark ) => {
94
+ let content = undefined ;
95
+ if ( bookmark . content ?. type == BookmarkTypes . LINK ) {
96
+ content = {
97
+ type : BookmarkTypes . LINK as const ,
98
+ url : bookmark . content . url ,
99
+ } ;
100
+ } else if ( bookmark . content ?. type == BookmarkTypes . TEXT ) {
101
+ content = {
102
+ type : BookmarkTypes . TEXT as const ,
103
+ text : bookmark . content . text ,
104
+ } ;
105
+ }
106
+ return {
107
+ title : bookmark . title ?? "" ,
108
+ content,
109
+ tags : bookmark . tags ,
110
+ addDate : bookmark . createdAt ,
111
+ notes : bookmark . note ?? undefined ,
112
+ } ;
113
+ } ) ;
99
114
}
0 commit comments