Canonical Voices

Posts tagged with 'theming'

Max

Upgrading my blog theme with the Vanilla CSS Framework

Recently I have spent more and more time thinking about the usability of my website and the cleanliness of its code.

This has brought me to another iteration in its design process.

Of course also related to my employment at Canonical I have decided to give our Vanilla Framework a try.

The first thing I had to update is my gulp task to include node_modules during the build.

//  CSS
gulp.task("css", function () {
  return gulp
    .src(`${source}/assets/css/styles.scss`)
    .pipe(sourcemaps.init())
    .pipe(sass({
      includePaths: ['node_modules']
    }).on('error', sass.logError))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("assets/built/"));
});

Otherwise it wouldnt pick up on the imports. This is also described on the framework page.

Then I have included the basic settings from Vanilla in my styles file with

@import "vanilla-framework/scss/settings";
@import "vanilla-framework/scss/base";
@include vf-base;

The @include is necessary because vanilla provides mixins via the imported files. This way I can control exactly what I want on my blog, thus reducing bloat and data usage.

Just by doing this, the website, given its semantic HTML already looks pretty nice:

Upgrading my blog theme with the Vanilla CSS Framework

One thing that I would still like to highlight though is the main content vs the head of the webpage. After browsing through the patterns at https://docs.vanillaframework.io/en/ for a bit I decided that I am only going to need the `p-card` pattern to achieve this.

After including this with @import "vanilla-framework/scss/patterns_card"; and using the needed mixins for the default card, the highlighted one and the content inside the card with

@include vf-p-card-default;
@include vf-p-card-highlighted;
@include vf-p-card-specific-content;

I just had to add classes to my articles on the index page and the content on the post page to achieve the following:

One thing that still bothers me here is the focus of the content on the left side. So I went ahead and adjusted some of the margins to the sides and on the header.

An additional thing I added (or actually removed) afterwards is the Font. If you set the $font-base-family variable before including the Vanilla base mixin, it will replace the default Ubuntu Font. As my goal is a very data saving, content focused website, I have replace it with serif, sans-serif. This will use the Fonts that are installed on the system in that order.

So, if for any reason, there is no Font found that has [serifs](https://en.wikipedia.org/wiki/Serif), a Font without serifs will be used instead.

Resume

In a few hours I was able to reach a design that is both clear and allows the user to focus on the content, which is written text. The Vanilla Framework, and the way it is set up, made it possible for me to focus on the things that are important to me and disregard the rest.

This way I can leverage all the design decisions around readability etc. that the Vanilla team has put into the framework and still have a bloat-free, brutalisitc website design to my liking, that represents me on the Internet.

This is a great speed improvement and asset for someone like me who appreciates great design, but spends a lot of time in the backend.

Read more
Max

Upgrading my blog theme with the Vanilla CSS Framework

Recently I have spent more and more time thinking about the usability of my website and the cleanliness of its code.

This has brought me to another iteration in its design process.

Of course also related to my employment at Canonical I have decided to give our Vanilla Framework a try.

The first thing I had to update is my gulp task to include node_modules during the build.

//  CSS
gulp.task("css", function () {
  return gulp
    .src(`${source}/assets/css/styles.scss`)
    .pipe(sourcemaps.init())
    .pipe(sass({
      includePaths: ['node_modules']
    }).on('error', sass.logError))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("assets/built/"));
});

Otherwise it wouldnt pick up on the imports. This is also described on the framework page.

Then I have included the basic settings from Vanilla in my styles file with

@import "vanilla-framework/scss/settings";
@import "vanilla-framework/scss/base";
@include vf-base;

The @include is necessary because vanilla provides mixins via the imported files. This way I can control exactly what I want on my blog, thus reducing bloat and data usage.

Just by doing this, the website, given its semantic HTML already looks pretty nice:

Upgrading my blog theme with the Vanilla CSS Framework

One thing that I would still like to highlight though is the main content vs the head of the webpage. After browsing through the patterns at https://docs.vanillaframework.io/en/ for a bit I decided that I am only going to need the `p-card` pattern to achieve this.

After including this with @import "vanilla-framework/scss/patterns_card"; and using the needed mixins for the default card, the highlighted one and the content inside the card with

@include vf-p-card-default;
@include vf-p-card-highlighted;
@include vf-p-card-specific-content;

I just had to add classes to my articles on the index page and the content on the post page to achieve the following:

One thing that still bothers me here is the focus of the content on the left side. So I went ahead and adjusted some of the margins to the sides and on the header.

An additional thing I added (or actually removed) afterwards is the Font. If you set the $font-base-family variable before including the Vanilla base mixin, it will replace the default Ubuntu Font. As my goal is a very data saving, content focused website, I have replace it with serif, sans-serif. This will use the Fonts that are installed on the system in that order.

So, if for any reason, there is no Font found that has [serifs](https://en.wikipedia.org/wiki/Serif), a Font without serifs will be used instead.

Resume

In a few hours I was able to reach a design that is both clear and allows the user to focus on the content, which is written text. The Vanilla Framework, and the way it is set up, made it possible for me to focus on the things that are important to me and disregard the rest.

This way I can leverage all the design decisions around readability etc. that the Vanilla team has put into the framework and still have a bloat-free, brutalisitc website design to my liking, that represents me on the Internet.

This is a great speed improvement and asset for someone like me who appreciates great design, but spends a lot of time in the backend.

Read more
Max

Upgrading my blog theme with the Vanilla CSS Framework

Recently I have spent more and more time thinking about the usability of my website and the cleanliness of its code.

This has brought me to another iteration in its design process.

Of course also related to my employment at Canonical I have decided to give our Vanilla Framework a try.

The first thing I had to update is my gulp task to include node_modules during the build.

//  CSS
gulp.task("css", function () {
  return gulp
    .src(`${source}/assets/css/styles.scss`)
    .pipe(sourcemaps.init())
    .pipe(sass({
      includePaths: ['node_modules']
    }).on('error', sass.logError))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("assets/built/"));
});

Otherwise it wouldnt pick up on the imports. This is also described on the framework page.

Then I have included the basic settings from Vanilla in my styles file with

@import "vanilla-framework/scss/settings";
@import "vanilla-framework/scss/base";
@include vf-base;

The @include is necessary because vanilla provides mixins via the imported files. This way I can control exactly what I want on my blog, thus reducing bloat and data usage.

Just by doing this, the website, given its semantic HTML already looks pretty nice:

Upgrading my blog theme with the Vanilla CSS Framework

One thing that I would still like to highlight though is the main content vs the head of the webpage. After browsing through the patterns at https://docs.vanillaframework.io/en/ for a bit I decided that I am only going to need the `p-card` pattern to achieve this.

After including this with @import "vanilla-framework/scss/patterns_card"; and using the needed mixins for the default card, the highlighted one and the content inside the card with

@include vf-p-card-default;
@include vf-p-card-highlighted;
@include vf-p-card-specific-content;

I just had to add classes to my articles on the index page and the content on the post page to achieve the following:

One thing that still bothers me here is the focus of the content on the left side. So I went ahead and adjusted some of the margins to the sides and on the header.

An additional thing I added (or actually removed) afterwards is the Font. If you set the $font-base-family variable before including the Vanilla base mixin, it will replace the default Ubuntu Font. As my goal is a very data saving, content focused website, I have replace it with serif, sans-serif. This will use the Fonts that are installed on the system in that order.

