key for name of json file (rather than just its fields) for use in Jekyll page generator?

别等时光非礼了梦想. 提交于 2021-01-29 20:11:04

问题


I'm using a data page generator for my Jekyll website to create pages based on a folder of JSON files. I want the generator to use the names of the json files as the page title, but I can't figure out the right syntax to tell it to use the file name instead of one of the fields in the json.

I can access the file name in one of the layout pages with:

for file in site.data.drinks 
file[0]

But file[0] doesn't work in the config (neither does record[0] or record):

  - data: drinks
    template: drink
    name: name
    title: name
    dir: drinks
    extension: html

where it seems to be just looking for the name of one of the fields in the json. I've been using the actual name of the page "Gin and Tonic" and usually that's fine because it matches the name of the file "gin-and-tonic.json", but in the cases where it doesn't, the website breaks.

So what's the right way to tell it to use the actual filename, and for the future, where should I look to figure out this kind of thing. Any help is greatly appreciated!

来源:https://stackoverflow.com/questions/65620610/key-for-name-of-json-file-rather-than-just-its-fields-for-use-in-jekyll-page-g

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