Skip to contentSkip to author details

blog

A 9-post collection

Using Prism Syntax Highlighting instead of Google Prettify

Written by Michael Earls
 blog  Code  programming

In a previous post, I discussed how to add code formatting (syntax highlighting) to your Ghost blog.

Since then, I've decided to switch to using Prism syntax highlighter. Prism uses more standards-compliant mechanisms for marking up code. Specifically, it uses a class on the code element to mark what language the code block is written in. It also allows you to pick which features you wish to use and download files specifically catered to your needs.

Unfortuantely, I already have a significant amount of code on my blog that is formatted for Google's Code Prettyfier. I decided to write some code to convert prettyfied code to Prism-formatted code. This is a temporary fix while I update my blog entries.

Here is the code I used to do the conversion:

function convertPrettyfierToPrism() {

    console.warn('there are ' + $('pre.prettyprint').length + ' prettyprint pre tags on this page');
    console.warn('there are ' + $('pre.linenums').length + ' linenums pre tags on this page');

    $('pre.prettyprint').each(function () {
        $(this).removeClass('prettyprint').children('code').each(function () {
            $(this).addClass('language-clike');
        });
    });

    $('pre.linenums').each(function () {
        $(this).removeClass('linenums').addClass('line-numbers');
    });
}

I used the c-like language since that is what most of my code is (there is CSS, VB, and PHP in my blog, but most of it is either JavaScript or C#).

Standardizing Ghost Client Development

Written by Michael Earls
 blog  programming  ghost  GTCA

While Ghost is a great blogging platform, developers of custom themes may find themselves reinventing some common blog functionality (Google analytics, blog comments, etc.) Each developer has most likely come up with their own way to implement each of these features in their blog. But what happens when the blog owner changes themes? Right now, they'd have to redo all of their code injection to match the requirements of the new theme. If there was a standard way to define these properties, then switching themes would be easy and would not require any changes on the user's part.

Jack Preston has developed a great standard for setting common configuration values by using his GTCA object. It meets the needs of a good standard for configuration variables.

It is a great idea and I'd like to expand on it a little.

Functional Standardization

While configuration settings are the current purpose behind GTCA, I would like to put forth an additional use case: functional standardization.

There are things that I would like to add to all of my themes that require the user of the theme to call a function on the window object. It would be nice if I could roll those calls into a functional GTCA standard.

However, this will require a bit more effort with regard to GTCA development and deployment. In short, it would require that GTCA go from being a simple "include this code somewhere in your page before {{ghost_head}}" to being a full-fledged CDN-hosted .js file that theme designers could include (or download).

Example

Here is what I would add first if GTCA were to add functions in addition to variables. This code adds the ability to bind icons to any element by using a specific CSS class and providing a Font Awesome icon name as well as an optional size.

Then, all the GTCA-compliant theme author would have to do is add a link to the gtca.min.js file in their default.hbs file.

Then, they would instruct their users to put the following code in their settings on Ghost:

window.__themeCfg.iconMap.defaultIconSize = 'fa-lg';  
window.__themeCfg.addLinkIcon('nav-home', 'fa-home');

Of course, this opens the doors for the possible nightmare of dependencies (my code makes use of jQuery). I'm sure I could rewrite my code to be plain old JavaScript, so that would limit some of the liability.

So, in this case, I would include a link to the gtca.min.js file as well as the gtca-icon-map.min.js file in my default.hbs file.

My idea is not fully fleshed out, but I'd like to put it out there for discussion. I think GTCA is a great idea and a good start to add client functionality to Ghost.

I am afraid that this line of thinking could lead to over engineering and we'd end up with a big giant mess, but I do feel that some basic functionality in addition to configuration data would be acceptable.

Thoughts?

Am I abusing Ghost?

Written by Michael Earls
 blog  programming  ghost

I have been working steadily on creating my new Ghost blog to be exactly what I want. However, I have found myself dipping into JavaScript to sew up the loose ends that I perceive with Ghost's built-in functionality.

Too much WordPress?

Am I trying to create a blog that has more WordPress in it? Have I spent so much time using a CMS that provides things like plugins, widgets, and server-side code that I'm defiling the elegance of the creators' original intent?

Perhaps blogs aren't meant to have dynamic icons, user-changeable themes or context-aware sidebars.

Client-side scripting OK?

Or, maybe they are. Maybe I've been a server-side developer for so long that I'm missing the point of client-side scripting - to do the things that servers just aren't good at. Perhaps I need to utilize client script to do the "heavy lifting" of modifying the page without having to reload the page every time the user clicks on something.

I really don't know the answer. I'm a little bit uncomfortable as I add more and more code to my theme. It's also a bit strange to see my page "sputter" as it loads the scripts and applies the styles.

Conclusion

I am pleased with the final result and my home page loads in under 1.5 seconds. I guess that's the ultimate goal I've had - better performance. Many people in the Ghost community refer back to the focus of Ghost - content, but as a developer, I am concerned with performance and SEO for the users of my theme. I still believe that "content is king", but not for me. I have a dual-purpose blog. Sure, I have content (you're reading it), but I am writing about the very software that I use to write with.

Dynamically adding icons to a Bootstrap nav menu in Ghost

Written by Michael Earls
 blog  bootstrap  programming  icons  navbar

Update: I have written another post about an alternate approach to defining the link-to-icon mapping.

Note: I wrote this post to describe how I added icons to my Ghost navbar, but this process can work with any website that uses unique classes for links. Technically, it can bind an icon to any element decorated with a css class.

I am currently very pleased with how Bootstrap is working on my custom Ghost blog theme.

However, I wanted to use FontAwesome icons on my navbar. Since I couldn't control the CSS classes coming from dynamically generated content on my hosted server, I had to add some client-side script to add them after the page loads.

In my theme, each navbar link is tagged with a nav-{{slug}} class, so I have something to work with. Here is what my navbar looks like as presented to the visitor's browser:

<div class="collapse navbar-collapse" id="ghost-menu-navbar-collapse-1">  
    <ul class="nav navbar-nav">
        <li class="nav-home active" role="presentation"><a href="https://cerkit.com/" aria-label="Home">Home</a></li>
        <li class="nav-about" role="presentation"><a href="https://cerkit.com/author/michael/" aria-label="About">About</a></li>
        <li class="nav-my-public-key" role="presentation"><a href="https://cerkit.com/my-public-key/" aria-label="My Public Key">My Public Key</a></li>
    </ul>
    <ul class="nav navbar-nav navbar-right">
        <li class="nav-test navbar-text" role="presentation">No Link icon test</li>
        <li><a href="https://cerkit.com/rss/" role="presentation" id="subscribe-button"><i class="fa fa-fw fa-lg fa-rss"></i>&nbsp;&nbsp;Subscribe</a></li>
    </ul>
</div><!-- /.navbar-collapse -->

Link-to-Icon Mapping

Since each navigation link has its own tag, we can create a mapping to the desired icon. I am using the following four icons for my navbar:

Home - <i class="fa fa-fw fa-lg fa-home"></i>
User - <i class="fa fa-fw fa-lg fa-user"></i>
Key - <i class="fa fa-fw fa-lg fa-key"></i>
Cogs - <i class="fa fa-fw fa-lg fa-cogs"></i>

Now, we simply need to map them to the nav links. We do this by using a JSON-formatted Icon Map and jQuery code that runs on the page ready handler.

Here is what the link-to-icon map looks like for this site (at the time of writing):

var navbarIconMap = {  
    'defaultIconSize' : 'fa-lg', 
    'iconMaps' : [
        { 'target' : 'nav-home', 'icon' : 'fa-home' },
        { 'target' : 'nav-about', 'icon' : 'fa-user' },
        { 'target' : 'nav-my-public-key', 'icon' : 'fa-key' },
        { 'target' : 'nav-test', 'icon' : 'fa-cogs' }
    ]
};

Note: This object is defined in the Footer of the Code Injection settings screen on your Ghost blog. For non-Ghost sites, you will need to ensure that this variable is defined in a <script /> tag outside of the $(document).ready(); block.

Note: you may notice that it's possible to bind an icon to any class on your page, not just navigation links.

As you can see, the object has two properties:

  • defaultIconSize - The size of the icon to use when rendering (if this is an empty string, then the default FontAwesome font size will be used).
  • iconMaps an array of map objects containing the information required to map your nav links to icons.

iconMaps contains objects that have three properties:

  • target - the name of the css class of the nav element to bind the icon to (ex: nav-home)
  • icon - the FontAwesome name of the icon (Ex: fa-home)
  • size - (optional) - The size of the icon to be displayed (ex: fa-lg, fa-3x, etc.). If this value is not provided, it will use the value stored in defaultIconSize.

What happens after the page loads?

Once the page is ready, the following code will execute (within the $(document).ready(); handler):

if (navbarIconMap != null) {  
    for (var i = 0; i < navbarIconMap.iconMaps.length; i++) {
        curIconMap = navbarIconMap.iconMaps[i];
        // see if the current map provided a size. If not, use the default
        curSize = 'size' in curIconMap ? curIconMap.size : navbarIconMap.defaultIconSize;

        // set the icon on the navbar item
        console.log('curIconMap.target = ' + curIconMap.target);

        targetNavbarItem = $('.' + curIconMap.target);

        console.log('$(targetNavbarItem).html() = ' + $(targetNavbarItem).html());

        targetItemFirstChild = $(targetNavbarItem).children()[0];

        // figure out if the nav item has any links in it. If so, use that as the icon parent.
        // Otherwise, use the navbarIconItem.
        iconParentElement = targetItemFirstChild == null ? targetNavbarItem : targetItemFirstChild;

        console.log($(iconParentElement).html());

        // insert the icon element at the beginning of the parent
        var iconElement = createIcon(curIconMap.icon, curSize);
        $(iconParentElement).prepend(iconElement);
    }
}

First, we make sure that the navbarIconMap is not null. This is how we determine whether or not to add icons to the navbar.

Then, we loop through each of the maps in the iconMaps array in our navbarIconMap, setting a few variables in the process. In particular, we set the size of the icon based on the size property on the current iconMap. If that's not set, then we set it to the navbarIconMap.defaultIconSize value. If that is blank, then we use the default size as set by FontAwesome.

We then get a handle on the target navbar item by using its class name provided by the curIconMap.target property. Once we have it, we then look to see if there are any child elements. This is done so that we can put the icon within the <a> tag so it is part of the link. If there are no children, then the code will simply add the new icon element to the beginning of the element (this happens when there is just text in the navbar nav item).

The system creates the icon in the createIcon(icon, size) function:

function createIcon(icon, size) {  
    var iconElement = $(document.createElement('i')).attr('class', 'fa fa-fw ' + icon + ' ' + size).append('&nbsp;');
    console.log('iconElement class attribute value: "' + iconElement.attr('class') + '"');
    return iconElement;
}

This is mostly just inline jQuery that embeds a call to the document object to create an <i> tag that we can use to display our icon. It then adds the class attribute as defined by the function arguments. After that, it appends a space so the icon doesn't sit too close to the other elements/text in the nav element.

I sprinkled in a few console.log() calls so I could check my sanity along the way. I left them in this post for completeness.

Conclusion

The benefits of using Bootstrap on my blog are enormous. I have been able to rapidly extend the Ghost theme and quickly develop code to extend the functionality and appearance of my blog.

This dynamic navbar icon project is one of many projects I've worked on using Bootstrap and Ghost. I have also created a sidebar architecture that allows me to add items from various Ghost contexts to the sidebar after the page loads. I plan to write about that next. As of this writing, there is a "Share" panel that contains social media buttons that allow you to share each post. That panel was actually defined in the post.hbs file and then moved to the sidebar after the page loaded. It does not load for other pages. I will provide more details in the near future.

I hope this overview of my work has been beneficial to you. Please leave a comment if you have any questions or wish to contribute ideas on how this could be done more efficiently.

As always, you can contribute to the theme project or even fork it on GitHub.

Creating a Bootstrap Theme Selector for your Site

Written by Michael Earls
 blog  bootstrap  themes  development  bootswatch

I have recently converted my Ghost blog to use Bootstrap. As part of that, I decided to add a little toy to the sidebar that would allow users to change the Bootstrap theme that the site uses to display its content. All code for my custom theme can be found on GitHub in the ghost-cerkit-theme repository.

This post will outline the design and code for the theme selection "control".

Themes

I am using the Bootswatch themes for my website. This will give us quite a few decent looking themes to choose from. They're also free.

Source Files

For this control to work, we will need to add an id to the link tag that we use for our initial Bootstrap theme (bootstrap-theme):

<link id="bootstrap-theme" href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/superhero/bootstrap.min.css" rel="stylesheet"  crossorigin="anonymous" />

This will allow us to use this link element in jQuery to actually change the CSS source file location.

You will also need to add a link to the JavaScript code in your page. For my Ghost theme, I used the following code below the link to jQuery:

<script type="text/javascript" src="{{asset "js/bootstrap-theme-selector.js"}}"></script>

In order to display this and other controls on the side, I have added a sidebar partial to my Ghost theme.

<!-- sidebar -->  
{{!include the various components}}
{{> "search-form"}}
{{> "sidebar-bio"}}
{{> "sidebar-theme-picker"}}

Let's take a look at the code for the sidebar-theme-picker.hbs partial.

<div class="panel panel-primary">  
    <div class="panel-heading">
        Alternate Theme
    </div>
    <div class="panel-body">
        <form class="form-inline" id="theme-selection-form">
            <div class="form-group">
                <div class="input-group">
                    <select id="theme-selector" class="form-control">
                        <option value="cerulean">Cerulean</option>
                        <option value="cosmo">Cosmo</option>
                        <option value="cyborg">Cyborg</option>
                        <option value="darkly">Darkly</option>
                        <option value="flatly">Flatly</option>
                        <option value="journal">Journal</option>
                        <option value="lumen">Lumen</option>
                        <option value="paper">Paper</option>
                        <option value="readable">Readable</option>
                        <option value="sandstone">Sandstone</option>
                        <option value="simplex">Simplex</option>
                        <option value="slate">Slate</option>
                        <option value="spacelab">Spacelab</option>
                        <option value="superhero">Superhero</option>
                        <option value="united">United</option>
                        <option value="yeti">Yeti</option>
                    </select>
                </div> <!-- .input-group -->
            </div> <!-- .form-group -->
            <button class="btn btn-success form-control" onclick="clearTheme()">Reset</button>
        </form>
    </div>
</div>

This will give us the drop down control that we need to choose the theme.

The JavaScript code that wires this control up to the change event can be found in the bootstrap-theme-selector.js file.

In addition, all initialization of the variables for the theme selector can be found in the site-init.js file. Here is the required code for initialization of the theme selector:

var linkToBootstrapCDN = "//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/";  
var themeStyleCss = "/bootstrap.min.css";  
var defaultTheme = 'superhero';  
var showThemeSelector = true;

Here is the code that runs when the document is ready:

$(document).ready(function() {

    var selectedTheme = $.cookie('user-theme');

    if(selectedTheme != null) {     
        changeTheme(selectedTheme);
    }
    else {
        setSelectedOption(defaultTheme);
    }

    $(document).on('change', '#theme-selector', function(e) {
        var selectedTheme = e.target.options[e.target.selectedIndex].value;
        setTheme(selectedTheme);
    });

    if(!showThemeSelector) {
        $('#theme-selector').css('display','none');
    }
});

We start by pulling a cookie out that stores the value of the user selected theme. If this value is not set, then we use the default theme as defined by our defaultTheme variable. Otherwise, we use the theme name as set in the cookie. We do this by calling the changeTheme() function, passing the name of the theme we wish to change to.

Here is the code for the changeTheme() function:

function changeTheme(selectedTheme) {  
    setSelectedOption(selectedTheme);

    var completeCssLink = linkToBootstrapCDN + selectedTheme + themeStyleCss;
    $('link#bootstrap-theme').attr('href', completeCssLink);
}

The first thing we do is call the setSelectedOption() function to loop through all of the options in the theme selection control and find the currently selected theme. When we find it, we set the selected attribute to 'true' (this has the same effect as adding an empty selected attribute). For options that aren't the currently selected theme, we simply remove the selected attribute altogether (it may or may not be on that option, but it doesn't hurt to attempt to remove a non-existent attribute).

After that, we build the entire link to the selected CSS file by combining the Bootstrap CDN address with the selected theme name and the filename to link to.

Then, we change the href attribute of the link element with the id of bootstrap-theme to point to the newly created CSS address. This is what triggers the browser to change the CSS theme that it uses to format the content.

Note: If you've made any CSS modifications that need to override the Bootstrap themes, you will need to also load those in the changeTheme() function after you have loaded the Bootstrap theme.

Here is the code for setSelectedOption():

function setSelectedOption(selectedTheme) {  
    $("#theme-selector option").each(function() {
        if ($(this).val() === selectedTheme) {
            $(this).attr('selected','true');
        }
        else {
            $(this).removeAttr('selected');
        }
    });
}

Selection control change event handler

In order to change the theme when the user selects a new theme from the drop-down list, we need to respond to the change event on the control. We wire up the change event by using the jQuery on() function like so (all of this happens during the $(document).ready() handler):

$(document).on('change', '#theme-selector', function(e) {  
    var selectedTheme = e.target.options[e.target.selectedIndex].value;
    setTheme(selectedTheme);
});

Note: #theme-selector is the id of the select control containing the list of themes.

After pulling the value of the theme out of the currently selected option, we call the setTheme() function, passing the name of the selected theme. Here is the code for setTheme():

function setTheme(theme) {  
    $.cookie('user-theme', theme, { expires: 170, path: '/' });
    changeTheme(theme);
}

As you can see, all this function does is set the user's cookie to hold the value of the selected theme and then call the changeTheme() function to trigger the browser to actually load the theme.

Resetting the theme

The sidebar form also contains a button that allows the user to reset the theme back to the default (as chosen by the blog theme author, or as defined in the header of the Settings->Code Injection section of the blog dashboard). The button itself is defined to call the clearTheme() function when clicked:

<button class="btn btn-success form-control" onclick="clearTheme()">Reset</button>

Here is the code for the clearTheme() function:

function clearTheme() {  
    $.removeCookie('user-theme', { path: '/' });
    changeTheme(defaultTheme);
}

All we do here is remove the cookie and change the theme to the default theme.

Hiding the control

The ghost-cerkit-theme allows you to hide this control by adding the following code to your header in Settings->Code Injection:

<script>  
    showThemeSelector = false;
</script>

Here is the code to check to see if the theme selector should display:

if(!showThemeSelector) {  
    $('#theme-selector').css('display','none');
}

This code exists in the $(document).ready() handler below everything else.

Summary

While not necessary, this control allows the user to change your blog's theme to something other than the theme you set during your design. This allows them to set it to a theme that is easier for them to read, or just change it to something different to keep from getting bored.

Integrating Bootstrap Pagination with Ghost

Written by Michael Earls
 blog  bootstrap  programming  ghost  development  casper  pagination

In my previous post, I discussed how to integrate Bootstrap into the default Ghost theme. This post will cover the way that I modified pagination to use Bootstrap's pagination control.

To start, you will need to create a new pagination.hbs file in the partials folder in the root of your theme.

Because of the way that Bootstrap pagination works, I had to implement pagination using client-side JavaScript. The implementation uses a combination of server-side handlebars markup and client-side script.

The variables that we'll use in the pagination are defined in the site-init.js file in /assets/js.

var prev;  
var pages;  
var page;  
var next;  
var pageUrl;  
var pageUrlPrev;  
var pageUrlNext;  
var numbersSurroundingEllipses = 3;  
var useSimplePagination = false;

Here is the pagination.hbs for the customized pagination that I am using on my site:

<script type="text/javascript">  
    // set the values that we'll use in the bootstrap-pagination.js file
    {{!if there is no value for the variable, display a 0}}
    prev = {{#if prev}}{{prev}}{{else}}0{{/if}};
    pages = {{#if pages}}{{pages}}{{else}}0{{/if}};
    page = {{#if page}}{{page}}{{else}}0{{/if}};
    next = {{#if next}}{{next}}{{else}}0{{/if}};
    pageUrl = '{{page_url}}';
    pageUrlPrev = '{{pageUrl prev}}';
    pageUrlNext = '{{pageUrl next}}';
    pageUrlFirst = '{{pageUrl 1}}';
    pageUrlLast = '{{pageUrl pages}}';
</script>
<nav>
  <ul class="pagination bootstrap-pagination">
  </ul>
</nav>

This particular bit of code is a little confusing at first glance because it combines client- and server-side script. Let's break it down.

Since this code will appear each time the pagination control is displayed, we don't want to define the variables here. That's why they were defined in the init script file. So, each time the code runs on the page, it will set the value of the variables needed to create the pagination control.

Notice the if statements. Since these values may be empty, we can't just use them "raw" to define the values of our JavaScript variables. This will lead to a JavaScript error because essentially, an empty value would render the following code:

prev = ;

This is obviously incorrect. The {{#if prev}}{{prev}}{{else}}0{{/if}}; code will check to see if we have the prev variable defined. If so, we'll simply print it out. If not, we'll provide the number 0. It then repeats this process for the remaining initialization variables.

After the initialization code, we just create a nav control with the ul defined. It is empty when it is defined. In order to fill it with page navigation controls, we will use jQuery code when the document is ready.

The main default.hbs file includes a link to the pagination script. Here is the code that runs when the page starts up:

$(document).ready(function() {  
    // see if there are any previous pages
    // if so, append them to the pagination ul
    if (prev > 0) {
        $('ul.bootstrap-pagination').append('<li class="prev"><a href="' + pageUrlFirst + '" title="Go to first page" aria-label="First"><span aria-hidden="true"><i class="fa fa-angle-double-left"></i></i></span></a></li>');
        $('ul.bootstrap-pagination').append('<li class="prev"><a href="' + pageUrlPrev + '" title="Go to previous page" aria-label="Previous"><span aria-hidden="true"><i class="fa fa-angle-left"></i></span></a></li>');
    }

    if (useSimplePagination) {
        doSimplePagination();
    }
    else {
        doComplexPagination();
    }

    // if we have pages after this one, display the 'next' buttons
    if (next > 0) {
        $('.bootstrap-pagination').append('<li class="nxt"><a href="' + pageUrlNext + '" title="Go to next page" aria-label="Next"><span aria-hidden="true"><i class="fa fa-angle-right"></i></span></a></li>');
        $('ul.bootstrap-pagination').append('<li class="nxt"><a href="' + pageUrlLast + '" title="Go to last page" aria-label="Last"><span aria-hidden="true"><i class="fa fa-angle-double-right"></i></i></span></a></li>');
    }
});

As you can see, this code will add the navigate to first and navigate to previous buttons if we are not on the first page. It does this by using jQuery selectors to find any ul's on the page that use the .bootstrap-pagination class and appends the li controls that have the proper links.

Then, it checks to see if it should perform simple or complex pagination. Simple pagination merely shows "Page X of Y". Complex pagination shows the page numbers with an ellipses in the middle.

Simple pagination is performed by the following function:

function doSimplePagination() {  
    $('.bootstrap-pagination').append('<li><a href="' + pageUrl + 'page/"' + page + '" aria-label="Page ' + page + ' of ' + pages + '">Page ' + page + ' of ' + pages + '</a></li>');
}

This shows the user what page they're on.

Complex pagination shows a set number of page numbers on either side of an ellipses. The number of page numbers to show is determined by the variable numbersSurroundingEllipses. This value is set in the init script to a default value of 3.

It is possible to override this number on the Settings->Code Injection screen on your site's dashboard. If the value is set to -1, then the pagination control will display all page numbers.

The code to determine which pages to display on the control is a bit complicated. In short, it will show the number of pages as defined by the numbersSurroundingEllipses variables and the page directly before and after the current page so that you can navigate between pages. When you get within a certain number of pages from the end (calculated based on the pages - (numbersSurroundingEllipses * 2) calculation), the ellipses is not shown and a link to the page in the "middle" is displayed.

Refer to the doComplexPagination() function in the bootstrap-pagination.js file.

The very last thing we do when creating the pagination control is set the current page as active:

$('li.page' + page).addClass('active');

This provides you with Bootstrap pagination on your Ghost blog.

Here is a screenshot of the pagination control:

Simple Pagination:
Simple Pagination

Complex Pagination:
Complex Pagination

Note: This implementation requires a link to FontAwesome fonts (used in the left and right buttons).

To make this work, make sure you remove (or alter) any CSS in your theme's screen.css file that might define properties on the nav element or the pagination class. I had a terrible time getting this working at first because the default theme heavily customizes these elements and has class names that clash with Bootstrap.

Integrating Bootstrap with the Casper Ghost Theme

Written by Michael Earls
 blog  bootstrap  css  programming  ghost  theme  casper

I have been working on my blog lately to customize the theme and provide some features that I wanted. I started with the default Ghost theme (Casper) and modified it to suit my needs.

I have shared my theme (I named it "Ghost Cerkit Theme") on GitHub in a new repository:

Ghost Cerkit Theme

I added a few features, like Google custom Search and Disqus comments. I also added a sidebar that shows Author information for the author of the first post on the site. This is for blogs that have a single author that want to show their information on all pages (except the Author page, where it is suppressed).

To use the theme, there are a few customization options that you'll have to change. The hardest one is probably the Google custom search. Instructions for how to create a custom search engine can be found on the Ghost website. In order for your custom search to work, you will need to put your search engine id in the hidden cx form field on the search form.

I had to make significant changes to the screen.css file in order for Bootstrap to work properly. There are a lot of settings in the default theme that interfere with Bootstrap. I believe the best way to see what changed would be to view the diffs for the css file (and some of the core .hbs templates).

In addition to the custom search form, I also added the ability for the user to change the current site theme. Since the custom theme utilizes Bootswatch themes, I was able to add a selection box containing all of the Bootswatch themes. When the user picks a new theme, the site changes to that theme and stores its name in a cookie on the user's browser. Whenever the user visits a page on the site in the future, the chosen theme is used instead of the default theme. There is also a reset button to return the site to the original theme as defined by the site owner. It is possible to hide the theme selector. Just add the following code to the header:

showThemeSelector = false;

I also replaced the Casper pagination control with a Bootstrap pagination control that shows more detail. However, in order for this to work, I had to utilize JavaScript. This might affect SEO a bit, but with the theme retaining the meta tags for navigation, I don't think there will be a major impact.

I will be writing up additional blog entries about how I implemented the Bootstrap pagination for Ghost as well as an entry about the theme selector.

The theme still needs some polish to remove all of the CSS that interferes with Bootstrap. I worked as hard as I could to remove any customizations that are specific to my personal site, but there are still some things that need to be done in order for it to work completely.

I retained the MIT license on the original Casper theme so that there are no constraints on usage. I thought about licensing it under GPL 2, but adding a more restrictive sublicense seemed inappropriate in this case. If you use the code and feel inclined to give me attribution, that would be great. Just link to my website (https://cerkit.com).