So, if for any reason, there is no Font found that has [serifs](https://en.wikipedia.org/wiki/Serif), a Font without serifs will be used instead.

Resümee

In a few hours I was able to reach a design that is both clear and allows the user to focus on the content, which is written text. The Vanilla Framework, and the way it is set up, made it possible for me to focus on the things that are important to me and disregard the rest.

This way I can leverage all the design decisions around readability etc. that the Vanilla team has put into the framework and still have a bloat-free, brutalisitc website design to my liking, that represents me on the Internet.

This is a great speed improvement and asset for someone like me who appreciates great design, but spends a lot of time in the backend.

Read more
Max

Impulse

Bug hunting on iOS 6.3.1

Me and my SO recently got an old iPad2, which we were planning to use for everyday usage around the house. Meaning, having it ready to research a recipe, get information about a topic or researching things to do together.

Unfortunately though, the iOS version that it came preinstalled with was 9.3.5. On this later version of iOS there is quite a problem with the responsiveness though.
Probably due to the big alterations on the design side the iPad feels slow and has noticeable lags when switching between applications, and even when using the web browser. The argument for this was, that it never seemed that slow before, and it should not be the hardware that wore down.
So I decided to try and downgrade the iPad and compare a much older version, namely 6.3.1, to the 9.3.5 that was installed.

After doing so successfully via ITunes and an old [IPSW](https://en.wikipedia.org/wiki/IPSW) file it was clear that the assumption was correct. Being back on the old version improved the performance significantly.
This only goes as far as the web though. When visiting certain websites errors started bringing the user satisfaction back down again.

Here are a a few screenshots of some broken styling:

And some websites were still a pleasure to use, here are the BBC and RA as examples:

Reflection

This made me think to go onto my own blog and start breaking it.
Given all the modern tech that I use for this theme, I would not be surprised to find some thing not working correctly. Mostly due to the CSS Grid specification I am using for the styling.

And indeed it did not take long:
First of all the header is broken, with the navigation links appearing in a horizontal manner, instead of a vertical one.
Additionally after some scrolling the header starts covering most of the content.

Bug hunting on iOS 6.3.1
Broken Header
Bug hunting on iOS 6.3.1
Header covering content

My speculation for the first bug being the CSS Grid, while the latter one could be related to the vh and vw units I am using.

Action

Since I am now in possession of a great testing device I set out to fix this.
Setting up my development environment by changing the the address of my development server to 0.0.0.0:8000, thus exposing it my local network, and accessing it on my iPad via IP.OF.MY.LAPTOP:8000, I have a quick feedback loop to test out my ideas and refactorings.

After looking at the stylings for the header the position: fixed; top: 0; turned out to be the problem.
Since this was a problem that was not solved elegantly initially I decided to throw it out completely and instead reiterate on the website design.

Since design in general is an iterative process I will take this as a major stepping stone in finding the right one for my blog.
For now the user (so you) will have to scroll back up to the top of the page in order to navigate. Given all the advanced technology that is on this site though, and its relative simplicity I will start from scratch for the layouting. This time using old methods and then adding modern techniques on top via cascading rules.

Resume

This rather random chain on events has again taught me, and hopefully some of you that are reading this, a lesson. While I always speak up for accessibility and its importantance in our work, I wanted to write the theme for this blog, using all the latest technologies, making my developer life comfortable and the code elegant.
This hypocrisy was made obvious right now, and I will have to backtrack and rework some parts. It also comes to show that some problems stem from architectural decisions rather than a specific bug. My assumptions about what could be breaking were not too far off, but as it turns out the problem has more depth.
While the CSS is easy to refactor and well decoupled, this could have become a nightmare if the project was bigger, since I have already accumulated tech-debt and would just keep on growing it.
But as always, a mistake made now is a mistake avoided in the future.

Cover photo by Tim Goedhart on Unsplash

Read more
Max

Impulse

Bug hunting on iOS 6.3.1

Me and my SO recently got an old iPad2, which we were planning to use for everyday usage around the house. Meaning, having it ready to research a recipe, get information about a topic or researching things to do together.

Unfortunately though, the iOS version that it came preinstalled with was 9.3.5. On this later version of iOS there is quite a problem with the responsiveness though.
Probably due to the big alterations on the design side the iPad feels slow and has noticeable lags when switching between applications, and even when using the web browser. The argument for this was, that it never seemed that slow before, and it should not be the hardware that wore down.
So I decided to try and downgrade the iPad and compare a much older version, namely 6.3.1, to the 9.3.5 that was installed.

After doing so successfully via ITunes and an old [IPSW](https://en.wikipedia.org/wiki/IPSW) file it was clear that the assumption was correct. Being back on the old version improved the performance significantly.
This only goes as far as the web though. When visiting certain websites errors started bringing the user satisfaction back down again.

Here are a a few screenshots of some broken styling:

And some websites were still a pleasure to use, here are the BBC and RA as examples:

Reflection

This made me think to go onto my own blog and start breaking it.
Given all the modern tech that I use for this theme, I would not be surprised to find some thing not working correctly. Mostly due to the CSS Grid specification I am using for the styling.

And indeed it did not take long:
First of all the header is broken, with the navigation links appearing in a horizontal manner, instead of a vertical one.
Additionally after some scrolling the header starts covering most of the content.

Bug hunting on iOS 6.3.1
Broken Header
Bug hunting on iOS 6.3.1
Header covering content

My speculation for the first bug being the CSS Grid, while the latter one could be related to the vh and vw units I am using.

Action

Since I am now in possession of a great testing device I set out to fix this.
Setting up my development environment by changing the the address of my development server to 0.0.0.0:8000, thus exposing it my local network, and accessing it on my iPad via IP.OF.MY.LAPTOP:8000, I have a quick feedback loop to test out my ideas and refactorings.

After looking at the stylings for the header the position: fixed; top: 0; turned out to be the problem.
Since this was a problem that was not solved elegantly initially I decided to throw it out completely and instead reiterate on the website design.

Since design in general is an iterative process I will take this as a major stepping stone in finding the right one for my blog.
For now the user (so you) will have to scroll back up to the top of the page in order to navigate. Given all the advanced technology that is on this site though, and its relative simplicity I will start from scratch for the layouting. This time using old methods and then adding modern techniques on top via cascading rules.

Resume

This rather random chain on events has again taught me, and hopefully some of you that are reading this, a lesson. While I always speak up for accessibility and its importantance in our work, I wanted to write the theme for this blog, using all the latest technologies, making my developer life comfortable and the code elegant.
This hypocrisy was made obvious right now, and I will have to backtrack and rework some parts. It also comes to show that some problems stem from architectural decisions rather than a specific bug. My assumptions about what could be breaking were not too far off, but as it turns out the problem has more depth.
While the CSS is easy to refactor and well decoupled, this could have become a nightmare if the project was bigger, since I have already accumulated tech-debt and would just keep on growing it.
But as always, a mistake made now is a mistake avoided in the future.

Cover photo by Tim Goedhart on Unsplash

Read more
Max

Impulse

Bug hunting on iOS 6.3.1

Me and my SO recently got an old iPad2, which we were planning to use for everyday usage around the house. Meaning, having it ready to research a recipe, get information about a topic or researching things to do together.

Unfortunately though, the iOS version that it came preinstalled with was 9.3.5. On this later version of iOS there is quite a problem with the responsiveness though.
Probably due to the big alterations on the design side the iPad feels slow and has noticeable lags when switching between applications, and even when using the web browser. The argument for this was, that it never seemed that slow before, and it should not be the hardware that wore down.
So I decided to try and downgrade the iPad and compare a much older version, namely 6.3.1, to the 9.3.5 that was installed.

After doing so successfully via ITunes and an old [IPSW](https://en.wikipedia.org/wiki/IPSW) file it was clear that the assumption was correct. Being back on the old version improved the performance significantly.
This only goes as far as the web though. When visiting certain websites errors started bringing the user satisfaction back down again.

Here are a a few screenshots of some broken styling:

And some websites were still a pleasure to use, here are the BBC and RA as examples:

Reflection

This made me think to go onto my own blog and start breaking it.
Given all the modern tech that I use for this theme, I would not be surprised to find some thing not working correctly. Mostly due to the CSS Grid specification I am using for the styling.

And indeed it did not take long:
First of all the header is broken, with the navigation links appearing in a horizontal manner, instead of a vertical one.
Additionally after some scrolling the header starts covering most of the content.

Bug hunting on iOS 6.3.1
Broken Header
Bug hunting on iOS 6.3.1
Header covering content

My speculation for the first bug being the CSS Grid, while the latter one could be related to the vh and vw units I am using.

Action

Since I am now in possession of a great testing device I set out to fix this.
Setting up my development environment by changing the the address of my development server to 0.0.0.0:8000, thus exposing it my local network, and accessing it on my iPad via IP.OF.MY.LAPTOP:8000, I have a quick feedback loop to test out my ideas and refactorings.

After looking at the stylings for the header the position: fixed; top: 0; turned out to be the problem.
Since this was a problem that was not solved elegantly initially I decided to throw it out completely and instead reiterate on the website design.

Since design in general is an iterative process I will take this as a major stepping stone in finding the right one for my blog.
For now the user (so you) will have to scroll back up to the top of the page in order to navigate. Given all the advanced technology that is on this site though, and its relative simplicity I will start from scratch for the layouting. This time using old methods and then adding modern techniques on top via cascading rules.

Resume

This rather random chain on events has again taught me, and hopefully some of you that are reading this, a lesson. While I always speak up for accessibility and its importantance in our work, I wanted to write the theme for this blog, using all the latest technologies, making my developer life comfortable and the code elegant.
This hypocrisy was made obvious right now, and I will have to backtrack and rework some parts. It also comes to show that some problems stem from architectural decisions rather than a specific bug. My assumptions about what could be breaking were not too far off, but as it turns out the problem has more depth.
While the CSS is easy to refactor and well decoupled, this could have become a nightmare if the project was bigger, since I have already accumulated tech-debt and would just keep on growing it.
But as always, a mistake made now is a mistake avoided in the future.

Cover photo by Tim Goedhart on Unsplash

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Ghost theme - Part 4: Finishing the Sidebar

On mobile Layouts < 360px width the Sidebar still overflows vertically. Lets fix it and implement the features decided on in Part 3.

First a small screenshot of the problem:

Ghost theme - Part 4: Finishing the Sidebar

As you can see the Sidebar flows into the other content.
To fix this lets remove some margins and change the nav to list its items horizontally.

All done with this bit of CSS in the styles.css file since we are changing the default layout.

.sidebar {
  grid-area: Sidebar;
  display: flex;
  flex-wrap: wrap;
  max-height: var(--sidebar-height);

  & .page-title {
      margin: 0px;
  }

  & .page-description {
      margin: 0px;
  }

  & .navigation {
    & .nav {
      display: flex;
      list-style: none;
      padding: 0px;
      margin: 0px;
    }
  }
}
@media screen and (min-width: 961px) {
    .sidebar {
        position: relative;
    }
}

This has actually become quite a lot to keep in the styles.css file.
Lets extract it into components/sidebar.css and import it.

All should look good now. Except when the content doesnt wrap!
Here is a screenshot of what I mean:

Ghost theme - Part 4: Finishing the Sidebar

Everything is in a row. The fix is quite easy with flexbox. Lets just set the flex-direction to column. That should fix it. Right?

Almost. The flex-wrap: wrap from earlier now messes things up. So lets just get rid of it on the sidebar. It worked great when the direction was row but now it is wrapping at the vertical ends, which is not what we want.

Now the sidebar looks pretty nice and our layout is almost done!

The features

Lets go on to the features:

  1. when scrolling the Title disappears
  2. when scrolling the Description disappears
  3. Only the Navigation is shown and the sidebar should shrink to its size but stay at the top

With position: sticky; the last one is pretty easy to do these days.
But to hide the other two we would need to restructure the HTML of our Sidebar since the position is relative to its parent. Which means it would still go out of the screen together with it.

So the last resort here is JavaScript together with position: fixed;. In general we should not use JavaScript for styling, but for this weird case lets make an exception and add a new class to the sidebar when it scrolls out of view.
Using that class we can then use the correct styles to achieve our goal and maybe add some nice CSS Animation.

Lets code

To use JavaScript create the file assets/js/helpers/styling.js.
The gotede build tools will take care of doing all the hard work of getting it onto the page, such as using babel and concatenating the JavaScript files you create.
Just take note that imports wont work. Since this is a Theme for purely Server-side rendered pages, that is totally fine. The JavaScript should be kept to a minimum here.

It should contain the following code, which will attach a new class to the Sidebar when we scroll down and then remove this class again once we scroll to the top:

function initScrollingListener() {
  const sidebar = document.getElementsByClassName("sidebar")[0];

  function addScrollClass() {
    if (window.pageYOffset >= 0) {
      sidebar.classList.add("scrolled");
      window.removeEventListener("scroll", addScrollClass);
      window.addEventListener("scroll", removeScrollClass);
    }
  }

  function removeScrollClass() {
    if (window.pageYOffset == 0) {
      sidebar.classList.remove("scrolled");
      window.removeEventListener("scroll", removeScrollClass);
      window.addEventListener("scroll", addScrollClass);
    }
  }

  if (window.pageYOffset == 0) {
    window.addEventListener("scroll", addScrollClass);
  } else {
    addScrollClass();
  }
}

initScrollingListener();

You should have some basic understanding of programming to really understand what is happening here but here is a small breakdown:

1.  If pageYOffset is 0 we are at the top, so we add a Listener that will call our addScrollClass function once we scroll. Otherwise we are not at the top and can call that function directly.
2. addScrollClass adds the class to the Sidebar element when we are not at the top of the page and the removes the Listener for calling itself on scrolling. Then it adds the Listener that calls removeScrollClass when we scroll.
3. removeScrollClass does exactly the opposite of addScrollClass.

Here is a list of all the DOM functionalities that are used in this piece of code: window, document, getElementsByClassName, window.pageYOffset, Element.classList, addEventListener, removeEventListener

Maybe you notice that we will call one of these functions every time that we scroll. In this case it is a very small amount of code, but it still has to run on the CPU, which is why we should generally avoid these kind of hacks.

Using the new class

So lets go and implement the things that should happen when we scroll in CSS.

.sidebar {
    /* ... */
    position: fixed;
    /* ... */
    &.scrolled{
        height: calc(var(--sidebar-height) / 1.5);
        width: var(--sidebar-width);

        & .page-title {
           display: none; 
        }

        & .page-description {
           display: none; 
        }
      }

This is all we need for now.
It should be inside the .sidebar block and hides both the description and the title when the scrolled class is added.

While it is not an optimal solution, since we use JavaScript for styling, it works in this case and does not put much load on the CPU since we only add two Listeners to our Window.

An Animation

To add some spiciness to our Sidebar suddenly reducing in size, we can add a small Animation when this happens.
Lets just make a dummy one for now where the Background transitions through colors. We can fine-tune this later when we got to the real colors of the theme.

  &.scrolled {
    /*...*/
    animation: background-transition 3s;
    background-color: yellow;
    z-index: 1;
  }
  /*...*/
  
  @keyframes background-transition {
    0% {
        background-color: blue;
    }
    100% {
        background-color: yellow;
    }
  }

One more thing is left to do.
While we have a nice Sidebar for a mobile layout these rules will break the Desktop design. Since we would have to overwrite all these rules in a MediaQuery lets make it easy on us and instead wrap these inside one themselves to keep the default on the other layouts.
To do this put all the CSS we just created for the scrolled class inside @media screen and (max-width: 960px) and dont forget to wrap them inside the .sidebar class as well.

The final sidebar.css should look like this:

.sidebar {
  grid-area: Sidebar;
  display: flex;
  flex-direction: column;
  max-height: var(--sidebar-height);

  position: fixed;
  top: 0;

  & .page-title {
      margin: 0px;
  }

  & .page-description {
      margin: 0px;
  }

  & .navigation {
    & .nav {
      display: flex;
      list-style: none;
      padding: 0px;
      margin: 0px;
    }
  }
}

@media screen and (max-width: 960px) {
    .sidebar {
        &.scrolled {
            height: calc(var(--sidebar-height) / 1.5);
            width: var(--sidebar-width);
            animation: background-transition 3s;
            background-color: yellow;
            z-index: 1;

        & .page-title {
            display: none; 
        }

        & .page-description {
            display: none; 
        }
        }
    }
}

@media screen and (min-width: 961px) {
    .sidebar {
        position: relative;
    }
}

@keyframes background-transition {
    0% {
        background-color: blue;
    }
    100% {
        background-color: yellow;
    }
}

The end

Here is a GIF of the new behaviour:

Ghost theme - Part 4: Finishing the Sidebar

Caught that Image that overflows our page? A Bug, how nice. I will fix it by next time. If you somehow followed along and want to do this as well, check out the class of such and element and try to find a setting that restricts its width ;)

Otherwise it looks like we are done here from a Basic Layouting point of view.
Of course there is still much needed on the visual front, which is what we will start in Part 6, where it is going to be all about Typography and choosing a Font.

Cover: https://unsplash.com/photos/SXihyA4oEJs

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Ghost theme - Part 4: Finishing the Sidebar

On mobile Layouts < 360px width the Sidebar still overflows vertically. Lets fix it and implement the features decided on in Part 3.

First a small screenshot of the problem:

Ghost theme - Part 4: Finishing the Sidebar

As you can see the Sidebar flows into the other content.
To fix this lets remove some margins and change the nav to list its items horizontally.

All done with this bit of CSS in the styles.css file since we are changing the default layout.

.sidebar {
  grid-area: Sidebar;
  display: flex;
  flex-wrap: wrap;
  max-height: var(--sidebar-height);

  & .page-title {
      margin: 0px;
  }

  & .page-description {
      margin: 0px;
  }

  & .navigation {
    & .nav {
      display: flex;
      list-style: none;
      padding: 0px;
      margin: 0px;
    }
  }
}
@media screen and (min-width: 961px) {
    .sidebar {
        position: relative;
    }
}

This has actually become quite a lot to keep in the styles.css file.
Lets extract it into components/sidebar.css and import it.

All should look good now. Except when the content doesnt wrap!
Here is a screenshot of what I mean:

Ghost theme - Part 4: Finishing the Sidebar

Everything is in a row. The fix is quite easy with flexbox. Lets just set the flex-direction to column. That should fix it. Right?

Almost. The flex-wrap: wrap from earlier now messes things up. So lets just get rid of it on the sidebar. It worked great when the direction was row but now it is wrapping at the vertical ends, which is not what we want.

Now the sidebar looks pretty nice and our layout is almost done!

The features

Lets go on to the features:

  1. when scrolling the Title disappears
  2. when scrolling the Description disappears
  3. Only the Navigation is shown and the sidebar should shrink to its size but stay at the top

With position: sticky; the last one is pretty easy to do these days.
But to hide the other two we would need to restructure the HTML of our Sidebar since the position is relative to its parent. Which means it would still go out of the screen together with it.

So the last resort here is JavaScript together with position: fixed;. In general we should not use JavaScript for styling, but for this weird case lets make an exception and add a new class to the sidebar when it scrolls out of view.
Using that class we can then use the correct styles to achieve our goal and maybe add some nice CSS Animation.

Lets code

To use JavaScript create the file assets/js/helpers/styling.js.
The gotede build tools will take care of doing all the hard work of getting it onto the page, such as using babel and concatenating the JavaScript files you create.
Just take note that imports wont work. Since this is a Theme for purely Server-side rendered pages, that is totally fine. The JavaScript should be kept to a minimum here.

It should contain the following code, which will attach a new class to the Sidebar when we scroll down and then remove this class again once we scroll to the top:

function initScrollingListener() {
  const sidebar = document.getElementsByClassName("sidebar")[0];

  function addScrollClass() {
    if (window.pageYOffset >= 0) {
      sidebar.classList.add("scrolled");
      window.removeEventListener("scroll", addScrollClass);
      window.addEventListener("scroll", removeScrollClass);
    }
  }

  function removeScrollClass() {
    if (window.pageYOffset == 0) {
      sidebar.classList.remove("scrolled");
      window.removeEventListener("scroll", removeScrollClass);
      window.addEventListener("scroll", addScrollClass);
    }
  }

  if (window.pageYOffset == 0) {
    window.addEventListener("scroll", addScrollClass);
  } else {
    addScrollClass();
  }
}

initScrollingListener();

You should have some basic understanding of programming to really understand what is happening here but here is a small breakdown:

1.  If pageYOffset is 0 we are at the top, so we add a Listener that will call our addScrollClass function once we scroll. Otherwise we are not at the top and can call that function directly.
2. addScrollClass adds the class to the Sidebar element when we are not at the top of the page and the removes the Listener for calling itself on scrolling. Then it adds the Listener that calls removeScrollClass when we scroll.
3. removeScrollClass does exactly the opposite of addScrollClass.

Here is a list of all the DOM functionalities that are used in this piece of code: window, document, getElementsByClassName, window.pageYOffset, Element.classList, addEventListener, removeEventListener

Maybe you notice that we will call one of these functions every time that we scroll. In this case it is a very small amount of code, but it still has to run on the CPU, which is why we should generally avoid these kind of hacks.

Using the new class

So lets go and implement the things that should happen when we scroll in CSS.

.sidebar {
    /* ... */
    position: fixed;
    /* ... */
    &.scrolled{
        height: calc(var(--sidebar-height) / 1.5);
        width: var(--sidebar-width);

        & .page-title {
           display: none; 
        }

        & .page-description {
           display: none; 
        }
      }

This is all we need for now.
It should be inside the .sidebar block and hides both the description and the title when the scrolled class is added.

While it is not an optimal solution, since we use JavaScript for styling, it works in this case and does not put much load on the CPU since we only add two Listeners to our Window.

An Animation

To add some spiciness to our Sidebar suddenly reducing in size, we can add a small Animation when this happens.
Lets just make a dummy one for now where the Background transitions through colors. We can fine-tune this later when we got to the real colors of the theme.

  &.scrolled {
    /*...*/
    animation: background-transition 3s;
    background-color: yellow;
    z-index: 1;
  }
  /*...*/
  
  @keyframes background-transition {
    0% {
        background-color: blue;
    }
    100% {
        background-color: yellow;
    }
  }

One more thing is left to do.
While we have a nice Sidebar for a mobile layout these rules will break the Desktop design. Since we would have to overwrite all these rules in a MediaQuery lets make it easy on us and instead wrap these inside one themselves to keep the default on the other layouts.
To do this put all the CSS we just created for the scrolled class inside @media screen and (max-width: 960px) and dont forget to wrap them inside the .sidebar class as well.

The final sidebar.css should look like this:

.sidebar {
  grid-area: Sidebar;
  display: flex;
  flex-direction: column;
  max-height: var(--sidebar-height);

  position: fixed;
  top: 0;

  & .page-title {
      margin: 0px;
  }

  & .page-description {
      margin: 0px;
  }

  & .navigation {
    & .nav {
      display: flex;
      list-style: none;
      padding: 0px;
      margin: 0px;
    }
  }
}

@media screen and (max-width: 960px) {
    .sidebar {
        &.scrolled {
            height: calc(var(--sidebar-height) / 1.5);
            width: var(--sidebar-width);
            animation: background-transition 3s;
            background-color: yellow;
            z-index: 1;

        & .page-title {
            display: none; 
        }

        & .page-description {
            display: none; 
        }
        }
    }
}

@media screen and (min-width: 961px) {
    .sidebar {
        position: relative;
    }
}

@keyframes background-transition {
    0% {
        background-color: blue;
    }
    100% {
        background-color: yellow;
    }
}

The end

Here is a GIF of the new behaviour:

Ghost theme - Part 4: Finishing the Sidebar

Caught that Image that overflows our page? A Bug, how nice. I will fix it by next time. If you somehow followed along and want to do this as well, check out the class of such and element and try to find a setting that restricts its width ;)

Otherwise it looks like we are done here from a Basic Layouting point of view.
Of course there is still much needed on the visual front, which is what we will start in Part 6, where it is going to be all about Typography and choosing a Font.

Cover: https://unsplash.com/photos/SXihyA4oEJs

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Ghost theme - Part 4: Finishing the Sidebar

On mobile Layouts < 360px width the Sidebar still overflows vertically. Lets fix it and implement the features decided on in Part 3.

First a small screenshot of the problem:

Ghost theme - Part 4: Finishing the Sidebar

As you can see the Sidebar flows into the other content.
To fix this lets remove some margins and change the nav to list its items horizontally.

All done with this bit of CSS in the styles.css file since we are changing the default layout.

.sidebar {
  grid-area: Sidebar;
  display: flex;
  flex-wrap: wrap;
  max-height: var(--sidebar-height);

  & .page-title {
      margin: 0px;
  }

  & .page-description {
      margin: 0px;
  }

  & .navigation {
    & .nav {
      display: flex;
      list-style: none;
      padding: 0px;
      margin: 0px;
    }
  }
}
@media screen and (min-width: 961px) {
    .sidebar {
        position: relative;
    }
}

This has actually become quite a lot to keep in the styles.css file.
Lets extract it into components/sidebar.css and import it.

All should look good now. Except when the content doesnt wrap!
Here is a screenshot of what I mean:

Ghost theme - Part 4: Finishing the Sidebar

Everything is in a row. The fix is quite easy with flexbox. Lets just set the flex-direction to column. That should fix it. Right?

Almost. The flex-wrap: wrap from earlier now messes things up. So lets just get rid of it on the sidebar. It worked great when the direction was row but now it is wrapping at the vertical ends, which is not what we want.

Now the sidebar looks pretty nice and our layout is almost done!

The features

Lets go on to the features:

  1. when scrolling the Title disappears
  2. when scrolling the Description disappears
  3. Only the Navigation is shown and the sidebar should shrink to its size but stay at the top

With position: sticky; the last one is pretty easy to do these days.
But to hide the other two we would need to restructure the HTML of our Sidebar since the position is relative to its parent. Which means it would still go out of the screen together with it.

So the last resort here is JavaScript together with position: fixed;. In general we should not use JavaScript for styling, but for this weird case lets make an exception and add a new class to the sidebar when it scrolls out of view.
Using that class we can then use the correct styles to achieve our goal and maybe add some nice CSS Animation.

Lets code

To use JavaScript create the file assets/js/helpers/styling.js.
The gotede build tools will take care of doing all the hard work of getting it onto the page, such as using babel and concatenating the JavaScript files you create.
Just take note that imports wont work. Since this is a Theme for purely Server-side rendered pages, that is totally fine. The JavaScript should be kept to a minimum here.

It should contain the following code, which will attach a new class to the Sidebar when we scroll down and then remove this class again once we scroll to the top:

function initScrollingListener() {
  const sidebar = document.getElementsByClassName("sidebar")[0];

  function addScrollClass() {
    if (window.pageYOffset >= 0) {
      sidebar.classList.add("scrolled");
      window.removeEventListener("scroll", addScrollClass);
      window.addEventListener("scroll", removeScrollClass);
    }
  }

  function removeScrollClass() {
    if (window.pageYOffset == 0) {
      sidebar.classList.remove("scrolled");
      window.removeEventListener("scroll", removeScrollClass);
      window.addEventListener("scroll", addScrollClass);
    }
  }

  if (window.pageYOffset == 0) {
    window.addEventListener("scroll", addScrollClass);
  } else {
    addScrollClass();
  }
}

initScrollingListener();

You should have some basic understanding of programming to really understand what is happening here but here is a small breakdown:

1.  If pageYOffset is 0 we are at the top, so we add a Listener that will call our addScrollClass function once we scroll. Otherwise we are not at the top and can call that function directly.
2. addScrollClass adds the class to the Sidebar element when we are not at the top of the page and the removes the Listener for calling itself on scrolling. Then it adds the Listener that calls removeScrollClass when we scroll.
3. removeScrollClass does exactly the opposite of addScrollClass.

Here is a list of all the DOM functionalities that are used in this piece of code: window, document, getElementsByClassName, window.pageYOffset, Element.classList, addEventListener, removeEventListener

Maybe you notice that we will call one of these functions every time that we scroll. In this case it is a very small amount of code, but it still has to run on the CPU, which is why we should generally avoid these kind of hacks.

Using the new class

So lets go and implement the things that should happen when we scroll in CSS.

.sidebar {
    /* ... */
    position: fixed;
    /* ... */
    &.scrolled{
        height: calc(var(--sidebar-height) / 1.5);
        width: var(--sidebar-width);

        & .page-title {
           display: none; 
        }

        & .page-description {
           display: none; 
        }
      }

This is all we need for now.
It should be inside the .sidebar block and hides both the description and the title when the scrolled class is added.

While it is not an optimal solution, since we use JavaScript for styling, it works in this case and does not put much load on the CPU since we only add two Listeners to our Window.

An Animation

To add some spiciness to our Sidebar suddenly reducing in size, we can add a small Animation when this happens.
Lets just make a dummy one for now where the Background transitions through colors. We can fine-tune this later when we got to the real colors of the theme.

  &.scrolled {
    /*...*/
    animation: background-transition 3s;
    background-color: yellow;
    z-index: 1;
  }
  /*...*/
  
  @keyframes background-transition {
    0% {
        background-color: blue;
    }
    100% {
        background-color: yellow;
    }
  }

One more thing is left to do.
While we have a nice Sidebar for a mobile layout these rules will break the Desktop design. Since we would have to overwrite all these rules in a MediaQuery lets make it easy on us and instead wrap these inside one themselves to keep the default on the other layouts.
To do this put all the CSS we just created for the scrolled class inside @media screen and (max-width: 960px) and dont forget to wrap them inside the .sidebar class as well.

The final sidebar.css should look like this:

.sidebar {
  grid-area: Sidebar;
  display: flex;
  flex-direction: column;
  max-height: var(--sidebar-height);

  position: fixed;
  top: 0;

  & .page-title {
      margin: 0px;
  }

  & .page-description {
      margin: 0px;
  }

  & .navigation {
    & .nav {
      display: flex;
      list-style: none;
      padding: 0px;
      margin: 0px;
    }
  }
}

@media screen and (max-width: 960px) {
    .sidebar {
        &.scrolled {
            height: calc(var(--sidebar-height) / 1.5);
            width: var(--sidebar-width);
            animation: background-transition 3s;
            background-color: yellow;
            z-index: 1;

        & .page-title {
            display: none; 
        }

        & .page-description {
            display: none; 
        }
        }
    }
}

@media screen and (min-width: 961px) {
    .sidebar {
        position: relative;
    }
}

@keyframes background-transition {
    0% {
        background-color: blue;
    }
    100% {
        background-color: yellow;
    }
}

The end

Here is a GIF of the new behaviour:

Ghost theme - Part 4: Finishing the Sidebar

Caught that Image that overflows our page? A Bug, how nice. I will fix it by next time. If you somehow followed along and want to do this as well, check out the class of such and element and try to find a setting that restricts its width ;)

Otherwise it looks like we are done here from a Basic Layouting point of view.
Of course there is still much needed on the visual front, which is what we will start in Part 6, where it is going to be all about Typography and choosing a Font.

Cover: https://unsplash.com/photos/SXihyA4oEJs

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Ghost theme - Part 3: Mobile Layout

Here is the third part of this series where we will dive into creating the proper layout for the posts on the front page and figure out a way to display our layout on mobilephones.

Just in case lets bring up the inital sketch again

Ghost theme - Part 3: Mobile Layout

But before we can jump in and take care of the posts we have a small problem.
Using the mobile page preview of the browser we can easily spot it.

Ghost theme - Part 3: Mobile Layout

The content inside the sidebar does not fit inside the container anymore. Unfortunately max-width does not help here, as the words are actually too long and the browser cant wrap the text to the next line.

So its time to come up with a new sketch:

Ghost theme - Part 3: Mobile Layout

You have probably encountered this technique before. Here is a break down:

  1. We will make the sidebar go to the top on mobile devices.
  2. The Title and subtitle will scroll out of the screen
  3. The navigation elements will stay on top

Implementation

Responsiveness

The first thing I am going to do is to convert the whole layout to this idea.
This 'old' design will be wrapped via media-queries that activate when a certain screen-size is reached.
This way of doing it is called mobile first.
Since this theme is in an early stage of development it is still easily possible to switch to this approach.

This is the updated CSS:

variables.css

:root {
  /* Container sizes */
  --main-width: 100vw;
  --main-height: 80vh;

  --sidebar-width: 100vw;
  --sidebar-height: 20vh;
}

@media screen and (min-width: 961px) {
  :root {
    /* Container sizes */
    --main-width: 80vw;
    --main-height: 100%;

    --sidebar-width: 20vw;
    --sidebar-height: 100vh;
  }
}

styles.css

@import "./helpers/variables.css";

/* Mobile */
body {
  margin: 0px;
}

.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: 1fr;
  grid-template-rows: var(--sidebar-height) var(--main-height);
  grid-gap: 0px;
  grid-template-areas: "Sidebar" "Content";
}

.main {
  grid-area: Content;
  max-width: var(--main-width);
}

.sidebar {
  grid-area: Sidebar;
}


/* Desktop */
@media screen and (min-width: 961px) {
  .grid-container {
    display: grid;
    height: 100%;
    grid-template-columns: var(--sidebar-width) var(--main-width);
    grid-template-rows: 1fr;
    grid-gap: 0px;
    grid-template-areas: "Sidebar Content";
  }
  .main {
    grid-area: Content;
    max-width: var(--main-width);
  }
}

Et voila, we have a responsive page.

Mobile:
Ghost theme - Part 3: Mobile Layout

Desktop:
Ghost theme - Part 3: Mobile Layout

The Sidebar

As you can see the content of the Sidebar seems to escape into regions it shouldnt.

To fix this lets first change the default.hbs and remove the <div class="sidebar> and attach that class directly to the <header>.

Back in the styles.css we can now add some rules.
I am going to go for a flexbox solution.

 .sidebar {
  grid-area: Sidebar;
  display: flex;
  flex-wrap: wrap;
  max-height: var(--sidebar-height);
}
  1. Tell the component that its display type is flexbox.
  2. Make sure that the content will wrap when it reaches the bounds of this container
  3. Set a maximum height on the sidebar. To make sure it doesnt grow beyond what we would like to have in our design. This is espacially useful when the sidebar is actually at the side.

Lets leave the additional requirements of hiding the title and subtitle for the next post.

The posts

Lastly its time to implement the post layout.
On the mobile front everything looks good already. One post per row.

For the desktop we need to find a way to display 2 posts next to each other though.

First I will create a new file components/index.css that will hold all the styles for the Index page. All the styling until now was for the default.hbs.
Also do not forget to import this file in the styles.css via @import "./components/index.css";.

Here is the CSS that will accomplish the task:

.index__posts {
  display: flex;
  flex-wrap: wrap;

  & .post {
    width: var(--post-width);
  }
}

You can see that the .post class is nested inside the .index__posts class. This again is taken care of during the build step via postcss-preset-env.

The --post-width variable is inside the variables.css file and looks like this:

/* .... */
:root {
  --post-width: var(--main-width);
}

@media screen and (min-width: 961px) {
  :root {
    /* .... */
    --post-width: calc(var(--main-width) / 2);
  }

This works in the following way:

  1. When the Screen is 961px wide or bigger every post will have the width of half the --main-width.
  2. Posts are inside a flexbox container
  3. Since the flexbox container does not wrap by default and instead rezises our posts to fit inside of it, we tell it to wrap the content.
  4. 2 posts will be shown per 'row' :)

The one thing I have not mentioned until now is the CSS calc function, which allows us to dynamically calculate some values.

Wrap up

Phew, this post had quite a lot of content and advanced techniques. Nevertheless the theme is now in a good state with relatively little CSS and should be pretty maintainable and extendable.

The neat little trick with the custom-properties is something that I have added to postcss-custom-properties while writing this, so it might not yet be released. I will update this post once it is.

Here is a final image of the Desktop page, looks pretty good already :

Ghost theme - Part 3: Mobile Layout

Next post

Whats going to happen in part 4?
Lets fix the Sidebar for mobile layouts. Afterwards in part 5 the Basics should be done to start with Typography and Colours :)

Cover: https://unsplash.com/photos/-1_RZL8BGBM

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Here is the third part of this series where we will dive into creating the proper layout for the posts on the front page and figure out a way to display our layout on mobilephones.

Just in case lets bring up the inital sketch again

Sketch_theme-2

But before we can jump in and take care of the posts we have a small problem.
Using the mobile page preview of the browser we can easily spot it.

mobile_view_broken

The content inside the sidebar does not fit inside the container anymore. Unfortunately max-width does not help here, as the words are actually too long and the browser cant wrap the text to the next line.

So its time to come up with a new sketch:

mobile_sketch-1

You have probably encountered this technique before. Here is a break down:

  1. We will make the sidebar go to the top on mobile devices.
  2. The Title and subtitle will scroll out of the screen
  3. The navigation elements will stay on top

Implementation

Responsiveness

The first thing I am going to do is to convert the whole layout to this idea.
This 'old' design will be wrapped via media-queries that activate when a certain screen-size is reached.
This way of doing it is called mobile first.
Since this theme is in an early stage of development it is still easily possible to switch to this approach.

This is the updated CSS:

variables.css

:root {
  /* Container sizes */
  --main-width: 100vw;
  --main-height: 80vh;

  --sidebar-width: 100vw;
  --sidebar-height: 20vh;
}

@media screen and (min-width: 961px) {
  :root {
    /* Container sizes */
    --main-width: 80vw;
    --main-height: 100%;

    --sidebar-width: 20vw;
    --sidebar-height: 100vh;
  }
}

styles.css

@import "./helpers/variables.css";

/* Mobile */
body {
  margin: 0px;
}

.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: 1fr;
  grid-template-rows: var(--sidebar-height) var(--main-height);
  grid-gap: 0px;
  grid-template-areas: "Sidebar" "Content";
}

.main {
  grid-area: Content;
  max-width: var(--main-width);
}

.sidebar {
  grid-area: Sidebar;
}


/* Desktop */
@media screen and (min-width: 961px) {
  .grid-container {
    display: grid;
    height: 100%;
    grid-template-columns: var(--sidebar-width) var(--main-width);
    grid-template-rows: 1fr;
    grid-gap: 0px;
    grid-template-areas: "Sidebar Content";
  }
  .main {
    grid-area: Content;
    max-width: var(--main-width);
  }
}

Et voila, we  have a responsive page.

mobile_resp
desktop_resp

The Sidebar

As you can see the content of the Sidebar seems to escape into regions it shouldnt.

To fix this lets first change the default.hbs and remove the <div class="sidebar> and attach that class directly to the <header>.

Back in the styles.css we can now add some rules.
I am going to go for a flexbox solution.

 .sidebar {
  grid-area: Sidebar;
  display: flex;
  flex-wrap: wrap;
  max-height: var(--sidebar-height);
}
  1. Tell the component that its display type is flexbox.
  2. Make sure that the content will wrap when it reaches the bounds of this container
  3. Set a maximum height on the sidebar. To make sure it doesnt grow beyond what we would like to have in our design. This is espacially useful when the sidebar is actually at the side.

Lets leave the additional requirements of hiding the title and subtitle for the next post.

The posts

Lastly its time to implement the post layout.
On the mobile front everything looks good already. One post per row.

For the desktop we need to find a way to display 2 posts next to each other though.

First I will create a new file  components/index.css that will hold all the styles for the Index page. All the styling until now was for the default.hbs.
Also do not forget to import this file in the styles.css via @import "./components/index.css";.

Here is the CSS that will accomplish the task:

.index__posts {
  display: flex;
  flex-wrap: wrap;

  & .post {
    width: var(--post-width);
  }
}

You can see that the .post class is nested inside the .index__posts class. This again is taken care of during the build step via postcss-preset-env.

The --post-width variable is inside the variables.css file and looks like this:

/* .... */
:root {
  --post-width: var(--main-width);
}

@media screen and (min-width: 961px) {
  :root {
    /* .... */
    --post-width: calc(var(--main-width) / 2);
  }

This works in the following way:

  1. When the Screen is 961px wide or bigger every post will have the width of half the --main-width.
  2. Posts are inside a flexbox container
  3. Since the flexbox container does not wrap by default and instead rezises our posts to fit inside of it, we tell it to wrap the content.
  4. 2 posts will be shown per 'row' :)

The one thing I have not mentioned until now is the CSS calc function, which allows us to dynamically calculate some values.

Wrap up

Phew, this post had quite a lot of content and advanced techniques. Nevertheless the theme is now in a good state with relatively little CSS and should be pretty maintainable and extendable.

The neat little trick with the custom-properties is something that I have added to postcss-custom-properties while writing this, so it might not yet be released. I will update this post once it is.

Here is a final image of the Desktop page, looks pretty good already :

desktop_done

Next post

Whats going to happen in part 4?
Lets fix the Sidebar for mobile layouts. Afterwards in part 5 the Basics should be done to start with Typography and Colours :)

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Here is the third part of this series where we will dive into creating the proper layout for the posts on the front page and figure out a way to display our layout on mobilephones.

