Converting obsidian to logseq (org mode)?

There is a setting you can use in config.edn to change this for the future. It’s under the key :org-mode/insert-file-link?, you want to change that to true.

You could convert those links pretty quickly with a small script. I take no responsibility for any data loss. Please check the output carefully before uncommenting the lines that write the file! I haven’t personally used this script.

#!/usr/bin/env python3

import os
import re


def check_and_replace_links(directory, text):
    def replace_link(match):
        link_text = match.group(1)
        link_path_pages = os.path.join(pages_directory, link_text + ".org")
        link_path_journals = os.path.join(journals_directory, link_text + ".org")

        if os.path.exists(link_path_pages):
            return f"[[file:{link_path_pages}][{link_text}]]"
        if os.path.exists(link_path_journals):
            return f"[[file:{link_path_journals}][{link_text}]]"

        return match.group(0)

    pattern = r"\[\[(.*?)\]\]"
    replaced_text = re.sub(pattern, replace_link, text)
    return replaced_text


def process_file(file_path):
    with open(file_path, "r") as file:
        content = file.read()
        updated_content = check_and_replace_links(os.path.dirname(file_path), content)

    ## For now just print the content
    print(updated_content)

    ## Write the files at your own risk
    # with open(file_path, "w") as file:
    #     file.write(updated_content)


if __name__ == "__main__":
    pages_directory = os.path.join(os.getcwd(), "pages")
    journals_directory = os.path.join(os.getcwd(), "journals")

    for root, _, filenames in os.walk(pages_directory):
        for filename in filenames:
            if filename.endswith(".org"):
                file_path = os.path.join(root, filename)
                process_file(file_path)

    for root, _, filenames in os.walk(journals_directory):
        for filename in filenames:
            if filename.endswith(".org"):
                file_path = os.path.join(root, filename)
                process_file(file_path)

The script assumes you are in the base logseq directory. That is, one directory above pages and journals.