The Twor-Bot

Customizing Octopress Pages

| Comments

After creating a simple blogging site, let’s now create some custom pages for our site like about and home pages.

Before that if you want to publish the blog page in yoururl.com/blog instead of yoururl.com and you just want your own index page at yoururl.com, then just open up the Rakefile and edit the blogindex_dir to :

1. blog_index_dir  = 'source/blog'

so that the blog page is now created at the your_url.com/blog.

To have your own page for the home, rake has another task for you called the rake newpage. If you are writing it as bundle exec rake newpage["index.html"], then it will create a index html page in that source directory.

so follow the command:

1. bundle exec rake new_page["index.html"]

Then go and edit it as you like.

For an instance let us change the layout. make it something like :

1. layout: home

Now we are telling the index.html file to follow the home layout. But we don’t have any till now. So go to your layouts folder and create a home.html file and add whatever you like and if you want to include your own head, header and footer files in home.html then just create those files in includes folder and add the lines in home.html as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30


  <html>
  
      {% include custom_head.html %}
  
      <body>

              <div class="any_class_in_your_css" >
              
                  {% include custom_header.html %}
          
                  <div class="any_other-class" >
                  


                      {{ content }}



                      {% include custom_footer.html %}

                  </div>

              </div>

      </body>

    </html>

And add your stylesheets in the stylesheets folder. And write the content, as we do in the _posts files for the blogs, in the index.html file.

And your custom page is done. Make sure in the header the navigation bar is correctly coded like :

1
2
3
4
5
6
7
8
9


<li><a href="{{ rooturl }}/">Home</a></li> <li><a href="{{ rooturl }}/about">About</a></li> <li><a href="{{ rooturl }}/blog">Blog</a></li> <li><a href="{{ rooturl }}/blog/archives/">Archives</a></li> <li><a href="{{ root_url }}/atom.xml">RSS</a></li>

Same links should be provided in the _includes/custom/navigation.html(as the blog page has this navigation file embedded. ). Then all done to preview.

But notice that in the navigation file I added the second line to link to a about folder and that will show in the browser like your_url.com/about.

How to do this? It’s much simpler than the first one.

1. bundle exec rake new_page[about]

A page without any extension is created as index.html within the desired folder (here it’s about).

Then just open that index file and do whatever you want to customize it.

And most importantly don’t write the link for the home page as just {{ rooturl }} in the navigation file and do write it as {{ rooturl }}/, otherwise the link will point to the same page which is being opened up in the browser.

All is set now and just run the commands:

1. bundle exec rake generate
2. bundle exec rake preview
3. bundle exec rake deploy

And all your codes are on the web now.

Open up yoururl.com or yoururl.github.io and have fun. :) :)

Comments