Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

The .json file is empty #1

Closed
XingxinHE opened this issue Oct 27, 2022 · 4 comments
Closed

The .json file is empty #1

XingxinHE opened this issue Oct 27, 2022 · 4 comments

Comments

@XingxinHE
Copy link

Hi @N3xed , thank you so much for making the script available馃尮! Before asking the question, I have to admit that I am not a Rust programmer so please forgive me for asking silly questions.

So here begin...

Files structure

The file structure is the following. Hex is my logseq repo and Migration is my target vault folder.

馃摝 root
鈹溾攢聽Hex
鈹溾攢聽logseq2obsdn
鈹斺攢聽Migration

Question 1

Question: Should ids.json be empty?

I have tried your scripts while the ids.json seems empty... The commands I wrote:

$ E:\xxx\logseq2obsdn> cargo run -- "E:\xxx\Hex\pages" "E:\xxx\Migration" --extract-ids
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target\debug\logseq2obsdn.exe E:\xxx\Hex\pages E:\xxx\Migration --extract-ids`

And I got the following...
馃搫ids.json

{
  "refs": {}
}

Question 2

Question: Is the one-time conversion by design?
For the command you mentioned in the README.md, it said

Run
cargo run -- "<logseq-dir>/pages/<file>" "<obsidian-vault-dir>"
for each <file> in the pages dir.

So in current version of the script, do I have to manually convert each file like the following?

cargo run -- "E:\xxx\Hex\pages\Algorithm.md" "E:\xxx\Migration"

Problem Report 1

When I hit the command

cargo run -- "E:\xxx\Hex\pages\Algorithm.md" "E:\xxx\Migration"

and I got

Error: copy \\?\E:\xxx\Hex\assets\Comparison_computational_complexity.svg -> E:\xxx\Migration\assets\Comparison_computational_complexity.svg

The error is fixed when I copied the assets folder from logseq to vault. Maybe this instruction could be documented in the README.md.馃槈

Problem Report 2

From the fix of problem report 1, I run the command again and the conversion was succeeded. However, the file name is .md rather than Algorithm.md.
At this point, I am not sure whether it was caused by the false setup in previous steps...

Thank You!

Anyhow, this script does very good in general especially handling the block logic to heading logic! Thank you!

@N3xed
Copy link
Owner

N3xed commented Oct 27, 2022

Question: Should ids.json be empty?

I have tried your scripts while the ids.json seems empty... The commands I wrote:

The ids.json stores all logseq block references which are in the form ((<block-address>)), so that the script can translate them to equivalent wikilinks or block ids depending if the block is a heading or not.

Question: Is the one-time conversion by design? For the command you mentioned in the README.md, it said

Run
cargo run -- "<logseq-dir>/pages/<file>" "<obsidian-vault-dir>"
for each <file> in the pages dir.

So in current version of the script, do I have to manually convert each file like the following?

Yes, this is by design. That's also why there is an id extraction step first.

When I hit the command

cargo run -- "E:\xxx\Hex\pages\Algorithm.md" "E:\xxx\Migration"

and I got

Error: copy \\?\E:\xxx\Hex\assets\Comparison_computational_complexity.svg -> E:\xxx\Migration\assets\Comparison_computational_complexity.svg

This is probably because the Migration/assets folder didn't exist. The script should copy all used assets automatically, but the destination folder has to exist.

Problem Report 2

From the fix of problem report 1, I run the command again and the conversion was succeeded. However, the file name is .md rather than Algorithm.md. At this point, I am not sure whether it was caused by the false setup in previous steps...

This is a quirk of my files, since all my logseq files had a

title:: <title>

at the beginning, and the script takes the name from that. But logseq only adds this if the page is in a namespace (e.g. <namespace>/<page_name>).
So if there is no title:: <title> at the beginning the resulting filename is empty.

Thank You!

Anyhow, this script does very good in general especially handling the block logic to heading logic! Thank you!

Thanks!

@XingxinHE
Copy link
Author

Thanks for the reply. Then my final question shifts to "how can I read the id successfully? Is there any prerequisite for the setup especially for id?

I personally think the command I hit is correct.

$ E:\xxx\logseq2obsdn> cargo run -- "E:\xxx\Hex\pages" "E:\xxx\Migration" --extract-ids

There are lots of ids for sure in my markdown file. Here is one of the examples where there is an id configured as id:: 630dd42f-05af-4871-9d9c-b1234f6d866f.

Could you give me any hints?

@N3xed
Copy link
Owner

N3xed commented Oct 29, 2022

Thanks for the reply. Then my final question shifts to "how can I read the id successfully? Is there any prerequisite for the setup especially for id?

I personally think the command I hit is correct.

$ E:\xxx\logseq2obsdn> cargo run -- "E:\xxx\Hex\pages" "E:\xxx\Migration" --extract-ids

There are lots of ids for sure in my markdown file. Here is one of the examples where there is an id configured as id:: 630dd42f-05af-4871-9d9c-b1234f6d866f.

Could you give me any hints?

This issue was actually related to the empty file name. It is now fixed with the last revision. And no need for a title:: property anymore, the script will just take the source file name for the destination file name if there is not title:: property.

@XingxinHE
Copy link
Author

Thank you @N3xed ! It works right now! In general, the script migrates almost everything! I would like to offer some personal opinions In order to scale the capability of this project,


鈿燚ISCLAIMER:
JUST PERSONAL OPINION. Since I don't understand rust and some opinion might pale.


Automation

Currently, the greatest pain point from my perspective is to migrate from file to file. The solutions flash into my mind are the following.

Solution1 - files parsing pipeline

Since you already have a --extract-ids step at the beginning, you can simply integrate the files parsing in this step to save computation. e.g. a files.json as a result.

Solution2 - batch script

Simply attach a batch script to automate in this repo could be a quick-fix solution. However, this is just a workaround and without scalability in software engineering perspective.

Assets related issues

Your intention to copy and paste the asset file to the destination is good to avoid "ghost" asset from logseq. Maybe there should some cases you could also consider.
Currently, the program would throw exceptions if the file doesn't exist or can't find it. e.g.

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 123, kind: InvalidFilename, message: "The filename, directory name, or volume label syntax is incorrect." }'

The assests can't be handled varies. Following are the few.

  • online asset. e.g. ![name](https://cdn.jsdelivr.net/npm/simple-icons@5.8.1/icons/git.svg)
  • complicate file name. e.g. critical_point_x^2(x+6)(x+2).svg
  • ...

Solution1 Error Handling

Since there might be a bunch of reasons that can crash a program, it is good to add error-handling logic in the code. In C++, there is a try-catch style and I think there are relatively similar mechanisms for error-handling in rust. You can append all the failed cases in failed-pages.json for example.

Solution2 Just ignore the assets path

It seems silly at the first glance but it is reasonable in the scenario when logseq and obsidian are working together. example 1, example 2, example 3.

Thank You!

It is good in general for migration! Sorry I am not a rust programmer, otherwise I can create a Pull Request rather than mumbling a lot... Thank you and wish you a pleasant life! Peace!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants