John Rooksby's Blog

Tumblr blog

I’m switching from using customised Tumblr pages for my blogs, to using the API.  I’ve found writing and managing my own Tumblr themes too fiddly.  The Javascript below is a modification of something written by @stuaart .  It uses version 1 of the API.  Tumblr released API V2 last July - I’ll write/modify something using that when I have time.

<head>

<script type=”text/javascript” src=”http://YOURBLOGNAME.tumblr.com/api/read/js”>

</script>

<script type=”text/javascript”>

function blog()
{
  for (var i = 0; i < tumblr_api_read.posts.length; ++i)
  {
    var post = tumblr_api_read.posts[i];

    document.write(“<div class="YOURCSS">”
                   + post[“date”]
                   + “<em> - ” + post.type + “- </em>”
                   + “<a href="” + post.url + “">permalink</a></div>”
                   + “<div class="YOURCSS">”);

    switch (post.type)
    {
      case “regular”:
      {
           document.write(“<div class="YOURCSS">”
              + post[“regular-title”]
              + “</div><div class="YOURCSS">”
              + post[“regular-body”]
              + “</div>”);             
      }
      break;

      case “photo”:
      {
        document.write(“<div class="YOURCSS">”
            + post[“photo-caption”]
            + “<center><img src="”
            + post[“photo-url-400”] + “" /></center></div>”);           
      }
      break;

      case “quote”:
      {
        document.write(“<blockquote><h2>"”
            + post[“quote-text”] + “"</h2></blockquote><div class="YOURCSS">”
            + post[“quote-source”] + “</div>”);                   
       }
       break;

      case “video”:
      {
        document.write(“<div class="YOURCSS">”
              + post[“video-caption”] + “</div>”);
        document.write(post[“video-player”]);
      }
      break;
        
         case “link”:
      {
         document.write(“<div class="YOURCSS"><a href="”
                + post[“link-url”] + “">” + post[“link-text”]
                + “</a>”
                + post[“link-description”] + “</div>”);
      }
      break;
        
         default:
        {
        document.write(“<div class="YOURCSS">”);
        document.write(“<em>Error reading blog entry (type: ” + post.type + “) <a href="http://YOURBLOGNAME.tumblr.com">YOURBLOGNAME.tumblr.com</a></em></div><br>” );
        }
      break;
     
    }

    document.write(“</div><br>”);

  }
}

</script>

</head>

<script type=”text/javascript”>document.onload = blog();</script>

  1. canada-news reblogged this from johnrooksby
  2. johnrooksby posted this