Just in case lets bring up the inital sketch again

Sketch_theme-2

But before we can jump in and take care of the posts we have a small problem.
Using the mobile page preview of the browser we can easily spot it.

mobile_view_broken

The content inside the sidebar does not fit inside the container anymore. Unfortunately max-width does not help here, as the words are actually too long and the browser cant wrap the text to the next line.

So its time to come up with a new sketch:

mobile_sketch-1

You have probably encountered this technique before. Here is a break down:

  1. We will make the sidebar go to the top on mobile devices.
  2. The Title and subtitle will scroll out of the screen
  3. The navigation elements will stay on top

Implementation

Responsiveness

The first thing I am going to do is to convert the whole layout to this idea.
This 'old' design will be wrapped via media-queries that activate when a certain screen-size is reached.
This way of doing it is called mobile first.
Since this theme is in an early stage of development it is still easily possible to switch to this approach.

This is the updated CSS:

variables.css

:root {
  /* Container sizes */
  --main-width: 100vw;
  --main-height: 80vh;

  --sidebar-width: 100vw;
  --sidebar-height: 20vh;
}

@media screen and (min-width: 961px) {
  :root {
    /* Container sizes */
    --main-width: 80vw;
    --main-height: 100%;

    --sidebar-width: 20vw;
    --sidebar-height: 100vh;
  }
}

