-
-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Allow import Netscape HTML format (#163)
* [Feature request] Netscape HTML format import/export #96 added the possibility to add exported bookmarks via the webUI for ease of use * [Feature request] Netscape HTML format import/export #96 updated the documentation * Extract the parser into its own file and reuse the existing bookmark upload logic --------- Co-authored-by: kamtschatka <[email protected]> Co-authored-by: MohamedBassem <[email protected]>
- Loading branch information
1 parent
bb431be
commit 033e8a2
Showing
5 changed files
with
113 additions
and
30 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
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,20 @@ | ||
import Link from "next/link"; | ||
import { ExternalLink } from "lucide-react"; | ||
|
||
export default function BookmarkAlreadyExistsToast({ | ||
bookmarkId, | ||
}: { | ||
bookmarkId: string; | ||
}) { | ||
return ( | ||
<div className="flex items-center gap-1"> | ||
Bookmark already exists. | ||
<Link | ||
className="flex underline-offset-4 hover:underline" | ||
href={`/dashboard/preview/${bookmarkId}`} | ||
> | ||
Open <ExternalLink className="ml-1 size-4" /> | ||
</Link> | ||
</div> | ||
); | ||
} |
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,20 @@ | ||
function extractUrls(html: string): string[] { | ||
const regex = /<a\s+(?:[^>]*?\s+)?href="(http[^"]*)"/gi; | ||
let match; | ||
const urls = []; | ||
|
||
while ((match = regex.exec(html)) !== null) { | ||
urls.push(match[1]); | ||
} | ||
|
||
return urls; | ||
} | ||
|
||
export async function parseNetscapeBookmarkFile(file: File) { | ||
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"); | ||
} | ||
|
||
return extractUrls(textContent).map((url) => new URL(url)); | ||
} |
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 |
---|---|---|
@@ -1,28 +1,45 @@ | ||
# Importing Bookmarks | ||
|
||
## Import using the WebUI | ||
|
||
Hoarder supports importing bookmarks using the Netscape HTML Format. | ||
|
||
Simply open the WebUI of your Hoarder instance and drag and drop the bookmarks file into the UI. | ||
|
||
:::info | ||
All the URLs in the bookmarks file will be added automatically, you will not be able to pick and choose which bookmarks to import! | ||
::: | ||
|
||
## Import using the CLI | ||
|
||
:::warning | ||
Currently importing bookmarks requires some technical knowledge and might not be very straightforward for non-technical users. Don't hesitate to ask questions in github discussions or discord though. | ||
Importing bookmarks using the CLI requires some technical knowledge and might not be very straightforward for non-technical users. Don't hesitate to ask questions in github discussions or discord though. | ||
::: | ||
|
||
## Import from Chrome | ||
### Import from Chrome | ||
|
||
- Open Chrome and go to `chrome://bookmarks` | ||
- Click on the three dots on the top right corner and choose `Export bookmarks` | ||
- This will download an html file with all of your bookmarks. | ||
- First follow the steps below to export your bookmarks from Chrome | ||
- To extract the links from this html file, you can run this simple bash one liner (if on windows, you might need to use [WSL](https://learn.microsoft.com/en-us/windows/wsl/install)): `cat <file_path> | grep HREF | sed 's/.*HREF="\([^"]*\)".*/\1/' > all_links.txt`. | ||
- This will create a file `all_links.txt` with all of your bookmarks one per line. | ||
- To import them, we'll use the [hoarder cli](https://docs.hoarder.app/command-line). You'll need a Hoarder API key for that. | ||
|
||
Run the following command to import all the links from `all_links.txt`: | ||
- Run the following command to import all the links from `all_links.txt`: | ||
|
||
``` | ||
cat all_links.txt | xargs -I{} hoarder --api-key <key> --server-addr <addr> bookmarks add --link {} | ||
``` | ||
|
||
## Import from other platforms | ||
### Import from other platforms | ||
|
||
If you can get your bookmarks in a text file with one link per line, you can use the following command to import them using the [hoarder cli](https://docs.hoarder.app/command-line): | ||
|
||
``` | ||
cat all_links.txt | xargs -I{} hoarder --api-key <key> --server-addr <addr> bookmarks add --link {} | ||
``` | ||
|
||
## Exporting Bookmarks from Chrome | ||
|
||
- Open Chrome and go to `chrome://bookmarks` | ||
- Click on the three dots on the top right corner and choose `Export bookmarks` | ||
- This will download an html file with all of your bookmarks. | ||
|
||
You can use this file to import the bookmarks using the UI or CLI method described above |