@@ -9,32 +9,6 @@ import { getDateForPage } from 'logseq-dateutils'
9
9
import icon from '../public/icon.png'
10
10
import { Article , loadArticles } from './util'
11
11
12
- const settings : SettingSchemaDesc [ ] = [
13
- {
14
- key : 'api key' ,
15
- type : 'string' ,
16
- title : 'Enter Omnivore Api Key' ,
17
- description : 'Enter Omnivore Api Key here' ,
18
- default : '' ,
19
- } ,
20
- {
21
- key : 'filter' ,
22
- type : 'string' ,
23
- title : 'Enter a filter for Omnivore articles' ,
24
- description :
25
- 'Enter a filter for Omnivore articles here. e.g. "has:highlights"' ,
26
- default : 'has:highlights' ,
27
- } ,
28
- {
29
- key : 'frequency' ,
30
- type : 'number' ,
31
- title : 'Enter sync with Omnivore frequency' ,
32
- description :
33
- 'Enter sync with Omnivore frequency in minutes here or 0 to disable' ,
34
- default : 60 ,
35
- } ,
36
- ]
37
-
38
12
const siteNameFromUrl = ( originalArticleUrl : string ) : string => {
39
13
try {
40
14
return new URL ( originalArticleUrl ) . hostname . replace ( / ^ w w w \. / , '' )
@@ -195,14 +169,17 @@ const syncOmnivore = (
195
169
apiKey : string ,
196
170
frequency : number ,
197
171
filter : string ,
198
- syncAt : string
172
+ syncAt : string ,
173
+ graph : string
199
174
) : number => {
200
175
let intervalID = 0
201
176
// sync every frequency minutes
202
177
if ( frequency > 0 ) {
203
178
intervalID = setInterval (
204
179
async ( ) => {
205
- syncAt = await fetchOmnivore ( apiKey , filter , syncAt , true )
180
+ if ( ( await logseq . App . getCurrentGraph ( ) ) ?. name === graph ) {
181
+ syncAt = await fetchOmnivore ( apiKey , filter , syncAt , true )
182
+ }
206
183
} ,
207
184
frequency * 1000 * 60 ,
208
185
syncAt
@@ -219,26 +196,61 @@ const syncOmnivore = (
219
196
const main = async ( baseInfo : LSPluginBaseInfo ) => {
220
197
console . log ( 'logseq-omnivore loaded' )
221
198
199
+ const settings : SettingSchemaDesc [ ] = [
200
+ {
201
+ key : 'api key' ,
202
+ type : 'string' ,
203
+ title : 'Enter Omnivore Api Key' ,
204
+ description : 'Enter Omnivore Api Key here' ,
205
+ default : '' ,
206
+ } ,
207
+ {
208
+ key : 'filter' ,
209
+ type : 'string' ,
210
+ title : 'Enter a filter for Omnivore articles' ,
211
+ description :
212
+ 'Enter a filter for Omnivore articles here. e.g. "has:highlights"' ,
213
+ default : 'has:highlights' ,
214
+ } ,
215
+ {
216
+ key : 'frequency' ,
217
+ type : 'number' ,
218
+ title : 'Enter sync with Omnivore frequency' ,
219
+ description :
220
+ 'Enter sync with Omnivore frequency in minutes here or 0 to disable' ,
221
+ default : 60 ,
222
+ } ,
223
+ {
224
+ key : 'graph' ,
225
+ type : 'string' ,
226
+ title : 'Enter the graph to sync with Omnivore' ,
227
+ description : 'Enter the graph to sync Omnivore articles to' ,
228
+ // default is the current graph
229
+ default : ( await logseq . App . getCurrentGraph ( ) ) ?. name as string ,
230
+ } ,
231
+ ]
222
232
logseq . useSettingsSchema ( settings )
223
233
224
234
let apiKey = logseq . settings ?. [ 'api key' ] as string
225
235
let frequency = logseq . settings ?. frequency as number
226
236
let filter = logseq . settings ?. filter as string
227
237
let syncAt = logseq . settings ?. [ 'synced at' ] as string
228
238
let intervalID : number
239
+ let graph = logseq . settings ?. graph as string
229
240
230
241
logseq . onSettingsChanged ( ( ) => {
231
242
apiKey = logseq . settings ?. [ 'api key' ] as string
232
243
filter = logseq . settings ?. filter as string
233
244
syncAt = logseq . settings ?. [ 'synced at' ] as string
245
+ graph = logseq . settings ?. graph as string
234
246
// remove existing scheduled task and create new one
235
247
const newFrequency = logseq . settings ?. frequency as number
236
248
if ( newFrequency !== frequency ) {
237
249
if ( intervalID ) {
238
250
clearInterval ( intervalID )
239
251
}
240
252
frequency = newFrequency
241
- intervalID = syncOmnivore ( apiKey , frequency , filter , syncAt )
253
+ intervalID = syncOmnivore ( apiKey , frequency , filter , syncAt , graph )
242
254
}
243
255
} )
244
256
@@ -268,7 +280,7 @@ const main = async (baseInfo: LSPluginBaseInfo) => {
268
280
await fetchOmnivore ( apiKey , filter , syncAt , true )
269
281
270
282
// sync every frequency minutes
271
- intervalID = syncOmnivore ( apiKey , frequency , filter , syncAt )
283
+ intervalID = syncOmnivore ( apiKey , frequency , filter , syncAt , graph )
272
284
}
273
285
274
286
// bootstrap
0 commit comments