styles.css

@import "./helpers/variables.css";

/* Mobile */
body {
  margin: 0px;
}

.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: 1fr;
  grid-template-rows: var(--sidebar-height) var(--main-height);
  grid-gap: 0px;
  grid-template-areas: "Sidebar" "Content";
}

.main {
  grid-area: Content;
  max-width: var(--main-width);
}

.sidebar {
  grid-area: Sidebar;
}


/* Desktop */
@media screen and (min-width: 961px) {
  .grid-container {
    display: grid;
    height: 100%;
    grid-template-columns: var(--sidebar-width) var(--main-width);
    grid-template-rows: 1fr;
    grid-gap: 0px;
    grid-template-areas: "Sidebar Content";
  }
  .main {
    grid-area: Content;
    max-width: var(--main-width);
  }
}

Et voila, we  have a responsive page.

mobile_resp
desktop_resp

The Sidebar

As you can see the content of the Sidebar seems to escape into regions it shouldnt.

To fix this lets first change the default.hbs and remove the <div class="sidebar> and attach that class directly to the <header>.

Back in the styles.css we can now add some rules.
I am going to go for a flexbox solution.

 .sidebar {
  grid-area: Sidebar;
  display: flex;
  flex-wrap: wrap;
  max-height: var(--sidebar-height);
}
  1. Tell the component that its display type is flexbox.
  2. Make sure that the content will wrap when it reaches the bounds of this container
  3. Set a maximum height on the sidebar. To make sure it doesnt grow beyond what we would like to have in our design. This is espacially useful when the sidebar is actually at the side.

