DEV Community

Cover image for Adrnlnjnky's Daily(ish) Blog Post
AdrnlnJnky
AdrnlnJnky

Posted on

Adrnlnjnky's Daily(ish) Blog Post

I'm going to start writing a daily-ish blog about what I'm working on and I'm
going to place it on my homepage. The first thing I'm going to do is pull in the script
from my Daily Journal builder and alter it to make my daily Blog Post.
Then I will write a script to build the markdown file that I will actually
write the daily(ish) Blog posts in. Finally I'm going to build a template for my Blog home page
so I can build the actual home page with the daily post embedded into it.

Here is a bit of my build script relevant to the Daily Journal

// create some date variables
month=$(date +'%B')
day=$(date +%d)
yesterday=$(date '+%d' --date='1 day ago')
year=$(date +Y)

// Build my Daily Journal
page='Daily'
rm /PATH/TO/Journals/Daily/Daily.md
touch /PATH/TO/Journals/Daily/Daily.md
i=1
while [[ $i < 9 ]]; do
  next_journal=/Journal/Daily/$(date '+%B/%d%B.md' --date="${i} day ago")
  cat $next_journal >> /PATH/TO/Journals/Daily/${page}.md
  // echo "$next_journal"
  let i++
done

pandoc -s /PATH/TO/Journals/Daily/${page}.md \
-c /PATH/TO/Helpers/Style/Header.css \
-c /PATH/TO/Helpers/Style/index.css \
-o /PATH/TO/Journals/Daily/index.html \
-A /PATH/TO/Helpers/HTML/Footer.html

Enter fullscreen mode Exit fullscreen mode

Ok this bit goes out and pulls the articles from my personal folder and
compiles them into an html document. For my journal I want several days posted
but for my blog post things are a bit easier.

( I've repeated the relevant bits for clarity here. )

// Build my Daily Blog Post

// create some date variables
month=$(date +'%B')
day=$(date +%d)
year=$(date +Y)

// create a variables to be used for the folder and the document names.
page='Daily'
title=${day}${month}${year}.md

// This will go to my personal articles folder find todays blog post and generate an HTML
// page in my Bloging folder.

pandoc -s  PATH/TO/${page}/${title}
-c /PATH/TO/Helpers/Style/Header.css \
-c /PATH/TO/Helpers/Style/index.css \
-o /PATH/TO/Articles/Daily/index.html \
-A /PATH/TO/Helpers/HTML/Footer.html

Enter fullscreen mode Exit fullscreen mode

Now for all of that to work my Blog posts have to actually exist. For that I
wrote a little template file with the title, date, a header and a signature.
Then I wrote this little script to generate the file. This will help me avoid
the inevitable typeos if I should write my file name hand every day.

// create some date variables
month=$(date +'%B')
day=$(date +%d)
year=$(date +%Y)

// create a variables to be used for the folder and the document names.
dir='Daily'
title=${day}${month}${year}.md

// check to see if the file exists
if [ -f PATH/TO/$month/$NewJournal ];
then
  echo "${title" Blog Exists"
else
  cp PATH/TO/Daily/template.md PATH/TO/${dir}/${title}
fi

Enter fullscreen mode Exit fullscreen mode

With those two bits set up I now have a daily Blog post that I can write in
Markdown, and convert into HTML when I move it into my Blog. That if loop is
there to make sure I don't accidentally write over an existing blog post.

As I put this together I realize that it's probably time for me to look at the
html/template package in Go to start building my entire blog site, so I decided
to through a quick hack together so that this will work for now. In the next
few days I'll post what I came up with after I have studied the HTML packages for Go.

The last part of my hack I copied my template into two files, Top and Bottom. Then I used pandoc to build the index page, with the Blog post sandwiched in the middle.

// Build the Home Page

// variable that matches the name of the daily blog
title=${day}${month}${year}.md

// pandoc the two halves of the Home page with the
// article sadwiched in the middle
pandoc -s  PATH/TO/${page}/${title}
--include-before-body="PATH/TO/Helpers/Templates/HomeHeader.html" \
--include-after-body="PATH/TO/Helpers/Templates/HomeFooter.html"

Enter fullscreen mode Exit fullscreen mode

Thanks for taking the time to read my first Daily Blog and check back soon to
see what I'm up to next.

Thanks for reading
and remember:
Smile it might hurt!

Tom Peltier

This has been another SmokingEars Production!!

Top comments (0)