Sean Lou

专注前端开发

Jekyll Usage

Posted in • other at 2012-03-08 by lxj
Tags:Jekyll,data,

From:https://github.com/mojombo/jekyll/wiki/Usage

Creating a Jekyll site usually involves the following, [[once jekyll is installed.Install]]
  1. Set up the basic structure of the site
  2. Create some posts, or [[import them from your previous platformBlog migrations]]
  3. Run your site locally to see how it looks
  4. Deploy your site

Basic Structure

Jekyll at its core is a text transformation engine. The concept behind the system is this: you give it text written in your favorite markup language, be that Markdown, Textile, or just plain HTML, and it churns that through a layout or series of layout files. Throughout that process you can tweak how you want the site URLs to look, what data gets displayed on the layout and more. This is all done through strictly editing files, and the web interface is the final product.

A basic Jekyll site usually looks something like this:

.
|-- _config.yml
|-- _includes
|-- _layouts
|   |-- default.html
|   `-- post.html
|-- _posts
|   |-- 2007-10-29-why-every-programmer-should-play-nethack.textile
|   `-- 2009-04-26-barcamp-boston-4-roundup.textile
|-- _site
`-- index.html

An overview of what each of these does:

_config.yml

Stores [[configurationConfiguration]] data. A majority of these options can be specified from the command line executable but it’s easier to throw them in here so you don’t have to remember them.

_layouts

These are the templates which posts are inserted into. Layouts are defined on a post-by-post basis in the [[YAML front matter]], which is described in the next section. The liquid tag <!doctype html> Jekyll Template data - Sean Lou

Sean Lou

专注前端开发

Jekyll Template data

Posted in • other at 2012-03-08 by lxj
Tags:Jekyll,data,
From:https://github.com/mojombo/jekyll/wiki/Template-Data Jekyll traverses your site looking for files to process. Any files with [[YAML Front Matter]] are subject to processing. For each of these files, Jekyll makes a variety of data available to the pages via the "Liquid templating system":http://wiki.github.com/shopify/liquid/liquid-for-designers. The following is a reference of the available data. h2. Global | *Variable* | *Description* | | @site@ | Sitewide information + Configuration settings from @_config.yml@ | | @page@ | This is just the [[YAML Front Matter]] with 2 additions: @url@ and @content@. | | @content@ | In layout files, this contains the content of the subview(s). This is the variable used to insert the rendered content into the layout. This is not used in post files or page files. | | @paginator@| When the @paginate@ configuration option is set, this variable becomes available for use. | h2. Site | *Variable* | *Description* | | @site.time@ | The current Time (when you run the jekyll command). | | @site.posts@ | A reverse chronological list of all Posts. | | @site.related_posts@ |If the page being processed is a Post, this contains a list of up to ten related Posts. By default, these are low quality but fast to compute. For high quality but slow to compute results, run the jekyll command with the @--lsi@ (latent semantic indexing) option. | | @site.categories.CATEGORY@ | The list of all Posts in category @CATEGORY@. | | @site.tags.TAG@ | The list of all Posts with tag @TAG@. | | @site.[CONFIGURATION_DATA]@ | As of *0.5.2*, all data inside of your @_config.yml@ is now available through the @site@ variable. So for example, if you have @url: http://mysite.com@ in your configuration file, then in your posts and pages it can be used like so: http://www.lxj.name. Jekyll does not parse a changed @_config.yml@ in @auto@ mode, you have to restart jekyll. | h2. Page | *Variable* | *Description* | | @page.url@ | The URL of the Page without the domain. e.g. @/es/index.html@ | | @page.content@ | The un-rendered content of the Page. | Note: Any custom front matter that you specify will be available under @page@. For example, if you specify @custom_css: true@ in a page's front matter, that value will be available in templates as @page.custom_css@ h2. Post | *Variable* | *Description* | | @post.title@ | The title of the Post. | | @post.url@ | The URL of the Post without the domain. e.g. @/2008/12/14/my-post.html@ | | @post.date@ | The Date assigned to the Post. This can be overridden in a post's front matter by specifying a new date/time in the format @YYYY-MM-DD HH:MM:SS@ | | @post.id@ | An identifier unique to the Post (useful in RSS feeds). e.g. @/2008/12/14/my-post@ | | @post.categories@ | The list of categories to which this post belongs. Categories are derived from the directory structure above the ==_posts== directory. For example, a post at @/work/code/_posts/2008-12-24-closures.textile@ would have this field set to @['work', 'code']@. These can also be specified in the [[YAML Front Matter]] | | @post.tags@ | The list of tags to which this post belongs. These can be specified in the [[YAML Front Matter]] | | @post.content@ | The rendered content of the Post. | h2. Paginator *note: only available in index files, can be in subdirectory /blog/index.html* | *Variable* | *Description* | | @paginator.per_page@ | Number of posts per page. | | @paginator.posts@ | Posts available for that page. | | @paginator.total_posts@ | Total number of posts. | | @paginator.total_pages@ | Total number of pages. | | @paginator.page@ | The number of the current page. | | @paginator.previous_page@ | The number of the previous page. | | @paginator.next_page@ | The number of the next page. |
© 2012

</code> is used to inject data onto the page.

_posts

Your dynamic content, so to speak. The format of these files is important, as named as YEAR-MONTH-DAY-title.MARKUP. The [[Permalinkspermalinks]] can be adjusted very flexibly for each post, but the date and markup language are determined solely by the file name.

_site

This is where the generated site will be placed once Jekyll is done transforming it. It’s probably a good idea to add this to your .gitignore file.

index.html and Other HTML/Markdown/Textile Files

Provided that the file has a [[YAML Front Matter]] section, it will be transformed by Jekyll. The same will happen for any .html, .markdown, or .textile file in your site’s root directory or directories not listed above.

Other Files/Folders

Every other directory and file except for those listed above will be transferred over as expected. For example, you could have a css folder, a favicon.ico, etc, etc. There’s [[plenty of sitesSites]] already using Jekyll if you’re curious as to how they’re laid out.

Any files in these directories will be parsed and transformed, according to the same rules mentioned previously for files in the root directory.

Running Jekyll

Usually this is done through the jekyll executable, which is installed with the gem. In order to get a server up and running with your Jekyll site, run:

jekyll --server

and then browse to http://0.0.0.0:4000. There’s plenty of [[configuration optionsConfiguration]] available to you as well.

On Debian or Ubuntu, you may need to add /var/lib/gems/1.8/bin/ to your path.

base-url option

If you are using base-url option like

jekyll --server --base-url '/blog'

then make sure that you access the site at

http://localhost:4000/blog/index.html .

Just accessing

http://localhost:4000/blog

will not work.

Deployment

Since Jekyll simply generates a folder filled with HTML files, it can be served using practically any available web server out there. Please check the [[Deployment]] page for more information regarding specific scenarios.

blog comments powered by Disqus
© 2012