Skip to main content

Embedding Github code into your Blogger blog

When I have thought about writing my own programming blog, it seems very easy to me I just have to login into Blogger using my gmail account. But in process of writing my first blog I  have faced a lots of problems like how to format my content how to insert images and a lots of things, But the major one is how to enter my my hand written well formatted code into my blog. So I have tried to just copy paste the code into Compose mode and also tried to embed it into HTML but I was not able to maintain the format of my code.

So have done some research over the net and found a lots of ways to do so there are lots of JS plugins to do so etc. But one way seems to be very cool and  easy to me is posting your code on Github Gist and then making reference from your blog. We should not confuse gist with git, both are separate things. Git is a popular source code management system while Gist is really an awesome way to share your well formatted code with anyone on any platform with just a javascript call, and below I am going to show you how to do that.

You can refer your complete gist repo or you can choose any file from your repo to do so. To do this first of all you need to create a Github account, it is very easy and you can found a lots of tutorials for that even on the official Github website. Then you need to make a gist repository for that you can also find tutorial on this link about gists.

Lets walk through below steps and share your github code on your blog

First of all you need to create a gist repository on e.g. this is one of my gist repo CustomSolrRepo.
you can create your Gist repo online on this link, all you need to do is just enter a filename with extension on top and then  add some code below and then click on create public gist, you can also create a secret gist if you want.




Now you need to copy the complete script tag which is just right to Embed dropdown box.



















And paste it in your blog, but you need to open your blog in HTML mode and you should paste it at the end after any tag. You might have created more than one file in your gist repository so to embed code of only one file into your you need to mention that file as argument inside the script tag e.g.

<script src="https://gist.github.com/njnareshjoshi/98eafbaaa55b919f551e.js?file=CustomSolrRepoApp.java"></script>

Same I am doing in blog here



And you can the output here


However when you will switch to Compose mode again you will not be able to see that but you can see that in Preview mode.

Comments

  1. Free easy & simple way to learn programming online we provide niit projects, assignments, cycle tests and much more..
    visit ====>>> https://githubhelp.blogspot.in/

    ReplyDelete
  2. Thanks bro ..
    Really Helpful post.

    ReplyDelete

Post a Comment

Popular posts from this blog

Java Cloning - Copy Constructor versus Cloning

In my previous article Java Cloning and Types of Cloning (Shallow and Deep) in Details with Example , I have discussed Java Cloning in details and answered questions about how we can use cloning to copy objects in Java, what are two different types of cloning (Shallow & Deep) and how we can implement both of them, if you haven’t read it please go ahead. In order to implement cloning, we need configure our classes to follow below steps Implement Cloneable interface in our class or its superclass or interface, Define clone() method which should handle CloneNotSupportedException (either throw or log), And in most cases from our clone() method we call the clone() method of the superclass. And super.clone() will call its super.clone() and chain will continue until call will reach to clone() method of the Object class which will create a field by field mem copy of our object and return it back. Like everything Cloning also comes with its advantages and disadvantages. However, Java c...

Creating objects through Reflection in Java with Example

In Java, we generally create objects using the new keyword or we use some DI framework e.g. Spring to create an object which internally use Java Reflection API to do so. In this Article, we are going to study the reflective ways to create objects. There are two methods present in Reflection API which we can use to create objects Class.newInstance() → Inside java.lang package Constructor.newInstance() → Inside java.lang.reflect package However there are total 5 ways create objects in Java, if you are not aware of them please go through this article 5 Different ways to create objects in Java with Example . Both Class.newInstance() and java.lang.reflect.Constructor.newInstance() are known as reflective methods because these two uses reflection API to create the object. Both are not static and we can call earlier one on a class level object while latter one needs constructor level object which we can get by using the class level object. Class.newInstance() The Class class is th...

Everything About Object Oriented JavaScript

Complete explanation of Object Oriented JavaScript 01:50  JavaScript Objects 02:36  Objects in Objects 04:12  Constructor Functions 05:58  instanceof 06:28  Passing Objects to Functions 08:09  Prototypes 09:34  Adding Properties to Objects 10:44  List Properties in Objects 11:38  hasOwnProperty 12:42  Add Properties to Built in Objects 14:31  Private Properties 18:01  Getters / Setters 21:20  defineGetter / defineSetter 24:38  defineProperty 27:07  Constructor Function Getters / Setters 29:40  Inheritance 37:13  Intermediate Function Inheritance 39:14  Call Parent Functions 41:51  ECMAScript 6 47:31  Singleton Pattern 49:32  Factory Pattern 52:53  Decorator Pattern 54:52  Observer Pattern