diff --git a/README.md b/README.md index f3463fd..1459772 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,22 @@ Substacks/ The main note includes frontmatter with title, subtitle, type, audience, date, comment count, and links to all media. Comments are embedded via `![[slug-comments]]`. +### URI protocol + +You can save a post directly via an `obsidian://` URI without opening the command palette: + +``` +obsidian://substack-clipper?vault=MyVault&url=https://alice.substack.com/p/my-article +``` + +| Parameter | Required | Description | +|-----------|----------|-------------| +| `vault` | no | Target vault name (Obsidian prompts if omitted and multiple vaults exist) | +| `url` | yes | Full Substack post URL (must contain `/p/`) | +| `open` | no | `true` or `false` — override the "open after saving" setting | + +Spaces in vault names should be percent-encoded (`%20`). This works from browsers, scripts, iOS Shortcuts, bookmarklets, and anywhere else that can open a URL. + ## Settings | Setting | Default | Description | diff --git a/src/main.ts b/src/main.ts index 39e2092..cc5808c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -40,6 +40,18 @@ export default class SubstackClipperPlugin extends Plugin { void this.activateHistoryView(); }, }); + + this.registerObsidianProtocolHandler('substack-clipper', (params) => { + const url = params.url; + if (!url || !url.includes('/p/')) { + new Notice('Invalid substack-clipper uri — a "URL" parameter containing /p/ is required.'); + return; + } + const openAfterClip = params.open === 'true' ? true + : params.open === 'false' ? false + : this.settings.openAfterClip; + void this.clipPost(url, openAfterClip); + }); } async activateHistoryView(): Promise {