I parsed all my Day One entries from the notes/2019/10-23-Wed/Export-from-DayOne.txt file, and now they’re in my website too.
The next step that I’d like to do is to find the images. I hope I hadn’t removed them entirely!
I can find the directory with this name, that’s the very first image I uploaded to that system:
photos/cd9fe903e2ef06dbfea4516b3665f395.jpeg
Did that with the help of this script:
#!/bin/bash
# Define the base directory
BASEDIR="/tmp/notes"
# Function to convert single quotes to typographic quotes
convert_quotes() {
sed -e "s/\([a-zA-Z]\)'/\1’/g" -e "s/'\([a-zA-Z]\)/‘\1/g"
}
# Function to parse date and convert to required format
parse_date() {
local date_str="$1"
local formatted_date_str=$(echo "$date_str" | sed 's/ at / /')
date -d "$formatted_date_str" +"%Y/%m-%d-%a/%H%M.md" 2>/dev/null
}
# Function to parse and create markdown files
parse_file() {
local input_file="$1"
local current_date=""
local weather=""
local location=""
local content=""
while IFS= read -r line; do
if [[ "$line" =~ ^[[:space:]]*Date:[[:space:]]*(.*) ]]; then
if [[ -n "$current_date" ]]; then
# Write the previous entry to a file
write_entry "$current_date" "$weather" "$location" "$content"
weather=""
location=""
content=""
fi
current_date="${BASH_REMATCH[1]}"
elif [[ "$line" =~ ^[[:space:]]*Weather:[[:space:]]*(.*) ]]; then
weather="${BASH_REMATCH[1]}"
elif [[ "$line" =~ ^[[:space:]]*Location:[[:space:]]*(.*) ]]; then
location="${BASH_REMATCH[1]}"
else
line=$(echo "$line" | convert_quotes)
if [[ "$line" =~ !\[\]\(.*\) ]]; then
content+="\n\n${line}\n\n"
elif [[ "$line" =~ ^---$ ]]; then
content+="\n\n${line}\n\n"
else
content+="$line\n"
fi
fi
done < "$input_file"
if [[ -n "$current_date" ]]; then
# Write the last entry to a file
write_entry "$current_date" "$weather" "$location" "$content"
fi
}
# Function to write the entry to a markdown file
write_entry() {
local date_str="$1"
local weather="$2"
local location="$3"
local content="$4"
local file_path="$(parse_date "$date_str")"
if [[ -z "$file_path" ]]; then
echo "Invalid date: $date_str"
return
fi
local dir_path="$(dirname "$file_path")"
mkdir -p "$BASEDIR/$dir_path"
local front_matter="+++
title = 'Day One Entry'
date = \"$(date -d "$(echo "$date_str" | sed 's/ at / /')" +"%Y-%m-%dT%H:%M:%S%z" 2>/dev/null)\"
draft = false
tags = ['diary', 'DayOne']"
if [[ -n "$weather" ]]; then
front_matter+="
weather = \"$weather\""
fi
if [[ -n "$location" ]]; then
front_matter+="
location = \"$location\""
fi
front_matter+="
+++"
echo -e "$front_matter\n\n$content" > "$BASEDIR/$file_path"
}
# Check if input file is provided
if [ -z "$1" ]; then
echo "Usage: $0 <input_file>"
exit 1
fi
# Parse the input file
parse_file "$1"
Now, removing the file.
2024-07-27-0023: I did it manually, not so many entries.