This might leave behind some duplicates (for me at least, I had embeds followed by download buttons).
Step 4: Replace ‘categories’ with tags (because Obsidian can only handle one ‘tag’ type field)
This’ll do it:
# assumes yaml, ymlthis, stringr, readr, and magrittr are installedlibrary(magrittr)# Define a function to manipulate the yaml itemsmanipulate_yaml <- function(file) { # Read the yaml from the file y <- readr::read_file(file) y <- stringr::str_split(y, pattern = "---") %>% .[[1]] content <- y %>% .[3] y <- y %>% .[2] %>% ymlthis::as_yml() #y <- read_yaml(file) # Get the items between categories and tags items <- y$categories # Prepend categories/ to each item items <- paste0("category/", items) # Replace categories with tags y$tags <- append(y$tags, items) # Remove categories #y$categories <- NULL # Remove the second occurrence of tags #y$tags <- y$tags[1] #make the header text again y <- strsplit(yaml::as.yaml(y), "\n") # Return the modified file y <- c("---\n", y[[1]], "\n---\n", content, "\n") return(y)}# Get the paths of all .md files in a given directory# You can change the directory to your desired onedir <- "C:/.../"files <- list.files(dir, pattern = "\\.md$", full.names = TRUE)# Apply the function to each file and write the modified yaml back to the filelapply(files, function(file) { # Manipulate the yaml y <- manipulate_yaml(file) # Write the yaml back to the file readr::write_lines(x = y, file)})
Step 3: Ensure the url string follows the : in the footnote:
Find: (?<!\r[[:blank:]]|\n[[:blank:]])(\[\^)(\d+)(]:)(\n|\r|\R)(\S+)
Replace: \1\2\3 \5
Step 2: Replace footnotes not preceded by a newline using:
Find: (?<!\r[[:blank:]]|\n[[:blank:]])(\[\^)(\d+)(]:)
Replace: \r\1\2\3\4
Step 1: Replace footnotes with [\d] form with [^\d] form
Find: (\[)(\d+)(])
Replace: \[\^(\2)]
Step 0: First I used either the Wordpress export to Hugo plugin or the Wordpress export to Gatsby…I’ve forgotten. The markdown was pretty messy, so I ran the below (and then the regex above using notepad++…I forget which of these two: