Skip to content

enibrn/dendron-move-images

Repository files navigation

Dendron Move Images

Terminology

  • primary vault: the main vault from where I upstream notes
  • secondary vault: one of the vault in the dependencies which will receive the notes moved from the primary vault

Why

When I move notes from a vault to another one using the move note command, any images in the notes had to be moved manually and then eventually removed from the first one if not referenced anymore (to clean up space).

Thats particularly unpleasant when there are a lot of notes to be moved, especially with images shared between notes (some of which need to be moved and some not).

So I built a script that does that automatically.

Scopes

  • Notes are moved from the primary vault to the secondary vault only
  • Only images are

Practical example

I want to move macosx.md note to secondary-vault

Initial structure

primary-vault/
├── dependencies/
│   └── some-folders-in-between/
│       └── secondary-vault/
│           └── notes/
│               ├── assets/
│               │   └── images/
│               │       └── tux-wallpaper.jpg
│               ├── root.md
│               └── linux.md
└── notes/
    ├── assets/
    │   └── images/
    │       ├── bliss-wallpaper.jpg
    │       ├── sierra-wallpaper.jpg
    │       └── mac-vs-pc.jpg
    ├── root.md
    ├── windows.md
    └── macosx.md

Image references

  • windows.md
    • bliss-wallpaper.jpg
    • mac-vs-pc.jpg
  • macosx.md
    • sierra-wallpaper.jpg
    • mac-vs-pc.jpg
  • linux.md
    • tux-wallpaper.jpg

After dendron move note structure

primary-vault/
├── dependencies/
│   └── some-folders-in-between/
│       └── secondary-vault/
│           └── notes/
│               ├── assets/
│               │   └── images/
│               │       └── tux-wallpaper.jpg
│               ├── root.md
│               ├── linux.md
│               └── macosx.md
└── notes/
    ├── assets/
    │   └── images/
    │       ├── bliss-wallpaper.jpg
    │       ├── sierra-wallpaper.jpg
    │       └── mac-vs-pc.jpg
    ├── root.md
    └── windows.md

After dendron move images structure

primary-vault/
├── dependencies/
│   └── some-folders-in-between/
│       └── secondary-vault/
│           └── notes/
│               ├── assets/
│               │   └── images/
│               │       ├── tux-wallpaper.jpg
│               │       ├── sierra-wallpaper.jpg
│               │       └── mac-vs-pc.jpg
│               ├── root.md
│               ├── linux.md
│               └── macosx.md
└── notes/
    ├── assets/
    │   └── images/
    │       ├── bliss-wallpaper.jpg
    │       └── mac-vs-pc.jpg
    ├── root.md
    └── windows.md

What happened

  • sierra-wallpaper.jpg is moved from primary vault to secondary vault and then removed from primary vault because not referenced anymore in any of its notes
  • mac-vs-pc.jpg is moved from primary vault to secondary vault but it is not removed from primary vault because is still needed for the note windows.md

How

Ideally, this script would be an npm package to be installed in the primary-vault project. For now I use a combination of npm link and npm bin to call the script from the primary-vault without installing dependencies.

Prerequisites

  • Node.js and npm (I have 20.11.1/10.2.4 on Windows 11)

Usage

  • Clone this repo
  • Go to the dendron-move-images folder
  • Link the library
    npm link
  • Go to your dendron primary vault
  • Link on the other side
    npm link dendron-move-images
  • Run command with standard settings (while still in dendron primary vault)
    dmi

Settings

  • l: logs the primary-vault and secondary-vault data
  • y: skip confirm
  • svn: define the secondary vault name. Without this will take the first vault in dependencies as the secondary vault.

Example

dmi -ly --secondary-vault=other-vault

Will be

{
  "l": true,
  "y": true,
  "secondary-vault": "other-vault"
}

Todo

  • Images relative path shoud be customizable
  • It crashes if any folder in the path assets/images does not exist, it should create them instead
  • Refactor tests
  • Tests with images in comment blocks and remote images from the web
  • Not tested with the youtube preview image format
    Example:
    [![Developers](http://img.youtube.com/vi/KMU0tzLwhbE/1.jpg)](http://www.youtube.com/watch?v=KMU0tzLwhbE)
    
  • npm package

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published