Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

feat: add OneTab import support (#2495)

apo-mak00f9ccc2d7cc
diff --git a/apps/web/components/settings/ImportExport.tsx b/apps/web/components/settings/ImportExport.tsx
index 1f252d8a..3d239066 100644
--- a/apps/web/components/settings/ImportExport.tsx
+++ b/apps/web/components/settings/ImportExport.tsx
@@ -328,6 +328,23 @@ export function ImportExportRow() {
<p>Import</p>
</FilePickerButton>
</ImportCard>
+ <ImportCard
+ text="OneTab"
+ description={t("settings.import.import_bookmarks_from_onetab_export")}
+ >
+ <FilePickerButton
+ size={"sm"}
+ loading={false}
+ accept=".txt"
+ multiple={false}
+ className="flex items-center gap-2"
+ onFileSelect={(file) =>
+ runUploadBookmarkFile({ file, source: "onetab" })
+ }
+ >
+ <p>Import</p>
+ </FilePickerButton>
+ </ImportCard>
<ExportButton />
</div>
{importProgress && (
diff --git a/apps/web/lib/i18n/locales/en/translation.json b/apps/web/lib/i18n/locales/en/translation.json
index 3e7d81fe..2dc830f6 100644
--- a/apps/web/lib/i18n/locales/en/translation.json
+++ b/apps/web/lib/i18n/locales/en/translation.json
@@ -312,6 +312,7 @@
"import_bookmarks_from_mymind_export": "Import Bookmarks from mymind export",
"import_bookmarks_from_instapaper_export": "Import Bookmarks from Instapaper export",
"import_bookmarks_from_readwise_reader_export": "Import Bookmarks from Readwise Reader export",
+ "import_bookmarks_from_onetab_export": "Import Bookmarks from OneTab export",
"export_links_and_notes": "Export Links and Notes",
"imported_bookmarks": "Imported Bookmarks"
},
diff --git a/packages/shared/import-export/parsers.test.ts b/packages/shared/import-export/parsers.test.ts
index 3039a43e..b94b473b 100644
--- a/packages/shared/import-export/parsers.test.ts
+++ b/packages/shared/import-export/parsers.test.ts
@@ -683,3 +683,52 @@ describe("parseReadwiseReaderBookmarkFile", () => {
expect(result[3].tags).toEqual([]);
});
});
+
+describe("parseOneTabFile", () => {
+ it("parses URL | Title lines", () => {
+ const txt = `https://example.com | Example Site
+https://github.com | GitHub`;
+ const { bookmarks } = parseImportFile("onetab", txt);
+ expect(bookmarks).toHaveLength(2);
+ expect(bookmarks[0]).toMatchObject({
+ title: "Example Site",
+ content: { type: "link", url: "https://example.com" },
+ });
+ expect(bookmarks[0].tags).toEqual([]);
+ expect(bookmarks[0].paths).toEqual([]);
+ expect(bookmarks[1]).toMatchObject({
+ title: "GitHub",
+ content: { type: "link", url: "https://github.com" },
+ });
+ expect(bookmarks[1].tags).toEqual([]);
+ expect(bookmarks[1].paths).toEqual([]);
+ });
+
+ it("parses plain URL lines without a title", () => {
+ const txt = `https://example.com`;
+ const { bookmarks } = parseImportFile("onetab", txt);
+ expect(bookmarks).toHaveLength(1);
+ expect(bookmarks[0].title).toBe("");
+ expect(bookmarks[0].content).toMatchObject({
+ type: "link",
+ url: "https://example.com",
+ });
+ });
+
+ it("skips non-URL lines and empty lines", () => {
+ const txt = `Sat Feb 18 2023 10:30:00 GMT+0000
+https://example.com | Example
+
+not a url at all
+https://github.com | GitHub`;
+ const { bookmarks } = parseImportFile("onetab", txt);
+ expect(bookmarks).toHaveLength(2);
+ });
+
+ it("deduplicates repeated URLs", () => {
+ const txt = `https://example.com | Example
+https://example.com | Example`;
+ const { bookmarks } = parseImportFile("onetab", txt);
+ expect(bookmarks).toHaveLength(1);
+ });
+});
diff --git a/packages/shared/import-export/parsers.ts b/packages/shared/import-export/parsers.ts
index 1984b517..0d1b6952 100644
--- a/packages/shared/import-export/parsers.ts
+++ b/packages/shared/import-export/parsers.ts
@@ -18,7 +18,8 @@ export type ImportSource =
| "tab-session-manager"
| "mymind"
| "readwise-reader"
- | "instapaper";
+ | "instapaper"
+ | "onetab";
export interface ParsedBookmark {
title: string;
@@ -574,6 +575,42 @@ function parseReadwiseReaderBookmarkFile(
});
}
+function parseOneTabFile(textContent: string): ParsedBookmark[] {
+ const bookmarks: ParsedBookmark[] = [];
+
+ for (const line of textContent.split("\n")) {
+ const trimmed = line.trim();
+ if (!trimmed) continue;
+
+ // OneTab format: "URL | Title" or just "URL"
+ const pipeIndex = trimmed.indexOf(" | ");
+ let url: string;
+ let title: string;
+
+ if (pipeIndex !== -1) {
+ url = trimmed.substring(0, pipeIndex).trim();
+ title = trimmed.substring(pipeIndex + 3).trim();
+ } else {
+ url = trimmed;
+ title = "";
+ }
+
+ // Skip lines that don't look like URLs (group headers, timestamps, etc.)
+ if (!url.startsWith("http://") && !url.startsWith("https://")) {
+ continue;
+ }
+
+ bookmarks.push({
+ title,
+ content: { type: BookmarkTypes.LINK as const, url },
+ tags: [],
+ paths: [],
+ });
+ }
+
+ return bookmarks;
+}
+
function deduplicateBookmarks(bookmarks: ParsedBookmark[]): ParsedBookmark[] {
const deduplicatedBookmarksMap = new Map<string, ParsedBookmark>();
const textBookmarks: ParsedBookmark[] = [];
@@ -664,6 +701,9 @@ export function parseImportFile(
case "readwise-reader":
result = parseReadwiseReaderBookmarkFile(textContent);
break;
+ case "onetab":
+ result = parseOneTabFile(textContent);
+ break;
}
return { bookmarks: deduplicateBookmarks(result), lists: [] };
}