【发布时间】:2017-07-20 20:56:17
【问题描述】:
最近,我决定在 Github Pages 上开始我的博客。我 fork Jekyll-Now 并将代码拉入我的本地环境。
现在我正在运行 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-Hello-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 是空的!
您对调试此问题有何建议?
我正在运行 jeykll-3.4.0
【问题讨论】:
-
发布您在
_posts文件夹中的帖子及其文件名。还有_config.yml. -
感谢 @marcanuy 的评论和编辑我问题中的标记。我刚刚编辑了帖子,希望它更清楚
-
似乎没问题,它应该与根文件夹(即包含
_config.yml的文件夹)下的jekyll serve一起使用 -
确实,我在
_config.yml和_posts文件夹所在的根文件夹中运行jekyll serve。Index.html也位于那里,并且似乎可以很好地编译到_site文件夹中。如果我用静态内容编辑index.html,它将被很好地构建。问题是由于某种原因没有访问变量。 -
文件名是:
YYYY-MM-DD-TITLE.md与2014-3-3-Hello-World.md不同
标签: jekyll github-pages