Get Jekyll collection item name (HRU)

大城市里の小女人 提交于 2019-12-24 11:27:28

问题


I'm making a Jekyll site destinated for GitHub Pages, and pre-testing it on local Windows 8.1 PC with Jekyll 2.5.3, Ruby 2.0.0p598 (2014-11-13) [x64-mingw32] and Gem 2.0.14.

In Jekyll, I have a collection named albums.

Directory structure for _albums is similar to the following:

_albums
    foo.md
    bar.md
    baz.md

Each file has Front Matter containing values such as title, description etc.

In some site page I'm making a Liquid loop such as following:

{% for album in site.albums %}
    /* need to get album name here */
{% endfor %}

The question is:

How can I get a bare name for collection item — like foo or bar (without extension, containing folders etc.)

Jekyll documentation says something about name variable, but album variable only has following properties: output, content, path, relative_path, url, collection (and also title and description I set in Front Matter)

album.path has value similar to: d:/repo/<project_name>/_albums/foo.md

A workaround I use for now is:

{% assign album_name = album.path | split:"/" | last | split:"." | first %}

Could you please suggest any better way?

Thank you in advance.

来源:https://stackoverflow.com/questions/30963826/get-jekyll-collection-item-name-hru

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!