Setup a personal website/blog with Github pages

Posted by Naveen on April 24, 2020

Nowadays website for personal and portfolio became quite common. Its became a digital identity in the digital world. So getting up a personal website its a not big deal when we have numerous ready-made templates available over the internet with free of cost. 

In this article, we are using Github pages to build a static website.  Github pages provide us free hosting and no need to pay anything. And it is a free code repository for private and public repositories.

All you need to do is get the website template based on the available free themes and host them on Github.

For this article, I am using this template which is free.  You can select any kind of template from the site. 

Download template to your local system. This contains all the HTML code necessary for a website. This all code is static which means there is no server-side code like PHP etc.

Now open an account in Github if not there earlier.

Then create a public repository with name as  <github username>.github.io 

Now extract the ZIP file from the downloaded theme. 

Upload all the code in that ZIP file folder to the created public repository. (Drag all the content of all the files into the Github repository ).

Now go to the repository and check index file is available.

Now click on Settings tab of the repository.  Scroll down to the GitHub pages section and selects master from the dropdown Source . After you selected master from the dropdown you will find the link above , which is the link for your website. Its something like   https://<github username>.github.io/ 

If you click on that link you can navigate to the website which you created just now with Github pages and free themes. 

To customize it further you can edit the HTML files and keep your names and further modifications.

We can also directly generate the websites based on the Jekyll themes from the GitHub pages section.

To make it more dynamic like whenever any person trying to contact through Contact page, we can route that to any API or Google spreadsheet.

Here I tried routing contact page message to Telegram bot where I can get a message to my Telegram messenger.

 You can find here how to create a telegram bot. To make it simple, its nothing but a URL we can get to post messages.

URL looks like  https://api.telegram.org/bot{bot_token}/sendMessage?chat_id=123456789&text= {any text message}  

After this, we have to make changes in our code. We need to edit the file contact_me.js which is inside js folder of our repository.

Make below changes to contact_me.js

 

JavaScript
 


1
...
2
...
3
 event.preventDefault(); 
4
//After above line enter below snippet
5
      // get values from FORM
6
      var name = $("input#name").val();
7
      var email = $("input#email").val();
8
      var phone = $("input#phone").val();
9
      var message = $("textarea#message").val();
10
      var parmaDetails = "chat_id=chatid&text=";
11
      var payload= parmaDetails.concat(" Name:",name," Email:",email," Phone no:",phone," Message:",message,"&parse_mode=HTML");
12

                                        
13
....
14
...
15
 $.ajax({
16
        url: "https://api.telegram.org/bot{bot_id}/sendMessage",
17
        type: "GET",
18
        data: payload,
19
  
20
  .....


We are replacing POST method with GET method and sending payload with all the parameters from HTML form.

It is a simple blog with minimal changes to the code. So whenever any new blog is written, you can make a new post.html file and have to link it from the index file.