-
-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(web): Add support for importing bookmarks from Pocket
- Loading branch information
1 parent
d62c972
commit 9dd6f21
Showing
7 changed files
with
270 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { cn } from "@/lib/utils"; | ||
import * as ProgressPrimitive from "@radix-ui/react-progress"; | ||
|
||
const Progress = React.forwardRef< | ||
React.ElementRef<typeof ProgressPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> | ||
>(({ className, value, ...props }, ref) => ( | ||
<ProgressPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"relative h-4 w-full overflow-hidden rounded-full bg-secondary", | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<ProgressPrimitive.Indicator | ||
className="h-full w-full flex-1 bg-primary transition-all" | ||
style={{ transform: `translateX(-${100 - (value ?? 0)}%)` }} | ||
/> | ||
</ProgressPrimitive.Root> | ||
)); | ||
Progress.displayName = ProgressPrimitive.Root.displayName; | ||
|
||
export { Progress }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copied from https://gist.github.com/devster31/4e8c6548fd16ffb75c02e6f24e27f9b9 | ||
import * as cheerio from "cheerio"; | ||
|
||
export interface ParsedBookmark { | ||
title: string; | ||
url?: string; | ||
tags: string[]; | ||
addDate?: number; | ||
} | ||
|
||
export async function parseNetscapeBookmarkFile( | ||
file: File, | ||
): Promise<ParsedBookmark[]> { | ||
const textContent = await file.text(); | ||
|
||
if (!textContent.startsWith("<!DOCTYPE NETSCAPE-Bookmark-file-1>")) { | ||
throw Error("The uploaded html file does not seem to be a bookmark file"); | ||
} | ||
|
||
const $ = cheerio.load(textContent); | ||
|
||
return $("a") | ||
.map(function (_index, a) { | ||
const $a = $(a); | ||
const addDate = $a.attr("add_date"); | ||
let tags: string[] = []; | ||
try { | ||
tags = $a.attr("tags")?.split(",") ?? []; | ||
} catch (e) { | ||
/* empty */ | ||
} | ||
return { | ||
title: $a.text(), | ||
url: $a.attr("href"), | ||
tags: tags, | ||
addDate: typeof addDate === "undefined" ? undefined : parseInt(addDate), | ||
}; | ||
}) | ||
.get(); | ||
} | ||
|
||
export async function parsePocketBookmarkFile( | ||
file: File, | ||
): Promise<ParsedBookmark[]> { | ||
const textContent = await file.text(); | ||
|
||
const $ = cheerio.load(textContent); | ||
|
||
return $("a") | ||
.map(function (_index, a) { | ||
const $a = $(a); | ||
const addDate = $a.attr("time_added"); | ||
let tags: string[] = []; | ||
const tagsStr = $a.attr("tags"); | ||
try { | ||
tags = tagsStr && tagsStr.length > 0 ? tagsStr.split(",") : []; | ||
} catch (e) { | ||
/* empty */ | ||
} | ||
return { | ||
title: $a.text(), | ||
url: $a.attr("href"), | ||
tags: tags, | ||
addDate: typeof addDate === "undefined" ? undefined : parseInt(addDate), | ||
}; | ||
}) | ||
.get(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.