Updates
This commit is contained in:
parent
54cce3cc5d
commit
155deb3b98
@ -6,4 +6,4 @@ insert_anchor_links = "right"
|
|||||||
+++
|
+++
|
||||||
To isolate the servo 5V rail, remove this diode:
|
To isolate the servo 5V rail, remove this diode:
|
||||||
|
|
||||||
![a435bcae86912205b6fac41731285b8d.png](6d668e05d8a54580966b94a752f3b7db)
|
![a435bcae86912205b6fac41731285b8d.png](../../6d668e05d8a54580966b94a752f3b7db.png)
|
@ -6,4 +6,4 @@ insert_anchor_links = "right"
|
|||||||
+++
|
+++
|
||||||
This is the pinout of the Omnibus F4 V3:
|
This is the pinout of the Omnibus F4 V3:
|
||||||
|
|
||||||
![53b3161d509dcc7bbfb43c89b16b0bae.png](99f5c91454204c1d9740a8d9b876833b)
|
![53b3161d509dcc7bbfb43c89b16b0bae.png](../../99f5c91454204c1d9740a8d9b876833b.png)
|
@ -3,6 +3,7 @@ import re
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from shutil import copy
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@ -25,19 +26,27 @@ class Note:
|
|||||||
|
|
||||||
class JoplinExporter:
|
class JoplinExporter:
|
||||||
content_dir = Path("content")
|
content_dir = Path("content")
|
||||||
|
static_dir = Path("static")
|
||||||
|
joplin_dir = Path.home() / ".config/joplin-desktop"
|
||||||
|
|
||||||
def clean_content_dir(self):
|
def clean_content_dir(self):
|
||||||
"""Reset the content directory to a known state to begin."""
|
"""Reset the content directory to a known state to begin."""
|
||||||
rmtree(self.content_dir)
|
rmtree(self.content_dir)
|
||||||
|
rmtree(self.static_dir)
|
||||||
self.content_dir.mkdir()
|
self.content_dir.mkdir()
|
||||||
|
self.static_dir.mkdir()
|
||||||
with open(self.content_dir / "_index.md", mode="w") as outfile:
|
with open(self.content_dir / "_index.md", mode="w") as outfile:
|
||||||
outfile.write('+++\nredirect_to = "welcome"\n+++')
|
outfile.write('+++\nredirect_to = "welcome"\n+++')
|
||||||
|
|
||||||
def resolve_note_links(self, note: Note) -> str:
|
def resolve_note_links(self, note: Note) -> str:
|
||||||
def replacement(match):
|
def replacement(match):
|
||||||
note_id = match.group(1)
|
item_id = match.group(1)
|
||||||
new_url = self.get_note_url_by_id(note_id)
|
new_url = self.get_note_url_by_id(item_id)
|
||||||
return "](" + ("../../" + new_url if new_url else note_id) + ")"
|
if not new_url:
|
||||||
|
new_url = self.get_resource_url_by_id(item_id)
|
||||||
|
if not new_url:
|
||||||
|
new_url = item_id
|
||||||
|
return f"](../../{new_url})"
|
||||||
|
|
||||||
return re.sub(r"\]\(:/([a-f0-9]{32})\)", replacement, note.body)
|
return re.sub(r"\]\(:/([a-f0-9]{32})\)", replacement, note.body)
|
||||||
|
|
||||||
@ -48,16 +57,35 @@ class JoplinExporter:
|
|||||||
return None
|
return None
|
||||||
return note.get_url()
|
return note.get_url()
|
||||||
|
|
||||||
|
def get_resource_url_by_id(self, resource_id: str) -> Optional[str]:
|
||||||
|
"""Return a resource's relative URL by its ID."""
|
||||||
|
resource = self.resources.get(resource_id)
|
||||||
|
if not resource:
|
||||||
|
return None
|
||||||
|
return resource_id + "." + resource[1]
|
||||||
|
|
||||||
|
def copy_resources(self):
|
||||||
|
"""Copy all the resources to the output directory."""
|
||||||
|
for resource_id, resource in self.resources.items():
|
||||||
|
title, extension = resource
|
||||||
|
copy(
|
||||||
|
self.joplin_dir / "resources" / (resource_id + "." + extension),
|
||||||
|
self.static_dir,
|
||||||
|
)
|
||||||
|
|
||||||
def read_data(self):
|
def read_data(self):
|
||||||
conn = sqlite3.connect(Path.home() / ".config/joplin-desktop/database.sqlite")
|
"""Read the data from the Joplin database."""
|
||||||
|
conn = sqlite3.connect(self.joplin_dir / "database.sqlite")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
# Create table
|
# Create table
|
||||||
c.execute("""SELECT id, title FROM folders;""")
|
c.execute("""SELECT id, title FROM folders;""")
|
||||||
self.folders = {id: title for id, title in c.fetchall()}
|
self.folders = {id: title for id, title in c.fetchall()}
|
||||||
|
|
||||||
c.execute("""SELECT id, title FROM resources;""")
|
c.execute("""SELECT id, title, file_extension FROM resources;""")
|
||||||
self.resources = {id: title for id, title in c.fetchall()}
|
self.resources = {
|
||||||
|
id: (title, file_extension) for id, title, file_extension in c.fetchall()
|
||||||
|
}
|
||||||
|
|
||||||
c.execute("""SELECT id, parent_id, title, body FROM notes;""")
|
c.execute("""SELECT id, parent_id, title, body FROM notes;""")
|
||||||
self.notes = defaultdict(list)
|
self.notes = defaultdict(list)
|
||||||
@ -70,18 +98,20 @@ class JoplinExporter:
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
def export(self):
|
def export(self):
|
||||||
|
self.read_data()
|
||||||
|
|
||||||
folder_list = list(self.folders.items())
|
folder_list = list(self.folders.items())
|
||||||
# Sort "Welcome" last.
|
# Sort "Welcome" last.
|
||||||
folder_list.sort(
|
folder_list.sort(
|
||||||
key=lambda x: x[1].lower().strip() if x[1] != "Welcome" else "0"
|
key=lambda x: x[1].lower().strip() if x[1] != "Welcome" else "0"
|
||||||
)
|
)
|
||||||
|
|
||||||
outdir = Path.cwd() / "content"
|
|
||||||
self.clean_content_dir()
|
self.clean_content_dir()
|
||||||
|
self.copy_resources()
|
||||||
|
|
||||||
for counter, folder in enumerate(folder_list, start=1):
|
for counter, folder in enumerate(folder_list, start=1):
|
||||||
folder_id, folder_title = folder
|
folder_id, folder_title = folder
|
||||||
dir = outdir / slugify(folder_title)
|
dir = self.content_dir / slugify(folder_title)
|
||||||
dir.mkdir(parents=True)
|
dir.mkdir(parents=True)
|
||||||
with (dir / "_index.md").open(mode="w") as outfile:
|
with (dir / "_index.md").open(mode="w") as outfile:
|
||||||
outfile.write(
|
outfile.write(
|
||||||
@ -98,7 +128,9 @@ Select one of the sublinks on the left to see the notes in this section."""
|
|||||||
sorted(self.notes[folder_id], key=lambda n: n.title)
|
sorted(self.notes[folder_id], key=lambda n: n.title)
|
||||||
):
|
):
|
||||||
print(f"Exporting {folder_title} - {note.title}...")
|
print(f"Exporting {folder_title} - {note.title}...")
|
||||||
with (outdir / (note.get_url() + ".md")).open(mode="w") as outfile:
|
with (self.content_dir / (note.get_url() + ".md")).open(
|
||||||
|
mode="w"
|
||||||
|
) as outfile:
|
||||||
outfile.write(
|
outfile.write(
|
||||||
f"""+++
|
f"""+++
|
||||||
title = "{note.title}"
|
title = "{note.title}"
|
||||||
@ -112,6 +144,4 @@ insert_anchor_links = "right"
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Exporting Joplin database...")
|
print("Exporting Joplin database...")
|
||||||
exporter = JoplinExporter()
|
JoplinExporter().export()
|
||||||
exporter.read_data()
|
|
||||||
exporter.export()
|
|
||||||
|
BIN
static/6d668e05d8a54580966b94a752f3b7db.png
Normal file
BIN
static/6d668e05d8a54580966b94a752f3b7db.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 358 KiB |
BIN
static/99f5c91454204c1d9740a8d9b876833b.png
Normal file
BIN
static/99f5c91454204c1d9740a8d9b876833b.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 748 KiB |
Loading…
Reference in New Issue
Block a user