Lets leave the additional requirements of hiding the title and subtitle for the next post.

The posts

Lastly its time to implement the post layout.
On the mobile front everything looks good already. One post per row.

For the desktop we need to find a way to display 2 posts next to each other though.

First I will create a new file  components/index.css that will hold all the styles for the Index page. All the styling until now was for the default.hbs.
Also do not forget to import this file in the styles.css via @import "./components/index.css";.

Here is the CSS that will accomplish the task:

.index__posts {
  display: flex;
  flex-wrap: wrap;

  & .post {
    width: var(--post-width);
  }
}

You can see that the .post class is nested inside the .index__posts class. This again is taken care of during the build step via postcss-preset-env.

The --post-width variable is inside the variables.css file and looks like this:

/* .... */
:root {
  --post-width: var(--main-width);
}

@media screen and (min-width: 961px) {
  :root {
    /* .... */
    --post-width: calc(var(--main-width) / 2);
  }

This works in the following way:

  1. When the Screen is 961px wide or bigger every post will have the width of half the --main-width.
  2. Posts are inside a flexbox container
  3. Since the flexbox container does not wrap by default and instead rezises our posts to fit inside of it, we tell it to wrap the content.
  4. 2 posts will be shown per 'row' :)

The one thing I have not mentioned until now is the CSS calc function, which allows us to dynamically calculate some values.

