Step wtfk: Accidentally delete htaccess file without a
htaccess_backup
I wanted to replace all instances of: _4626-550x367.jpg with: _-\d{3}x300 OR _-\300xd{3}
Step 10:
find:
\?resize=(\d{3})%2C\d{3}replace:
|\1Step 9: … Find:
\[<img src="\/static\/(\d{4}\/\d{2}\/[^"]+)"[^>]+\/>]\(([^)]+)\)Replace:
![[/assets/uploads\/\1]]Step 8: Yes this could be more efficient, replace the remaining html images Find:
\[<img\s+src="\/static\/(\d{4}\/\d{2}\/[^"]+)"[^>]+alt="([^"]+)"[^>]+>\]\(\/static(\/\d{4}\/\d{2}\/.*?)\)Replace:
![[assets\/uploads\3|\2]]Step 7: Replace other image links
Notepad++ again
Find:
(]\()(/static\/\d{4}\/\d{2}\/.*?)(\.jpg)Replace:
\1/uploads\2-300x200\3Step 6: Replace featured_image frontmatter with updated link Using Notepad++ regex search, with ”. matches newline” ticked Find:
(featured_image: )(/static\/\d{4}\/\d{2}\/.*?)Replace:
\1/uploads\2Step 5: Use FTP to download uploads from Wordpress install, and replace links in the markdown
Using Notepad++ regex search, with ”. matches newline” ticked
<a\s*href="http:\/\/sjgknight\.com\/finding-knowledge\/static\/(\d{4}\/\d{2}\/[^"]+)(?:".*?)>(.*?)<\/a>Replace:
![[assets/uploads/\1|\2]]\nThis 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 installed
library(magrittr)
# Define a function to manipulate the yaml items
manipulate_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 one
dir <- "C:/.../"
files <- list.files(dir, pattern = "\\.md$", full.names = TRUE)
# Apply the function to each file and write the modified yaml back to the file
lapply(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:
- node ./content/tomd.cjs
- node ./content/tomdpan.cjs
tomd.cjs
PATH: "vault://tomd.cjs"
TITLE: "tomd.cjs" tomdpan.cjs
PATH: "vault://tomdpan.cjs"
TITLE: "and using pandoc tomdpan.cjs"