radam9/bookmarks-converter

Import custom JSON based on file system hierarchy?

Closed this issue · 2 comments

phx commented

I am building a bookmark manager and would like to include your project, but when I generate custom JSON and try to convert it, it messes everything up.

I have a feeling this comes from the IDs, which appear to determine folder hierarchy.

Would there be a way to generate custom IDs to auto-generate the hierarchy? The folder stack appears completely correct, but the final output is unable to be imported without looking messed up.

I have attached a few example files for reference.

bookmarks_troubleshooting.zip

I am building a bookmark manager and would like to include your project, but when I generate custom JSON and try to convert it, it messes everything up.

how do you generate the custom JSON? from an .html? another .json?
to which format are you trying to convert it? and what do you mean by "it messes everything up" ?

I have a feeling this comes from the IDs, which appear to determine folder hierarchy.

The IDs do not determine folder hierarchy, they are just there as a way to identify the node (folder or url).
If the imported file is a .json or .db and it contains IDs then they are used as is, the only exception being chrome, where the ID of each node is incremented by 1.
If the imported file is .html then the IDs are generated as the node are being parsed since the HTML bookmarks file doesn't have any IDs.
The index attribute is what decides what the order of the nodes within a folder node will be.

Would there be a way to generate custom IDs to auto-generate the hierarchy? The folder stack appears completely correct, but the final output is unable to be imported without looking messed up.

You again mention messed up, but that unfortunately doesn't explain what exactly is going wrong.
As I mentioned, the index attribute dictates the order of element within its parent node, the hierarchy of the generated custom .json file depends on the input file.

  • If the input file is .html the nodes are parsed from the top of the file to the bottom, which leads to a depth first traversal. This causes the IDs of the items to increase as you go deep into the tree first and then along its breadth.
  • If the input file is .json the nodes are parsed just as provided in the .json file, and if the file is a chrome .json the ID is incremented by 1.

I have attached a few example files for reference.

bookmarks_troubleshooting.zip

Unfortunately I do not know what I am looking for in the files to be able to help you. I did however notice that the structure of the nodes in the custom_bookmarks.json looks like this:

"bookmark_bar": {
      "absolute_path": "Bookmarks bar",
      "absolute_path_hash": "37a7f9537fd3576a27d67628f43eb33d",
      "absolute_parent_path": "/",
      "absolute_parent_path_hash": "6666cd76f96956469e7be39d750cc7d9",
      "relative_path": "Bookmarks bar",
      "guid": "63ebc7d8-94dd-4fc8-8f64-1d62384d763c",
      "title": "Bookmarks bar",
      "type": "folder",
      "id": 980,
      "date_added": 1655751906,
      "date_modified": 0,
      "children": [...],
} 

I see that there are extra fields absolute_path, absolute_path_hash, absolute_parent_path, absolute_parent_path_hash, relative_path and guid, these are not fields in the bookmarks_converter library. If you are modifying the source code, I can't know what issues might arise as a side effect of these changes.

phx commented

Never mind. The easiest method was for me to convert the file system hierarchy to a sqlite database and then convert that database to HTML. The part that was so hard was setting the indices correctly, and I did not realize that it is enforced by the code that url types must take index precedence over folder types.

Everything appears to be working correctly now. If I have time, I will fork and update with my code so that it can convert file system hierarchy automatically in case anyone is interested in that sort of thing, but I figure I'm probably the only one, so I don't guess it's something I need to prioritize at the moment.