问题
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