Monthly Archives: June 2015

Creating Custom Blogger Template From Scratch

Although when I started with it, I hardly knew anything about a blogger template, but it turned out, designing a blogger template is easier than designing a HTML template. Just a few basic concepts and you are good to go.

Firstly, before digging into the template code, we will look at the grammar needed to code our thing. This simple article assumes you can read basic HTML, CSS and XML. Nothing above the basic level, plain simple stuff. If not, whenever you do not understand something, make sure you search that term or tag on w3schools to understand it. Yes, that’s all you really need, trust me.

Planning the layout

First of all, how do you want your blog to look like when it’s done. Just a basic idea would do. You must know what you are working for. Here is what I made. It is the way most simple blogs look like. Two column layout, a header on top and a footer at bottom.

Header
Blog PostsSidebar
Footer

Not the most interesting table, yeah I know. HTML tables, not really my thing. But this is what our end result should look like, structurally.

Basic Structure

These few lines make up a basic web page. You will see that this is quite similar to what we’re doing.

<!DOCTYPE html>
<html>
  <head>
    <title></title>
  <head>

  <body>

  </body>
</html>

And this is how a basic blogger template looks like.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html b:version='2' class='v2' expr:dir='data:blog.languageDirection' xmlns='https://www.w3.org/1999/xhtml' xmlns:b='https://www.google.com/2005/gml/b' xmlns:data='https://www.google.com/2005/gml/data' xmlns:expr='https://www.google.com/2005/gml/expr'>
  <head>
    <title><data:blog.pageTitle/></title>
    <b:skin><![CDATA[ /* CSS here */ ]]></b:skin>
  </head>

  <body>
    <!-- Blog elements here -->
  </body>
</html>

Pretty neat, isn’t it? Now, the elements of a blogger blog. Blogger is built upon XHTML, and uses the same for retrieving and displaying data from the database. A basic block of a blogger template is called a section. So all of these are sections.

Header
Blog PostsSidebar
Footer

And you have to define each section before you add ‘widgets‘ to them. A basic section block looks like this.

<b:section id=' ' class=' ' maxwidgets=' ' showaddelement=' '></b:section>

where id is any unique identifier (for CSS and JS later) and class value is used to tell blogger where do we plan to place this section. Maxelements is the maximum number of ‘widgets’ we can add to this section. Generally, it is useful to limit the number of widgets in header and footer to one. Showaddelement is that ‘Add gadget’ link you see in the layout window. It takes boolean value ‘true’ or ‘false’. Now there are ‘widgets‘ that go into these sections. Every separate component that you see on your blog is a widget. The ‘blog posts’ is one widget, ‘blog archive’ is another, and so on. These widgets can be directly added from the graphical layout tab in the control panel of your blog, but it doesn’t hurt to know how to add them manually, does it?

<b:widget id="HTML2" locked="false" title="Some Title" type="HTML" />

Similarly here,

  • id – is just an unique ID
  • locked – can the widget be moved around, in the layout tab? (yes or no)
  • title – The title that will be displayed on top of the widget
  • type – One of the many basic types that blogger supports (html, blog, feed, header etc)

For example, your ‘blog posts’ widget will be something like this

<b:widget id='blog1' locked='true' title='' type='Blog' />

That’s it. Add it to the template and blogger will fill it with auto-generated code you need not care about. This was all for the basics. Let’s start with some code now. I am using Bootstrap  to save myself from writing unnecessary CSS. First thing you do here is enclose the entire body in either container or container-fluid div.

  • container – for fixed width layout
  • container-fluid – for dynamic body width

I personally prefer fixed. This is the code so far. I added container class to the <b:skin> which we can (and will) customize later.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html b:version='2' class='v2' expr:dir='data:blog.languageDirection' xmlns='https://www.w3.org/1999/xhtml' xmlns:b='https://www.google.com/2005/gml/b' xmlns:data='https://www.google.com/2005/gml/data' xmlns:expr='https://www.google.com/2005/gml/expr'>
  <head>
    <title><data:blog.pageTitle/></title>
    <b:skin><![CDATA[ .container { }  ]]></b:skin>
  </head>
  <body>
    <div class='container'>
    </div>
  </body>
</html>

Now add the divs for header, post area, right sidebar and footer and corresponding CSS classes. Code trimmed for brivity.

<head>
  <title><data:blog.pageTitle/></title>
  <link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css' rel='stylesheet'/>
  <b:skin><![CDATA[
    #container {
      max-width: 960px;
      margin: 0 auto;
    }
    #main-wrapper {
      width: 710px;
      float: left;
    }
    #sidebar-wrapper {
      width: 250px;
      float: right;
    }
    #footer-widgets {
      padding: 0px 0px 5px 0px;
    }
  ]]></b:skin>
</head>
<body>
  <div id='container'>
   <!-- Header -->
   <b:section class='header' id='header' maxwidgets='1' showaddelement='yes'>
      <b:widget id='Header1' locked='true' title='Blog title' type='Header' />
   </b:section>
   <div id='main-wrapper'>
     <!-- Blog posts area -->
     <b:section class='main' id='main' maxwidgets='' showaddelements='yes' />
        <b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog' />
     </b:section>
   </div>
   <div id='sidebar-wrapper'>
     <!-- Right sidebar -->
     <b:section class='sidebar' id='sidebar' maxwidgets='' showaddelements='yes'>
       <!-- Widgets can be added from layout page -->
     </b:section>
   </div>
   <div id='footer-widgets'>
     <!-- Footer -->
     <b:section class='footer' id='footer' maxwidgets='' showaddelements='yes'>
       <b:widget id='Attribution1' locked='false' title='' type='Attribution' />
     </b:section>
   </div>
  </div>
