I have been using the theme CodeIT for my blog. I am encountering a problem now that I want to introduce a change.
The theme, by default, shows the blog as soon as you open the website.
I want the first page to be shown to be a static page, something like an about page, and the blog to be accessible by clicking “Blog” in the menu.
By adding an index.html file in /layouts/, and an _index.md in /content/, I managed to override the default behaviour and the static page shows correctly.
My problem now is that I can’t move the blog to myblog.com/blog/.
I don’t think you need a _index.md file in your content/blog folder—I don’t in mine. Just put the markdown files of the blog posts in that folder.
The original theme has an index.html in /themes/CodeIT/layouts/. This produces a nice blog page in the homepage.
I modified index.html to suit what I need and moved it to /layouts/ to override the theme’s original. Then wrote my content for the homepage in /content/_index.md.
Now, I had lost the theme’s blog page. I wanted the theme’s blog page to be visualised in mydomain.com/blog/. This is how I achieved it. I don’t know how clean this hack is, but it works.
I copied the original index.html from /themes/CodeIT/layouts/, renamed it to blog.html, created the folder /layouts/blog/, and put blog.html in this folder.
Then I created the folder /content/blog/ and put an empty page in there. It doesn’t seem to matter what you name that page, I named it blog.md but it could be hello-world.md. This does the trick. (Just don’t name it index.md.)
Now when I open the domain I can see my personalised page, and if I click on “Blog” from the menu it visualises the theme’s blog layout with all the posts.
I didn’t need to move the posts from /posts/ to /blog/, everything is still in /posts/ as intended. This allows my visitors to access the page mydomain.com/posts/ in order to see the simple list page with all the posts in chronological order.
That’s not a hack, it’s the proper way to do it That’s why the theme is in a subfolder. Everything you mirror in your root layouts directory will override (modify) the theme files in the same location under themes/themename/layouts.