I gave up on this task. I’ll try to get back to it much later, probably writing the parser myself, and simplifying it significantly. Will come back to that later, and only then will write a proper post to my primary blog. Let this shit live here for a while.



So I updated the logic, and don’t rename files with their ids. I just rename the files and directories according to its creation time.

  1. Rename the files to dates.
  2. Insert links whenever it can.
  3. Insert toml-metadata.
  4. The rest is a manual work, I think.

1. Rename the files to dates

Prompt:

Very bad. Forget this script and write me another one.

I provide you a path that have markdown files and directories.

  1. Check every file in a given path
  2. Find the line that starts with the word Created: , e.g.: Created: December 12, 2016 9:10 AM
  3. Check whether the file has a directory counterpart with the same name (without the .md extension). E.g. example-name directory and example-name.md file.
  4. Rename both directory and the file, follow this pattern: YYYY-mm-DD-HHMM for directory and YYYY-mm-DD-HHMM.md for a markdown file, where YYYY is the year, mm is the month, DD is the day of the month, HH is hours in 24-hr format, MM is minutes. E.g. 2016-12-12-0910. Take the date from Created: .
  5. If there’s the file and directory with that name already, increase minute by one for both file and directory, e.g. 2016-12-12-0911, so the filenames would be unique.
  6. If there’s just a file and no directory with the same name, I’d like to rename the file with the same logic.

If it makes the renaming correctly, I’ll explore the links by myself, manually. There’s not so many attachments I’d like to actually keep.


2. Insert links whenever it can