</body>

The above code should look like this on any blogger blog.

The mobile site, I must say, would look horrible. Extra efforts are needed to make the template responsive. Since we already have Bootstrap, that is not a big deal either. I must conclude this post now, and for mobile friendly site, I may write an article soon. Also, there is no SEO in this template. You must add relevant <meta> tags to make your blog more search engine friendly. You can always override CSS rules of bootstrap by writing your own in the <b:skin> section.

Thank you for reading!

TechMax Publications – Plagiarism Check

I study for my finals from various sources, the Internet, class notes and some reference books. This time though, I had this Computer Graphics, by Sanjesh Pawale, Techmax Publications. The books from this publishing house are everything what a Mumbai University guy needs to study for exam. Well, not exactly, but that’s how most see this book as.

So when I was reading it, I noticed that much of what I read in the book was something I already read someplace else. A quick browser history lookup revealed that the stuff were taken from Wikipedia. Wait, let me rephrase it, the stuff were copied and pasted from Wikipedia, including the text, images and caption.

For your information, the content of Wikipedia is licensed under creative commons attribution share-alike 3.0. The license states that the usage is unrestricted. even for commercial use as long as appropriate credits are given and indications of modifications are made. Moreover, the content, modified or original, must be distributed under the same license.

https://creativecommons.org/licenses/by-sa/3.0/

But there’s a bummer. The content copied by Techmax shows no attribution, no credits to Wikipedia or it’s authors, and the worst, they have copyrighted the book under their name and it’s totally restricted.

Here is a piece of text from https://en.wikipedia.org/wiki/Wikipedia:Copyrights

To re-distribute text on Wikipedia in any form, provide credit to the authors either by including a) a hyperlink (where possible) or URL to the page or pages you are re-using, b) a hyperlink (where possible) or URL to an alternative, stable online copy which is freely accessible, which conforms with the license, and which provides credit to the authors in a manner equivalent to the credit given on this website, or c) a list of all authors. (Any list of authors may be filtered to exclude very small or irrelevant contributions.)

So it is mandatory for TechMax to provide a backlink to the webpage they are lifting the content from. At least a bibliography at the end of the book. The second part to this is copyleft/share-alike policy. To quote,

If you make modifications or additions to the page you re-use, you must license them under the Creative Commons Attribution-Share-Alike License 3.0 or later.

Hence, Techmax is also violating this by copyrighting the content under their own restricting license. They should consider revising their license.

And finally, as far as the students are concerned, why not just take a little more effort and learn from the web instead of a printed version of the web.

Edit. A little proof of what I am talking about. The content in the image in copyrighted by *cough* Techmax *cough* and Wikipedia.

From Techmax, page8-23

From Wikipedia

As I said, this is just an instance. If anybody is interested, just send me a mail. I would be more than happy to provide you with more proof. Cheers!

A Day Of Struggle With Python IDEs

Yesterday, I gave up on doing my next web application project with QT. I knew C++ was never meant to be a language of the web, but I really had some hopes with QT. It actually is good, and apparently it would have ran faster than any other platform or language for the web. The problem is, it is a lot time consuming to develop anything in it, especially web apps. I really don’t have all that time. So I decided to do it in Python or Ruby. After reading some articles, it became clear, they are not much different, where python is a more general programming language, ruby is more towards the web, with it’s rails framework.

I choose Python, just because I know how to write code in python, beforehand. It was time to go shopping for some good frameworks to develop this thing. No doubt, finally I had to decide between Django and Flask. I choose flask. It was damn too simple, or at least it seemed like that. I tried the simple hello.py script which displays “hello world” on the localhost port 5000.

I tried that in emacs, but immediately felt the need for an IDE in this foreign land. I looked in my ‘Downloads’ folder, and luckily there was Aptana Studio 3 still sitting there. I used to have it installed when I was into PHP last year. Since then, it got removed and thrown into a corner. I installed it. I really loved Aptana back then, for it’s usability. But now, it started to act like a stubborn child, refusing to detect Flask. I googled and googled, but alas, no way. Many people seemed to be having the same problem, and the only solution I saw didn’t work.

Seeing no way, I uninstalled Aptana, and googled for other good IDEs. PyCharm was what most were recommending. I decided to give it a try. Turned out, it was a memory hogger. Both my CPUs were doing a constant 100% and other windows turned sluggish too. About half a tonne of RAM was what it was utilizing, with a single .py file open with 4 lines of text in it. No way, again. Removed it, and went to eat some food. Damn.

I was not ready to go to the sluggish Eclipse again, nor Netbeans for the same reason. Finally I settled for Komodo Edit, free lite version of the commercial Komodo IDE. It lacks many things that you will ask for in an IDE, and it is a little better than using bare emacs or vim. Still, for now, I am using it. Configured it to execute python script right inside the window following this tutorial, https://stackoverflow.com/questions/21686395/how-to-run-the-first-python-program-in-komodo-edit-8-5

Life’s good, but just hoping to learn flask for my next project as fast as I can.