Wrap up

Phew, this post had quite a lot of content and advanced techniques. Nevertheless the theme is now in a good state with relatively little CSS and should be pretty maintainable and extendable.

The neat little trick with the custom-properties is something that I have added to postcss-custom-properties while writing this, so it might not yet be released. I will update this post once it is.

Here is a final image of the Desktop page, looks pretty good already :

desktop_done

Next post

Whats going to happen in part 4?
Lets fix the Sidebar for mobile layouts. Afterwards in part 5 the Basics should be done to start with Typography and Colours :)

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Ghost theme - Part 2: a Grid

In this post I want to start with the styling.
the first thing here is to consult the sketches again.

Ghost theme - Part 2: a Grid

Since we split out the sidebar into the default layout, we should create a Grid for this first.
The technology I am going to use here is CSS-Grid.

The only to be aware of is the browser support. Check caniuse.com to see if it supports the browsers you want.
Since this is my personal blog and the audience is probably using modern browsers (this is an assumption, as I have no tracking yet) I am totally fine with ignoring older and more exotic browsers for now.

Grid

With tools like https://www.layoutit.com/grid we can quickly generate a basic layout.

The generated code for the grid I want on the blog according to the sketches looks like this

.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: 20vw 80vw;
  grid-template-rows: 1fr;
  grid-gap: 0px;
  grid-template-areas: "Sidebar Content";
}

.main{ grid-area: Content; }

.sidebar { grid-area: Sidebar; }

This will have to go into a css file at assets/css/styles.css in the theme folder.

Make sure to restart the `npm run start` task, so that gulp can pick up on the newly created `.css` file. Unfortunately this is not detected automatically.

In the default.hbs this stylesheet now needs to be imported and the correct classes need to be added to the HTML in the like following:


<head>
...
<link rel="stylesheet" type="text/css" href="{{asset "built/styles.css"}}" />

</head>

<body class="{{body_class}} grid-container">
    <div class="sidebar">
        <header>
            <h1 class="page-title">{{@blog.title}}</h1>
            <h2 class="page-description">{{@blog.description}}</h2>
            <nav class="navigation">
                {{navigation}}
            </nav>
        </header>
    </div>
    <div class="main">
        {{{body}}}
    </div>
    {{ghost_foot}}
</body>

The <body> is acting as the Grid container, and the sidebar and main where already equipped with the correct classes.

With this simple addition the page already looks like this:

Ghost theme - Part 2: a Grid

Variables

Now we have a good base to start introducing variables in CSS.
We can use these due to the postcss-custom-properties that are included in the default gotede gulp task.

What this will allow us is to define certain variables that should be applied throughout our app and then reuse them whenever needed.

By doing this we introduce 2 benefits.

  1. We can easily make a change in 1 place that will be applied everywhere that value was used
  2. There is 1 place to check in order to find out what specific values are

The place to define those is f.e. assets/css/helpers/variables.css, so lets create some, that we can use for our grid.

:root {
  /* Container sizes */
  --main-width: 80vw;
  --sidebar-width: 20vw;

  /* Gutter sizes */
  --gutter-horizontal--small: 2vw;
}

Notice that they are wrapped in the :root{} block.

Once this is done the gulp task will automatically make those 'available' in all our CSS files (This is actually done in the build step, but thats semantics I guess).

Lets import them and use them for the grid like this:


@import "./helpers/variables.css";


.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: var(--sidebar-width) var(--main-width);
  grid-template-rows: 1fr;
  grid-gap: 0px;
  grid-template-areas: "Sidebar Content";
}

.main {
  grid-area: Content;
}

.sidebar {
  grid-area: Sidebar;
}

You can see that the variables are used with var(VARIABLE_NAME). While this might not seem super important or useful right now, be sure that this will save a lot of headaches down the line.

A break in the layout

There is a little weirdness going on when we head over to the Writing posts with Ghost for example.
You can see that something is breaking on mobile devices. The content seems to escape the website.
Ghost theme - Part 2: a Grid

To fix this lets set a max-width on the main container. This does exactly what the name implies, telling it that its maximum width should be of some value.
Which one is the correct value? Given our Layout it should be the --main-width variable. Already comming in handy :).

Lets add it to the .main block

.main {
  grid-area: Content;
  max-width: var(--main-width);
}

Check out the post again. All good?
Nope, looks like the picture is still escaping to the right.

If you inspect the HTML you can find the picture class .kg-image. For this class we will add a rule of max-width: 100%; for now, until we encounter the styling of the pictures again, later on.

Now it looks good again:
Ghost theme - Part 2: a Grid

By the way, you can ignore the purple lines.
These are added by the Firefox developer tools. You can read about these here if you would like to use them too.

A small task for you

Check out the Publishing options article. On this page you should encounter another problem of content escaping.
I will leave this as a small task for you to fix right now. Should you need help or a hint feel free to drop me a short email or contact me on my new twitter.

What next?

The theme already looks quite a bit like the sketch. One thing we need to ensure though, is that there are always only 2 posts next to each other (and maybe alter this idea for mobile devices?).

So the next post will be focussing on those 2 topics including media-queries and flexbox.

Cover: https://unsplash.com/photos/Vwf8q3RzBRE

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Ghost theme - Part 2: a Grid

In this post I want to start with the styling.
the first thing here is to consult the sketches again.

Ghost theme - Part 2: a Grid

Since we split out the sidebar into the default layout, we should create a Grid for this first.
The technology I am going to use here is CSS-Grid.

The only to be aware of is the browser support. Check caniuse.com to see if it supports the browsers you want.
Since this is my personal blog and the audience is probably using modern browsers (this is an assumption, as I have no tracking yet) I am totally fine with ignoring older and more exotic browsers for now.

