diff --git a/README.md b/README.md index 3fb9bfd..ea2bb3f 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,11 @@ within Obsidian. You can also sync your Pocket items using an Obsidian command: "Sync Pocket list". +You can either sync all Pocket items or just Pocket items with a particular tag +that you specify, using the "Pocket sync tag" setting. Leave it blank to sync +all Pocket items, or specify a Pocket tag to limit your sync to just Pocket +items with that tag. + ### Opening and using the Pocket list Once the Pocket list is downloaded and stored, open the command palette and diff --git a/images/obsidian-pocket-settings.png b/images/obsidian-pocket-settings.png index 67f53ca..ca02c1f 100644 Binary files a/images/obsidian-pocket-settings.png and b/images/obsidian-pocket-settings.png differ diff --git a/src/SettingsManager.ts b/src/SettingsManager.ts index be75f70..f9e4406 100644 --- a/src/SettingsManager.ts +++ b/src/SettingsManager.ts @@ -1,5 +1,4 @@ import update from "immutability-helper"; -import log from "loglevel"; import { MultiWordTagConversion } from "./Tags"; import { CallbackId, CallbackRegistry } from "./Types"; import { getUniqueId } from "./utils"; @@ -8,6 +7,7 @@ export interface PocketSettings { "item-note-template"?: string; "item-notes-folder"?: string; "multi-word-tag-converter"?: MultiWordTagConversion; + "pocket-sync-tag"?: string; } const DEFAULT_POCKET_SETTINGS: PocketSettings = { diff --git a/src/data/PocketSync.ts b/src/data/PocketSync.ts index daa0e37..8aa09ea 100644 --- a/src/data/PocketSync.ts +++ b/src/data/PocketSync.ts @@ -6,7 +6,8 @@ import { PocketItemStore } from "./PocketItemStore"; export const doPocketSync = async ( itemStore: PocketItemStore, pocketAPI: PocketAPI, - accessInfo: AccessInfo + accessInfo: AccessInfo, + pocketSyncTag?: string ) => { const lastUpdateTimestamp = await itemStore.getLastUpdateTimestamp(); @@ -14,7 +15,8 @@ export const doPocketSync = async ( const getPocketItemsResponse = await pocketAPI.getPocketItems( accessInfo.accessToken, - lastUpdateTimestamp + lastUpdateTimestamp, + pocketSyncTag ); new Notice( diff --git a/src/main.ts b/src/main.ts index 3a9abb3..b394b19 100644 --- a/src/main.ts +++ b/src/main.ts @@ -48,7 +48,13 @@ export default class PocketSync extends Plugin { return; } - this.pendingSync = doPocketSync(this.itemStore, this.pocketAPI, accessInfo); + const pocketSyncTag = this.settingsManager.getSetting("pocket-sync-tag"); + this.pendingSync = doPocketSync( + this.itemStore, + this.pocketAPI, + accessInfo, + pocketSyncTag + ); try { await this.pendingSync; } finally { diff --git a/src/pocket_api/PocketAPI.ts b/src/pocket_api/PocketAPI.ts index 0d6b473..851cc79 100644 --- a/src/pocket_api/PocketAPI.ts +++ b/src/pocket_api/PocketAPI.ts @@ -53,7 +53,8 @@ export type GetRequestToken = ( export type GetAccessToken = () => Promise; export type GetPocketItems = ( accessToken: AccessToken, - lastUpdateTimestamp?: UpdateTimestamp + lastUpdateTimestamp?: UpdateTimestamp, + pocketSyncTag?: string ) => Promise; export interface PocketAPI { @@ -120,7 +121,8 @@ export type TimestampedPocketGetItemsResponse = { export const getPocketItems: GetPocketItems = async ( accessToken, - lastUpdateTimestamp? + lastUpdateTimestamp?, + pocketSyncTag? ) => { const GET_ITEMS_URL = "https://getpocket.com/v3/get"; const nextTimestamp = Math.floor(Date.now() / 1000); @@ -132,6 +134,7 @@ export const getPocketItems: GetPocketItems = async ( ? new Number(lastUpdateTimestamp).toString() : null, detailType: "complete", + tag: pocketSyncTag, }; if (!!lastUpdateTimestamp) { diff --git a/src/ui/settings.ts b/src/ui/settings.ts index 97649da..fa2e19d 100644 --- a/src/ui/settings.ts +++ b/src/ui/settings.ts @@ -158,6 +158,27 @@ const addMultiWordTagConverterSetting = ( }); }; +const SYNC_TAG_CTA = "Pocket sync tag"; +const SYNC_TAG_DESC = `Specify a Pocket tag to sync, e.g. adding 'obsidian' here +will result in only Pocket items tagged with 'obsidian' being synced. If this +setting is left blank, all Pocket items will be synced.`; + +const addPocketSyncTagSetting = ( + settingsManager: SettingsManager, + containerEl: HTMLElement +) => { + new Setting(containerEl) + .setName(SYNC_TAG_CTA) + .setDesc(SYNC_TAG_DESC) + .addText((text) => { + text.setPlaceholder("Specify a tag to limit syncs"); + text.setValue(settingsManager.getSetting("pocket-sync-tag")); + text.onChange(async (newValue) => { + await settingsManager.updateSetting("pocket-sync-tag", newValue); + }); + }); +}; + export class PocketSettingTab extends PluginSettingTab { plugin: PocketSync; settingsManager: SettingsManager; @@ -178,5 +199,6 @@ export class PocketSettingTab extends PluginSettingTab { addItemNoteTemplateSetting(this.settingsManager, containerEl); addItemNotesLocationSetting(this.settingsManager, containerEl); addMultiWordTagConverterSetting(this.settingsManager, containerEl); + addPocketSyncTagSetting(this.settingsManager, containerEl); } }