My site only publishes from New York time
I ran into a fun problem this week. I moved my Eleventy source files to a different computer and realized that because my post dates are being read from the “date created” metadata of the files in finder, when the website files are copied, all the post display dates reset to the copied date as well, instead of retaining their original created date. I’m now realizing why they recommend NOT using “date created” in the Eleventy docs :)...
There is a way to override the date by manually typing a fixed timestamp in the markdown front matter. I’m annoyed by this because I want to be able to post nearly blank markdown files. In fact, many of my entries didn’t even have front matter previous to this discovery.
I put a lot of effort into reducing the steps to publishing, so I will not tolerate having to type out “date: 2025-03-12T16:43-04:00” every time I want to make a new post. Since I do already have my mkpost() bash script to create an index.md inside a new folder named with the current timestamp, I figured there must be a way to write the date to the contents of the markdown file at the same time as well.
I updated my script to look like this:
mkpost() {
export STAMP=$(date +%Y-%m-%dT%H:%M-05:00)
export POSTDIR=src/posts/$(date +%Y-%m-%d-%H-%M)
mkdir -p $POSTDIR
echo -e "---\ndate: $STAMP\n---" >> $POSTDIR/index.md
}
Great! Except not, because now the hour displayed on the website is different from the hour in the folder name and permalink. I really wanted to tear my hair out because I couldn’t believe how complicated this function had to be in the end. I went from a 1-liner to 12! All to accommodate daylight savings time. In a way I was lucky that this happened across the week where we sprung forward. Otherwise I never would have thought about a variable UTC offset.
I’m pleased to present my new mkpost() script which will automatically account for the clocks changing twice a year:
mkpost() {
export DST=$(date +%Z)
if [ $DST = 'EDT' ]; then
export OFFSET='04:00'
else
export OFFSET='05:00'
fi
export STAMP=$(date +%Y-%m-%dT%H:%M-$OFFSET)
export POSTDIR=src/posts/$(date +%Y-%m-%d-%H-%M)
mkdir -p $POSTDIR
echo -e "---\ndate: $STAMP\n---" >> $POSTDIR/index.md
}
Wasn’t this a thrilling entry??