Grid

With tools like https://www.layoutit.com/grid we can quickly generate a basic layout.

The generated code for the grid I want on the blog according to the sketches looks like this

.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: 20vw 80vw;
  grid-template-rows: 1fr;
  grid-gap: 0px;
  grid-template-areas: "Sidebar Content";
}

.main{ grid-area: Content; }

.sidebar { grid-area: Sidebar; }

This will have to go into a css file at assets/css/styles.css in the theme folder.

Make sure to restart the `npm run start` task, so that gulp can pick up on the newly created `.css` file. Unfortunately this is not detected automatically.

In the default.hbs this stylesheet now needs to be imported and the correct classes need to be added to the HTML in the  like following:


<head>
...
<link rel="stylesheet" type="text/css" href="{{asset "built/styles.css"}}" />

</head>

<body class="{{body_class}} grid-container">
    <div class="sidebar">
        <header>
            <h1 class="page-title">{{@blog.title}}</h1>
            <h2 class="page-description">{{@blog.description}}</h2>
            <nav class="navigation">
                {{navigation}}
            </nav>
        </header>
    </div>
    <div class="main">
        {{{body}}}
    </div>
    {{ghost_foot}}
</body>

The <body> is acting as the Grid container, and the sidebar and main where already equipped with the correct classes.

With this simple addition the page already looks like this:

Ghost theme - Part 2: a Grid

Variables

Now we have a good base to start introducing variables in CSS.
We can use these due to the postcss-custom-properties that are included in the default gotede gulp task.

What this will allow us is to define certain variables that should be applied throughout our app and then reuse them whenever needed.

By doing this we introduce 2 benefits.

  1. We can easily make a change in 1 place that will be applied everywhere that value was used
  2. There is 1 place to check in order to find out what specific values are

The place to define those is f.e. assets/css/helpers/variables.css, so lets create some, that we can use for our grid.

:root {
  /* Container sizes */
  --main-width: 80vw;
  --sidebar-width: 20vw;

  /* Gutter sizes */
  --gutter-horizontal--small: 2vw;
}

Notice that they are wrapped in the :root{} block.

Once this is done the gulp task will automatically make those 'available' in all our CSS files (This is actually done in the build step, but thats semantics I guess).

Lets import them and use them for the grid like this:


@import "./helpers/variables.css";


.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: var(--sidebar-width) var(--main-width);
  grid-template-rows: 1fr;
  grid-gap: 0px;
  grid-template-areas: "Sidebar Content";
}

.main {
  grid-area: Content;
}

.sidebar {
  grid-area: Sidebar;
}

You can see that the variables are used with var(VARIABLE_NAME). While this might not seem super important or useful right now, be sure that this will save a lot of headaches down the line.

A break in the layout

Ghost theme - Part 2: a Grid

To fix this lets set a max-width on the main container. This does exactly what the name implies, telling it that its maximum width should be of some value.
Which one is the correct value? Given our Layout it should be the --main-width variable. Already comming in handy :).

Lets add it to the .main block

.main {
  grid-area: Content;
  max-width: var(--main-width);
}

Check out the post again. All good?
Nope, looks like the picture is still escaping to the right.

If you inspect the HTML you can find the picture class .kg-image. For this class we will add a rule of max-width: 100%; for now, until we encounter the styling of the pictures again, later on.

Ghost theme - Part 2: a Grid

By the way, you can ignore the purple lines.
These are added by the Firefox developer tools. You can read about these here if you would like to use them too.

A small task for you

Check out the Publishing options article. On this page you should encounter another problem of content escaping.
I will leave this as a small task for you to fix right now. Should you need help or a hint feel free to drop me a short email or contact me on my new twitter.

What next?

The theme already looks quite a bit like the sketch. One thing we need to ensure though, is that there are always only 2 posts next to each other (and maybe alter this idea for mobile devices?).

So the next post will be focussing on those 2 topics including media-queries and flexbox.

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Ghost theme - Part 2: a Grid

In this post I want to start with the styling.
the first thing here is to consult the sketches again.

Ghost theme - Part 2: a Grid

Since we split out the sidebar into the default layout, we should create a Grid for this first.
The technology I am going to use here is CSS-Grid.

The only to be aware of is the browser support. Check caniuse.com to see if it supports the browsers you want.
Since this is my personal blog and the audience is probably using modern browsers (this is an assumption, as I have no tracking yet) I am totally fine with ignoring older and more exotic browsers for now.

Grid

With tools like https://www.layoutit.com/grid we can quickly generate a basic layout.

The generated code for the grid I want on the blog according to the sketches looks like this

.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: 20vw 80vw;
  grid-template-rows: 1fr;
  grid-gap: 0px;
  grid-template-areas: "Sidebar Content";
}

.main{ grid-area: Content; }

.sidebar { grid-area: Sidebar; }

This will have to go into a css file at assets/css/styles.css in the theme folder.

Make sure to restart the `npm run start` task, so that gulp can pick up on the newly created `.css` file. Unfortunately this is not detected automatically.

In the default.hbs this stylesheet now needs to be imported and the correct classes need to be added to the HTML in the  like following:


<head>
...
<link rel="stylesheet" type="text/css" href="{{asset "built/styles.css"}}" />

</head>

<body class="{{body_class}} grid-container">
    <div class="sidebar">
        <header>
            <h1 class="page-title">{{@blog.title}}</h1>
            <h2 class="page-description">{{@blog.description}}</h2>
            <nav class="navigation">
                {{navigation}}
            </nav>
        </header>
    </div>
    <div class="main">
        {{{body}}}
    </div>
    {{ghost_foot}}
</body>

The <body> is acting as the Grid container, and the sidebar and main where already equipped with the correct classes.

With this simple addition the page already looks like this:

Ghost theme - Part 2: a Grid

Variables

Now we have a good base to start introducing variables in CSS.
We can use these due to the postcss-custom-properties that are included in the default gotede gulp task.

What this will allow us is to define certain variables that should be applied throughout our app and then reuse them whenever needed.

By doing this we introduce 2 benefits.

  1. We can easily make a change in 1 place that will be applied everywhere that value was used
  2. There is 1 place to check in order to find out what specific values are

The place to define those is f.e. assets/css/helpers/variables.css, so lets create some, that we can use for our grid.

:root {
  /* Container sizes */
  --main-width: 80vw;
  --sidebar-width: 20vw;

  /* Gutter sizes */
  --gutter-horizontal--small: 2vw;
}

Notice that they are wrapped in the :root{} block.

Once this is done the gulp task will automatically make those 'available' in all our CSS files (This is actually done in the build step, but thats semantics I guess).

Lets import them and use them for the grid like this:


@import "./helpers/variables.css";


.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: var(--sidebar-width) var(--main-width);
  grid-template-rows: 1fr;
  grid-gap: 0px;
  grid-template-areas: "Sidebar Content";
}

.main {
  grid-area: Content;
}

.sidebar {
  grid-area: Sidebar;
}

You can see that the variables are used with var(VARIABLE_NAME). While this might not seem super important or useful right now, be sure that this will save a lot of headaches down the line.

A break in the layout

Ghost theme - Part 2: a Grid

To fix this lets set a max-width on the main container. This does exactly what the name implies, telling it that its maximum width should be of some value.
Which one is the correct value? Given our Layout it should be the --main-width variable. Already comming in handy :).

Lets add it to the .main block

.main {
  grid-area: Content;
  max-width: var(--main-width);
}

Check out the post again. All good?
Nope, looks like the picture is still escaping to the right.

If you inspect the HTML you can find the picture class .kg-image. For this class we will add a rule of max-width: 100%; for now, until we encounter the styling of the pictures again, later on.

Ghost theme - Part 2: a Grid

By the way, you can ignore the purple lines.
These are added by the Firefox developer tools. You can read about these here if you would like to use them too.

A small task for you

Check out the Publishing options article. On this page you should encounter another problem of content escaping.
I will leave this as a small task for you to fix right now. Should you need help or a hint feel free to drop me a short email or contact me on my new twitter.

What next?

The theme already looks quite a bit like the sketch. One thing we need to ensure though, is that there are always only 2 posts next to each other (and maybe alter this idea for mobile devices?).

So the next post will be focussing on those 2 topics including media-queries and flexbox.

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Creating a new ghost theme - Part 1

I want to make my blog more unique and fitting to my style both in code and in looks.
Writing my own theme seems like the right thing to do, given that I am currently looking for a job and having both more free time and wanting to look good to possible employers.

So I want to accompany this with a few blog posts on how I am going about this.

All of this will be done incrementally and I will set the theme live, so you can give me some feedback if you can/want. The best way to do this is on Twitter or at max [at] ehlers . berlin.

The development environment

The first thing that I need is a development environment. I wrote this article about a small script I wrote to help with this.

The homepage/index

When you come to this blog via its basic URL the first thing you are going to be greeted with is the index.

So this is also the first thing that I want to work on.

Here is a small sketch I made to get started:

Creating a new ghost theme - Part 1

Now I implemented all the things needed according to the Documentation in the index.hbs of my theme.

It now looks like this

<header>
  <h1 class="page-title">{{@blog.title}}</h1>
  <h2 class="page-description">{{@blog.description}}</h2>
  <nav class="navigation">
    {{navigation}}
  </nav>
</header>

