How to import markdown files without re-indexing?

How to import markdown files without re-indexing?

I couldn’t find an answer that works with recent Logseq versions anywhere (Help, Discourse, Discord and Reddit).

I finally managed to import markdown files by doing the following:

  • put the files in the pages directory
  • git add . on the command line
  • refresh in Logseq
  • restart Logseq

It only works with all these steps in that order. (I’m on Ubuntu)

Is there an easier way?

1 Like

I’m curious: What is so bad about re-indexing that you do not want to do it?

I’m testing a small script to import old markdown files into Logseq, and as far as I can see there is no real need for most of the steps. Logseq constantly watches the filesystem for changes (logseq/fs_watcher.cljs at 1fd160d9ddea6fab21d6165b0011175285834bfa · logseq/logseq), and when detected they get added to the db.

On my (Linux) system I tested it by adding [[findthislink]] to <logseq-folder/pages/testme.md, on my (active) journal page I add a link by typing [[find it gets completed to [[findthislink]]

In short, in theory nothing should be needed.

If you want to cleanly add a bunch of files to git, this workflow should work:

  • Close down Logseq just in case (not 100% needed)
  • cd <logseq-folder>
  • git stash
  • add markdown files
  • git add . && git commit -am "added stuff"
  • git stash apply
  • Now you should be exactly where you left things, with a dedicated commit for your new stuff

It resets the collapsed status of all the blocks in all the pages (they all become unfolded), which is not acceptable for me.

It also takes 3 minutes with the data I have (170 markdown files totaling 6 MB with a 60 MB database cache), using a lot of CPU in the meantime.

So if I’m understanding right, it works for you without the steps I mentioned.

In that case, should I file a bug report?

Just to clarify, in your paragraph “On my (Linux) system I tested it by adding…”, did you mean you created a new file or added a new line on an existing file? If it’s the latter, it doesn’t count as importing a new file.

the collapsed state sounds like a bug, I spend a lot of time collapsing everything "
just right"

Yes, I did: echo "[[placeholder22]]" >> pages/testpage24.md and then completed placeholder22. Also on my placeholder page, when opening it finds echo "[[placeholder]]" >> pages/testpage23.md the newly added page.

In short, Logseq finds all new pages and page changes made outside of Logseq.

As a caveat: I have succeeded in creating a bit of a race condition where I edited a page, and used a script to send data to that same page. That’s not a good idea.

PS I am on Fedora, which is obviously superior to Ubuntu :stuck_out_tongue_winking_eye:

Do you mean the collapsed state of blocks is preserved when you re-index?

What do you mean by that?

Sorry, I don’t understand this sentence…

Ok, so should I file a bug report?

It looks like it is :wink:

Not really sure why and what doesn’t work. As far as I can see, you can just add a markdown page to logseq by placing it in the right location (<logseq-folder/pages/). Or, you can use an external editor to make changes to your markdown files. All these new additions and changes should be picked up by Logseq (almost) immediately.

You shouldn’t have to re-index (to add md files), so then the problem (of loosing collapsed states) would not occur.

But, if you re-index, collapsed states should not disappear (that would be a bug).

Ok, I’ll file a bug report then.

Thank you Alex for you time!

Here is the bug report about new markdown files not being imported automatically: https://github.com/logseq/logseq/issues/4378

The only part I can reproduce is that it is not added to all pages

If I add a new page with a tag: [[findme1234]] and do a query, it finds the page immediately. The page is indexed. No idea why it’s not in all pages, though, that is indeed a bug.

This is a related issue: collapsed state is not being written on some .md files. The collapsed:: true/false line never appears in these files. So the state is completely lost.

That might be one of the issues I’ve encountered.

Has this been declared as a bug?

found it. indeed, it’s a bug: