Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve theme docs #5690

Merged
merged 6 commits into from Jan 24, 2017
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
134 changes: 114 additions & 20 deletions docs/_docs/themes.md
Expand Up @@ -4,28 +4,41 @@ title: Themes
permalink: /docs/themes/
---

Jekyll has an extensive theme system, which allows you to leverage community-maintained templates and styles to customize your site's presentation. Jekyll themes package layouts, includes, and stylesheets in a way that can be overridden by your site's content.
Jekyll has an extensive theme system that allows you to leverage community-maintained templates and styles to customize your site's presentation. Jekyll themes package up layouts, includes, and stylesheets in a way that can be overridden by your site's content.

## Installing a theme
## Understanding gem-based themes

1. To install a theme, first, add the theme to your site's `Gemfile`:
When you [create a new Jekyll site](/docs/quickstart) (by running the `jekyll new <PATH>` command), Jekyll installs a site that uses a gem-based theme called [Minima](https://github.com/jekyll/minima).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- Jekyll installs a gem-based theme called [Minima](https://github.com/jekyll/minima).
+ Jekyll installs a Site that uses a gem-based theme called [Minima](https://github.com/jekyll/minima).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, but why capitalize "site" here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no particular reason. site is just as valid as Site in this context

gem 'my-awesome-jekyll-theme'
With gem-based themes, some of the site's directories (such as the `assets`, `_layouts`, `_includes`, and `_sass` directories) are stored in the theme-gem, hidden from your immediate view. Yet all of the necessary directories will be read and processed during Jekyll's build process.

2. Save the changes to your `Gemfile`
3. Run the command `bundle install` to install the theme
4. Finally, activate the theme by adding the following to your site's `_config.yml`:
In the case of Minima, you see only the following files in your Jekyll site directory:

theme: my-awesome-jekyll-theme
```
├── Gemfile
├── Gemfile.lock
├── _config.yml
├── _posts
│   └── 2016-12-04-welcome-to-jekyll.markdown
├── about.md
└── index.md
```

You can have multiple themes listed in your site's Gemfile, but only one theme can be selected in your site's `_config.yml`.
{: .note .info }
The `Gemfile` and `Gemfile.lock` files are used by Bundler to keep track of the required gems and gem versions you need to build your Jekyll site.

Gem-based themes make it easy for theme developers to make updates available to anyone who has the theme gem. When there's an update, theme developers push the update to RubyGems.

If you have the theme gem, you can (if you desire) run `bundle update` to update all gems in your project. Or you can run `bundle update <theme>`, replacing `<theme>` with the theme name, such as `minima`, to just update the theme gem. Any new files or updates the theme developer has made (such as to stylesheets or includes) will be pulled into your project automatically.

The goal of gem-based themes is to allow you to get all the benefits of a robust, continually updated theme without having all the theme's files getting in your way and over-complicating what might be your primary focus: creating content.

## Overriding theme defaults

Jekyll themes set default layouts, includes, and stylesheets, that can be overridden by your site's content. For example, if your selected theme has a `page` layout, you can override the theme's layout by creating your own `page` layout in the `_layouts` folder (e.g., `_layouts/page.html`).
Jekyll themes set default layouts, includes, and stylesheets. However, you can override any of the theme defaults with your own site content.

Jekyll will look first to your site's content, before looking to the theme's defaults, for any requested file in the following folders:
For example, if your selected theme has a `page` layout, you can override the theme's layout by creating your own `page` layout in the `_layouts` directory (for example, `_layouts/page.html`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for example, _layouts/page.html)

This is a tricky case of "e.g." vs "i.e." and I think it's "i.e." here, because you're elaborating and giving specific information about a pre-existing example. This would read better to me:

by creating your own page layout in the _layouts directory, i.e. _layouts/page.html.

Feel free to replace "i.e." with something less Latin if you would prefer.

Copy link
Contributor Author

@tomjoht tomjoht Dec 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.


Jekyll will look first to your site's content before looking to the theme's defaults for any requested file in the following folders:

* `/assets`
* `/_layouts`
Expand All @@ -35,13 +48,78 @@ Jekyll will look first to your site's content, before looking to the theme's def
Refer to your selected theme's documentation and source repository for more information on what files you can override.
{: .note .info}

To locate theme's files on your computer, run `bundle show` followed by
the name of the theme's gem, e.g. `bundle show minima` for default Jekyll's
theme. Then copy the files you want to override, from the returned path to your root folder.
To locate theme's files on your computer:

1. Run `bundle show` followed by the name of the theme's gem, e.g., `bundle show minima` for default Jekyll's theme.

The location of the theme gem is returned. For example, minima is located in `/usr/local/lib/ruby/gems/2.3.0/gems/minima-2.1.0` on a Mac.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path is not always the path on a Mac, so I'd love to see some specificity here for our users:

is located in /usr/local/lib/ruby/gems/2.3.0/gems/minima-2.1.0 when using the system Ruby installation on a Mac.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


2. Change to the directory's location and open the directory in Finder or Explorer:

```
cd /usr/local/lib/ruby/gems/2.3.0/gems/minima-2.1.0
open .
# for Windows, use "explorer ."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not open /usr/local/lib/ruby/gems/2.3.0/gems/minima-2.1.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"open" doesn't work on the Windows command terminal (at least not mine, and I have a Windows 10 PC. "explorer" does work, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added examples for each OS.

On MacOS you can simply open $(bundle show minima), I leaved the full path with explorer command as I have no clue if that works under Windows.

```

A Finder or Explorer window opens showing the theme's files and directories.

With a clear understanding of the theme's files, you can now override any theme file by creating a similarly named file in your Jekyll site directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps an example here would be useful. The user may still be wondering what the full path is they need to create in their site.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. updated.


## Converting gem-based themes to regular themes

Suppose you want to get rid of the gem-based theme and convert it to a regular theme, where all files are present in your Jekyll site directory, with nothing stored in the theme gem.

To do this, copy the files from the theme gem's directory into your Jekyll site directory. (For example, copy them to `/myblog` if you created your Jekyll site at `/myblog`. See the previous section for details.)

Then modify the Gemfile and configuration to remove references to the theme gem. For example, to remove Minima:
* Open `Gemfile` and remove `gem "minima", "~> 2.0"`.
* Open `_config.yml` and remove `theme: minima`.

Now `bundle update` will no longer get updates for the theme gem.

## Installing a gem-based theme {#installing-a-theme}

The `jekyll new <PATH>` command isn't the only way to create a new Jekyll site with a gem-based theme. You can also find gem-based themes online and incorporate them into your Jekyll project.

For example, search for [jekyll-theme on RubyGems](https://rubygems.org/search?utf8=%E2%9C%93&query=jekyll-theme) to find other gem-based themes. (Note that not all themes are using `jekyll-theme` as a convention in the theme name.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the hyphen and simply use "jekyll theme".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parkr Frank suggested querying for jekyll-theme to display the new themes supported by GitHub Pages gem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

searches for "jekyll theme" return the same as for "jekyll-theme". removing hyphen.


## Creating a theme
To install a gem-based theme:

Jekyll themes are distributed as Ruby gems. Don't worry, Jekyll will help you scaffold a new theme with the `new-theme` command. Just run `jekyll new-theme` with the theme name as an argument:
1. Add the theme to your site's `Gemfile`:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this clear line before the start of a fenced-code block is not needed actually..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see. i thought it was needed. however, without it, the spacing seems too smushed together.

```sh
gem 'my-awesome-jekyll-theme'
```

2. Install the theme:

```sh
bundle install
```

3. Add the following to your site's `_config.yml` to activate the theme:
Copy link
Member

@DirtyF DirtyF Dec 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space at the beginning of the third list item.

code-rendering


```sh
theme: my-awesome-jekyll-theme
```

4. Build your site:

```sh
bundle exec jekyll serve
```

You can have multiple themes listed in your site's `Gemfile`, but only one theme can be selected in your site's `_config.yml`.
{: .note .info }

If you're publishing your Jekyll site on [Github Pages](https://pages.github.com/), note that Github Pages supports only some gem-based themes. See [Supported Themes](https://pages.github.com/themes/) in Github's documentation to see which themes are supported.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github ~> GitHub

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


## Creating a gem-based theme

If you're a Jekyll theme developer (rather than just a consumer of themes), you can package up your theme in RubyGems and allow users to install it through Bundler.

If you're unfamiliar with creating Ruby gems, don't worry. Jekyll will help you scaffold a new theme with the `new-theme` command. Just run `jekyll new-theme` with the theme name as an argument:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section had some changes requested in the previous PR..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pathawkes had said:

Scaffolding a new theme is unrelated to distributing Ruby gems. This is not one sentence

Also, you wrote:

you can package up your theme as ruby gems

Actually, I don't really mean to make controversial changes here. My main changes were in another part of this file. But I made an update to this paragraph just now to change "distributing" to "creating" and also capitalized "Ruby." Isn't Ruby capitalized, just as Java, Python, or other programming languages?

Also, the phrase "don't worry" is short enough to stand on its own.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes Ruby should be capitalized 👍

```sh
jekyll new-theme my-awesome-theme
Expand All @@ -61,7 +139,7 @@ Your new Jekyll theme, my-awesome-theme, is ready for you in /path/to/my-awesome
For help getting started, read /path/to/my-awesome-theme/README.md.
```

Add your template files in the corresponding folders, complete the `.gemspec` and the README files according to your needs.
Add your template files in the corresponding folders. Then complete the `.gemspec` and the README files according to your needs.

### Layouts and includes

Expand All @@ -71,13 +149,29 @@ For example, if your theme has a `/_layouts/page.html` file, and a page has `lay

### Assets

Any file in `/assets` will be copied over to the user's site upon build unless they have a file with the same relative path. You may ship any kind of asset here: SCSS, an image, a webfont, etc. These files behave just like pages and static files in Jekyll: if the file has [YAML front matter]({{ site.baseurl }}/docs/frontmatter/) at the top, then it will be rendered. If it does not have YAML front matter, it will simply be copied over into the resulting site. This allows theme creators to ship a default `/assets/styles.scss` file which their layouts can depend on as `/assets/styles.css`.
Any file in `/assets` will be copied over to the user's site upon build unless they have a file with the same relative path. You can ship any kind of asset here: SCSS, an image, a webfont, etc. These files behave just like pages and static files in Jekyll:

* If the file has [YAML front matter](../docs/frontmatter/) at the top, it will be rendered.
* If the file does not have YAML front matter, it will simply be copied over into the resulting site.

This allows theme creators to ship a default `/assets/styles.scss` file which their layouts can depend on as `/assets/styles.css`.

All files in `/assets` will be output into the compiled site in the `/assets` folder just as you'd expect from using Jekyll on your sites.

### Stylesheets

Your theme's stylesheets should be placed in your theme's `/_sass` folder, again, just as you would when authoring a Jekyll site. Your theme's styles can be included in the user's stylesheet using the `@import` directive.
Your theme's stylesheets should be placed in your theme's `_sass` folder, again, just as you would when authoring a Jekyll site.

```
_sass
├── jekyll-theme-my-awesome-theme.scss
```

Your theme's styles can be included in the user's stylesheet using the `@import` directive.

```css
{% raw %}@import "{{ site.theme }}";{% endraw %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while I'm 👍 on the use of @import "{{ site.theme }}";, lets hope it doesn't create confusion or an extra step of customization for people opting to not using gem-based themes or in the rare situation that the theme-gem doesn't name their main sass file the same as their theme-name..

```

### Documenting your theme

Expand Down