<main role="main">
  {{#foreach posts}}
	<article class="{{post_class}}">
 		<header class="post-header">
   		<h2><a href="{{url}}">{{title}}</a></h2>
    </header>
    <section class="post-excerpt">
 			<p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">...</a></p>
    </section>
    <footer class="post-meta">
      {{authors}}
      {{tags prefix=" on "}}
      <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
    </footer>
  </article>
  {{/foreach}}
</main>

{{pagination}}

When you made the changes, make sure to restart Ghost or reenable your theme.
Since my instance in running inside a container I can do a quick docker restart THEME_NAME and reload the page.

This code is only adopted very slightly from the example given in the documentation. All that is removed is the author image for each post, and a navigation is added in the <header>.

I am not worrying about the design yet, this post is only about the structure. Having the sketch just helps me in figuring out what is needed on the page.

Posts

Next up are the posts.
Again a quick sketch:
Creating a new ghost theme - Part 1

We can again consult the Documentation and can copy the example code, so that the post.hbs looks like this:

{{#post}}
              
<article class="{{post_class}}">
  <header class="post-header">
    <h1 class="post-title">{{title}}</h1>
    <section class="post-meta">
      <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">
        {{date format="DD MMMM YYYY"}}
      </time> 
      {{tags prefix=" on "}}
    </section>  
  </header>
  <section class="post-content">
    {{content}}
  </section>     
</article>

{{/post}} 

Now we will have to somehow add the navigation sidebar here and since it is not supposed to change on any pages on the blog we can use a default.hbs file in our theme.
This file we be applied to all pages that Ghost will display.

First we remove the navigation from our index.hbs file and then create the default.hbs with the following content.
It will include a few helpers from Ghost so that different things can be injected here from the Admin panel.

<!DOCTYPE html>
<html lang="{{lang}}">

<head>
    {{! Document settings and metadata }}
    <title>{{meta_title}}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" /> 
    {{!-- This tag outputs SEO meta+structured data and other important settings --}}
    {{ghost_head}}
</head>

<body class="{{body_class}}">
    <div class="sidebar">
        <header>
            <h1 class="page-title">{{@blog.title}}</h1>
            <h2 class="page-description">{{@blog.description}}</h2>
            <nav class="navigation">
                {{navigation}}
            </nav>
        </header>
    </div>
    <div class="main">
        {{{body}}}
    </div>
    {{ghost_foot}}
</body>

</html>

Once we have this file we need to tell both the index.hbs and post.hbs file that they should use this default file by adding

{{!< default}}

to the top of both files.

We can now restart our Ghost instance and should see the navigation on both pages.

Here is a screenshot of the posts page:

Creating a new ghost theme - Part 1

Wrap up

This should be enough for a start.
The theme now has the basic structure to start with a bit of styling.

Ill cover that in the next article :)

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Creating a new ghost theme - Part 1

I want to make my blog more unique and fitting to my style both in code and in looks.
Writing my own theme seems like the right thing to do, given that I am currently looking for a job and having both more free time and wanting to look good to possible employers.

So I want to accompany this with a few blog posts on how I am going about this.

All of this will be done incrementally and I will set the theme live, so you can give me some feedback if you can/want. The best way to do this is on Twitter or at max [at] ehlers . berlin.

The development environment

The first thing that I need is a development environment. I wrote this article about a small script I wrote to help with this.

The homepage/index

When you come to this blog via its basic URL the first thing you are going to be greeted with is the index.

So this is also the first thing that I want to work on.

Here is a small sketch I made to get started:

Creating a new ghost theme - Part 1

Now I implemented all the things needed according to the Documentation in the index.hbs of my theme.

It now looks like this

<header>
  <h1 class="page-title">{{@blog.title}}</h1>
  <h2 class="page-description">{{@blog.description}}</h2>
  <nav class="navigation">
    {{navigation}}
  </nav>
</header>

<main role="main">
  {{#foreach posts}}
	<article class="{{post_class}}">
 		<header class="post-header">
   		<h2><a href="{{url}}">{{title}}</a></h2>
    </header>
    <section class="post-excerpt">
 			<p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">...</a></p>
    </section>
    <footer class="post-meta">
      {{authors}}
      {{tags prefix=" on "}}
      <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
    </footer>
  </article>
  {{/foreach}}
</main>

{{pagination}}

When you made the changes, make sure to restart Ghost or reenable your theme.
Since my instance in running inside a container I can do a quick docker restart THEME_NAME and reload the page.

This code is only adopted very slightly from the example given in the documentation. All that is removed is the author image for each post, and a navigation is added in the <header>.

I am not worrying about the design yet, this post is only about the structure. Having the sketch just helps me in figuring out what is needed on the page.

Posts

Creating a new ghost theme - Part 1

We can again consult the Documentation and can copy the example code, so that the post.hbs looks like this:

{{#post}}
              
<article class="{{post_class}}">
  <header class="post-header">
    <h1 class="post-title">{{title}}</h1>
    <section class="post-meta">
      <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">
        {{date format="DD MMMM YYYY"}}
      </time> 
      {{tags prefix=" on "}}
    </section>  
  </header>
  <section class="post-content">
    {{content}}
  </section>     
</article>

{{/post}} 

Now we will have to somehow add the navigation sidebar here and since it is not supposed to change on any pages on the blog we can use a default.hbs file in our theme.
This file we be applied to all pages that Ghost will display.

First we remove the navigation from our index.hbs file and then create the default.hbs with the following content.
It will include a few helpers from Ghost so that different things can be injected here from the Admin panel.

<!DOCTYPE html>
<html lang="{{lang}}">

<head>
    {{! Document settings and metadata }}
    <title>{{meta_title}}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" /> 
    {{!-- This tag outputs SEO meta+structured data and other important settings --}}
    {{ghost_head}}
</head>

<body class="{{body_class}}">
    <div class="sidebar">
        <header>
            <h1 class="page-title">{{@blog.title}}</h1>
            <h2 class="page-description">{{@blog.description}}</h2>
            <nav class="navigation">
                {{navigation}}
            </nav>
        </header>
    </div>
    <div class="main">
        {{{body}}}
    </div>
    {{ghost_foot}}
</body>

</html>

Once we have this file we need to tell both the index.hbs and post.hbs file that they should use this default file by adding

{{!< default}}

to the top of both files.

We can now restart our Ghost instance and should see the navigation on both pages.

Here is a screenshot of the posts page:

Creating a new ghost theme - Part 1

Wrap up

This should be enough for a start.
The theme now has the basic structure to start with a bit of styling.

Ill cover that in the next article :)

Read more
Max

Please Note that this theme is not in use anymore. See this post for more info.

Creating a new ghost theme - Part 1

I want to make my blog more unique and fitting to my style both in code and in looks.
Writing my own theme seems like the right thing to do, given that I am currently looking for a job and having both more free time and wanting to look good to possible employers.

So I want to accompany this with a few blog posts on how I am going about this.

All of this will be done incrementally and I will set the theme live, so you can give me some feedback if you can/want. The best way to do this is on Twitter or at max [at] ehlers . berlin.

The development environment

The first thing that I need is a development environment. I wrote this article about a small script I wrote to help with this.

The homepage/index

When you come to this blog via its basic URL the first thing you are going to be greeted with is the index.

So this is also the first thing that I want to work on.

Here is a small sketch I made to get started:

Creating a new ghost theme - Part 1

Now I implemented all the things needed according to the Documentation in the index.hbs of my theme.

It now looks like this

<header>
  <h1 class="page-title">{{@blog.title}}</h1>
  <h2 class="page-description">{{@blog.description}}</h2>
  <nav class="navigation">
    {{navigation}}
  </nav>
</header>

<main role="main">
  {{#foreach posts}}
	<article class="{{post_class}}">
 		<header class="post-header">
   		<h2><a href="{{url}}">{{title}}</a></h2>
    </header>
    <section class="post-excerpt">
 			<p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">...</a></p>
    </section>
    <footer class="post-meta">
      {{authors}}
      {{tags prefix=" on "}}
      <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
    </footer>
  </article>
  {{/foreach}}
</main>

{{pagination}}

When you made the changes, make sure to restart Ghost or reenable your theme.
Since my instance in running inside a container I can do a quick docker restart THEME_NAME and reload the page.

This code is only adopted very slightly from the example given in the documentation. All that is removed is the author image for each post, and a navigation is added in the <header>.

I am not worrying about the design yet, this post is only about the structure. Having the sketch just helps me in figuring out what is needed on the page.

Posts

Creating a new ghost theme - Part 1

We can again consult the Documentation and can copy the example code, so that the post.hbs looks like this:

{{#post}}
              
<article class="{{post_class}}">
  <header class="post-header">
    <h1 class="post-title">{{title}}</h1>
    <section class="post-meta">
      <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">
        {{date format="DD MMMM YYYY"}}
      </time> 
      {{tags prefix=" on "}}
    </section>  
  </header>
  <section class="post-content">
    {{content}}
  </section>     
</article>

{{/post}} 

Now we will have to somehow add the navigation sidebar here and since it is not supposed to change on any pages on the blog we can use a default.hbs file in our theme.
This file we be applied to all pages that Ghost will display.

First we remove the navigation from our index.hbs file and then create the default.hbs with the following content.
It will include a few helpers from Ghost so that different things can be injected here from the Admin panel.

<!DOCTYPE html>
<html lang="{{lang}}">

<head>
    {{! Document settings and metadata }}
    <title>{{meta_title}}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" /> 
    {{!-- This tag outputs SEO meta+structured data and other important settings --}}
    {{ghost_head}}
</head>

<body class="{{body_class}}">
    <div class="sidebar">
        <header>
            <h1 class="page-title">{{@blog.title}}</h1>
            <h2 class="page-description">{{@blog.description}}</h2>
            <nav class="navigation">
                {{navigation}}
            </nav>
        </header>
    </div>
    <div class="main">
        {{{body}}}
    </div>
    {{ghost_foot}}
</body>

</html>

Once we have this file we need to tell both the index.hbs and post.hbs file that they should use this default file by adding

{{!< default}}

to the top of both files.

We can now restart our Ghost instance and should see the navigation on both pages.

Here is a screenshot of the posts page:

Creating a new ghost theme - Part 1

Wrap up

This should be enough for a start.
The theme now has the basic structure to start with a bit of styling.

Ill cover that in the next article :)

Read more