Jekyll 没有阅读 site.posts
Jekyll is not reading site.posts
最近,我决定在 Github 页面上开始我的博客。我 fork Jekyll-Now 并将代码拉入我的本地环境。
现在我正在 运行ning jekyll serve
但它没有阅读 _posts 文件夹中的帖子!
似乎无法读取index.html
中的site.posts
变量。如果我输出变量或将其检查为:{{ site.posts | inspect }}
那么它是空的。
帖子名称格式正确 YYYY-MM-DD-TITLE.md
如果我在 _posts
文件夹中 运行 jekyll serve
,那么我将得到一个 IndexOf
页面,其中列出了所有帖子,没有任何问题。
_config.yml
的内容:
# Name of your site (displayed in the header)
name: My name
# Short bio or description (displayed in the header)
description: Blog on various topics
# URL of your avatar or profile pic (you could use your GitHub profile pic)
# avatar: https://raw.githubusercontent.com/barryclark/jekyll-now/master/images/jekyll-logo.png
# Includes an icon in the footer for each username you enter
footer-links:
github: motleis/blog
baseurl: ""
permalink: /:title/
# The release of Jekyll Now that you're using
version: v3.4.0
# Jekyll 3 now only supports Kramdown for Markdown
kramdown:
# Use GitHub flavored markdown, including triple backtick fenced code blocks
input: GFM
# Jekyll 3 and GitHub Pages now only support rouge for syntax highlighting
syntax_highlighter: rouge
syntax_highlighter_opts:
# Use existing pygments syntax highlighting css
css_class: 'highlight'
# Set the Sass partials directory, as we're using @imports
sass:
style: :expanded # You might prefer to minify using :compressed
# Use the following plug-ins
gems:
- jekyll-sitemap # Create a sitemap using the official Jekyll sitemap gem
- jekyll-feed # Create an Atom feed using the official Jekyll feed gem
# Exclude these files from your production _site
exclude:
- Gemfile
- Gemfile.lock
- LICENSE
- README.md
- CNAME
在 _posts 下:我只有简单的示例文件:
2014-3-3-你好-World.md
---
layout: post
title: You're up and running!
---
Just a single line that should be displayed!
下面是 index.html
的内容,其中应列出帖子:
site.posts : {{ site.posts }}
My posts:
<ul>
{% for post in site.posts %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
{{ post.excerpt }}
</li>
{% endfor %}
</ul>
结果是:
site.posts :
My Posts:
如您所见,site.posts 是空的!
您对调试此问题有何建议?
我是运行ning jeykll-3.4.0
更新答案:
检查您的帖子是否在 YYYY-MM-DD-title.MARKUP,即 2017-01-0 1-title.md 样式,填充为 0。
在 Jekyll 文档页面 "Writing Posts" 的“创建 Post 文件”下:
To create a new post, all you need to do is create a file in the _posts directory. How you name files in this folder is important. Jekyll requires blog post files to be named according to the following format:
YEAR-MONTH-DAY-title.MARKUP
Where YEAR is a four-digit number, MONTH and DAY are both two-digit numbers, and MARKUP is the file extension representing the format used in the file. For example, the following are examples of valid post filenames:
2011-12-31-new-years-eve-is-awesome.md
2012-09-12-how-to-write-a-blog.md
原答案:
您的 _posts 文件夹是否位于您网站的根目录中?
否则我的主要建议是创建一个布局(在布局文件夹中)专门用于显示您的索引(因此制作一个普通网页并将 index.md 文件的当前非 frontmatter 内容复制并粘贴到其中).据我了解,如果不是 Liquid 或 Markdown,您的代码将按原样显示,并且不会为构建网站而读取/处理。即使您的 index.md 页面的下半部分完全空白,据我所知,它也应该显示您的帖子。
最近,我决定在 Github 页面上开始我的博客。我 fork Jekyll-Now 并将代码拉入我的本地环境。
现在我正在 运行ning jekyll serve
但它没有阅读 _posts 文件夹中的帖子!
似乎无法读取index.html
中的site.posts
变量。如果我输出变量或将其检查为:{{ site.posts | inspect }}
那么它是空的。
帖子名称格式正确 YYYY-MM-DD-TITLE.md
如果我在 _posts
文件夹中 运行 jekyll serve
,那么我将得到一个 IndexOf
页面,其中列出了所有帖子,没有任何问题。
_config.yml
的内容:
# Name of your site (displayed in the header)
name: My name
# Short bio or description (displayed in the header)
description: Blog on various topics
# URL of your avatar or profile pic (you could use your GitHub profile pic)
# avatar: https://raw.githubusercontent.com/barryclark/jekyll-now/master/images/jekyll-logo.png
# Includes an icon in the footer for each username you enter
footer-links:
github: motleis/blog
baseurl: ""
permalink: /:title/
# The release of Jekyll Now that you're using
version: v3.4.0
# Jekyll 3 now only supports Kramdown for Markdown
kramdown:
# Use GitHub flavored markdown, including triple backtick fenced code blocks
input: GFM
# Jekyll 3 and GitHub Pages now only support rouge for syntax highlighting
syntax_highlighter: rouge
syntax_highlighter_opts:
# Use existing pygments syntax highlighting css
css_class: 'highlight'
# Set the Sass partials directory, as we're using @imports
sass:
style: :expanded # You might prefer to minify using :compressed
# Use the following plug-ins
gems:
- jekyll-sitemap # Create a sitemap using the official Jekyll sitemap gem
- jekyll-feed # Create an Atom feed using the official Jekyll feed gem
# Exclude these files from your production _site
exclude:
- Gemfile
- Gemfile.lock
- LICENSE
- README.md
- CNAME
在 _posts 下:我只有简单的示例文件: 2014-3-3-你好-World.md
---
layout: post
title: You're up and running!
---
Just a single line that should be displayed!
下面是 index.html
的内容,其中应列出帖子:
site.posts : {{ site.posts }}
My posts:
<ul>
{% for post in site.posts %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
{{ post.excerpt }}
</li>
{% endfor %}
</ul>
结果是:
site.posts :
My Posts:
如您所见,site.posts 是空的!
您对调试此问题有何建议?
我是运行ning jeykll-3.4.0
更新答案:
检查您的帖子是否在 YYYY-MM-DD-title.MARKUP,即 2017-01-0 1-title.md 样式,填充为 0。
在 Jekyll 文档页面 "Writing Posts" 的“创建 Post 文件”下:
To create a new post, all you need to do is create a file in the _posts directory. How you name files in this folder is important. Jekyll requires blog post files to be named according to the following format:
YEAR-MONTH-DAY-title.MARKUP
Where YEAR is a four-digit number, MONTH and DAY are both two-digit numbers, and MARKUP is the file extension representing the format used in the file. For example, the following are examples of valid post filenames:
2011-12-31-new-years-eve-is-awesome.md
2012-09-12-how-to-write-a-blog.md
原答案:
您的 _posts 文件夹是否位于您网站的根目录中?
否则我的主要建议是创建一个布局(在布局文件夹中)专门用于显示您的索引(因此制作一个普通网页并将 index.md 文件的当前非 frontmatter 内容复制并粘贴到其中).据我了解,如果不是 Liquid 或 Markdown,您的代码将按原样显示,并且不会为构建网站而读取/处理。即使您的 index.md 页面的下半部分完全空白,据我所知,它也应该显示您的帖子。