Last active
June 20, 2022 13:20
-
-
Save trashhalo/f1c51f782a87728a4d831809380f3ea9 to your computer and use it in GitHub Desktop.
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
# Script to migrate from obsidian readwise to logseq readwise | |
# 1. Create a new logseq vault and sync your readwise content into it. Script assumes you are in this new folder. | |
# 2. Merge obsidian readwise content into new vault using this ruby file | |
# 3. Delete Readwise folder from obsidian vault | |
# 4. copy the pages files into your obsidian pages folder | |
# map of url => new filename | |
logseq_url_map = Dir["pages/*"].map do |page| | |
[File.read(page)[/^\s*url:: (.*)$/, 1], page] | |
end.to_h | |
# map of full title => new filename | |
logseq_full_title_map = Dir["pages/*"].map do |page| | |
[File.read(page)[/^\s*full-title:: (.*)$/, 1], page] | |
end.to_h | |
# map of new file name => title | |
logseq_new_title_map = Dir["pages/*"].map do |page| | |
[page, File.read(page)[/^\s*title:: (.*)$/, 1]] | |
end.to_h | |
# iterate over old obsidian readwise files | |
Dir.glob("../Notes2.0/Readwise/**/*.md").each do |page| | |
content = File.read(page) | |
url = content[/^\s*URL:: (.*)$/, 1] | |
full_title = content[/^\s*full title:: (.*)$/, 1] | |
title = content[/^\s*title:: (.*)$/, 1] | |
filename = nil | |
# did we find a url? try to match by url | |
if !url.nil? | |
filename = logseq_url_map[url] | |
end | |
# url didnt work? did we find a title? try that | |
if filename.nil? && !full_title.nil? | |
filename = logseq_full_title_map[full_title] | |
end | |
if filename.nil? | |
print "warn #{page} no match\n" | |
next | |
end | |
# replace title with new title format | |
content[title] = logseq_new_title_map[filename] | |
# write obsidian readwise content onto new filename | |
File.write(filename, content) | |
en |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment