I have a script mkblog which

  • Creates a slugged blog document
  • Links the document without the date (for easy editing)
  • Generates a uuid (for use as disqus_identifier)

Here's a snippet:

cat - > /tmp/${FILE} << EOF
layout: article
uuid: `uuidgen`
title: `echo ${TITLE}`
created_at: `date +'%Y-%m-%d'`
updated_at: `date +'%Y-%m-%d'`
categories: unfinished

In my _layouts/default.html, right above the closing </body>, I have the disqus-provided JavaScript.

<script type="text/javascript">
var disqus_shortname = 'coolaj86-gh';
(function () {
  var s = document.createElement('script'); s.async = true;
  s.src = 'http://disqus.com/forums/coolaj86-gh/count.js';
  (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
</body> <!-- RIGHT ABOVE THE END -->

In my _layouts/post.html I put a little conditional logic to load Disqus comments for all of the posts I've made since I started including uuids.

{% if page.uuid %}
<div id="disqus_thread"></div>
<script type="text/javascript">
    var disqus_identifier = disqus_identifier && 'badid' || '';
  (function() {
   var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
   dsq.src = 'http://coolaj86-gh.disqus.com/embed.js';
   (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript=coolaj86-gh">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
{% endif %}

In order to get a custom github domain I

  • echo "coolaj86.info" > CNAME - added the CNAME to the root of the blog
  • changed the A record on coolaj86.info at freedns.afraid.org to
  • changed the CNAME record for www.coolaj86.info to coolaj86.github.com


Add UUID's to Existing posts

ls _posts/ | while read P; do sed -i _posts/${P} -e "s|\(^title:.*\)|uuid: `uuidgen`\n\1|g"; done

Create short-name links

ls _posts/ | while read N; do NEW=`echo $N | cut -d'-' -f4-99`; echo "ln -s ../_posts/$N ./edit/$NEW"; done


set -e


if [ ! -n "${TITLE}" ] || [ -n "${2}" ]
  echo "USAGE: ${0} 'Title of my Blog Super-Post!'"
  exit 1

SLUG=`echo "${TITLE}" \
  | tr '[A-Z]' '[a-z]' \
  | tr ' ' '-' \
  | sed 's/[^a-zA-Z0-9\-]/-/g' \
  | sed 's/-\+/-/g' \
  | sed -e 's/^-//g' -e 's/-$//g'`

FILE=`date '+%Y-%m-%d'`-${SLUG}.md

if [ ! -e ${POSTDIR}/${FILE} ]
  mkdir -p "${POSTDIR}"
  cat - > /tmp/${FILE} << EOF
layout: article
title: `echo ${TITLE}`
categories: unfinished
updated_at: `date +'%Y-%m-%d'`
uuid: `uuidgen`

  HEY YOU: Remember to changed the category from unfinished.

  cat /tmp/${FILE}
  mv /tmp/${FILE} ${POSTDIR}/${FILE}

  mkdir -p ${EDITDIR}
  ln -s ../${POSTDIR}/${FILE} ${EDFILE}

echo "Saved ${EDFILE}."

By AJ ONeal

If you loved this and want more like it, sign up!

Did I make your day?
Buy me a coffeeBuy me a coffee  

(you can learn about the bigger picture I'm working towards on my patreon page )