diff --git a/joplinexport.py b/joplinexport.py index 2c93715..552fa30 100755 --- a/joplinexport.py +++ b/joplinexport.py @@ -47,6 +47,11 @@ class JoplinExporter: static_dir = Path("static/resources") joplin_dir = Path.home() / ".config/joplin-desktop" + def __init__(self): + # A dict of {resource_id: (title, extension)}. + self.resources = {} + self.used_resources = set() + def clean_content_dir(self): """Reset the content directory to a known state to begin.""" rmtree(self.content_dir) @@ -82,11 +87,15 @@ class JoplinExporter: resource = self.resources.get(resource_id) if not resource: return None + # Add the resource to the set of used resources, so we can only copy + # the resources that are used. + self.used_resources.add(resource_id) return "resources/" + resource_id + "." + resource[1] def copy_resources(self): - """Copy all the resources to the output directory.""" - for resource_id, resource in self.resources.items(): + """Copy all the used resources to the output directory.""" + for resource_id in self.used_resources: + resource = self.resources[resource_id] title, extension = resource copy( self.joplin_dir / "resources" / (f"{resource_id}.{extension}"), @@ -144,7 +153,6 @@ class JoplinExporter: folder_list.sort(key=lambda x: x[1].lower().strip() if x[1] != "Welcome" else "0") self.clean_content_dir() - self.copy_resources() for folder_counter, folder in enumerate(folder_list, start=1): folder_id, folder_title = folder @@ -207,6 +215,8 @@ Click on a link in the list below to go to that page: """ ) + self.copy_resources() + if __name__ == "__main__": print("Exporting Joplin database...") diff --git a/static/resources/8d53a1960f1c42f4918de1a9da469f44.png b/static/resources/8d53a1960f1c42f4918de1a9da469f44.png deleted file mode 100644 index 089761e..0000000 Binary files a/static/resources/8d53a1960f1c42f4918de1a9da469f44.png and /dev/null differ diff --git a/static/resources/b6da3f5c07ad4720a12e9730008f7bb5.png b/static/resources/b6da3f5c07ad4720a12e9730008f7bb5.png deleted file mode 100644 index 9e68d7d..0000000 Binary files a/static/resources/b6da3f5c07ad4720a12e9730008f7bb5.png and /dev/null differ diff --git a/static/resources/ccb31117efba476bbb29e1bdc3e074cb.png b/static/resources/ccb31117efba476bbb29e1bdc3e074cb.png deleted file mode 100644 index bdae433..0000000 Binary files a/static/resources/ccb31117efba476bbb29e1bdc3e074cb.png and /dev/null differ