Jekyll不读书site.posts
最近,我决定在Github Pages上启动我的博客。我分叉Jekyll现在并将代码拉入我的本地环境。Jekyll不读书site.posts
现在我正在运行jekyll serve
,但它不读取_posts文件夹中的帖子!
看来site.posts
变量index.html
无法读取。如果我输出变量或检查它:{{ site.posts | inspect }}
然后它是空的。
的职位名称中的正确格式YYYY-MM-DD-TITLE.md 如果我跑jekyll serve
的_posts
文件夹内,然后我会得到一个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
更新答:
检查你的文章是在YYYY-MM-DD-title.MARKUP,即2017- 1-title.md样式,填充为0。
在哲基尔的文档页面上"Writing Posts"“创建张贴档案”:
要创建一个新的职位,所有你需要做的是建立在_posts目录中的文件。如何命名文件夹中的文件非常重要。杰奇需要博客文章的文件按照以下格式命名:
YEAR-MONTH-DAY-title.MARKUP
其中year是一个四位数字,月和日都是两位数字,和标记是代表的文件扩展名格式在文件中使用。例如,以下是有效的文件名后的例子:
2011-12-31-new-years-eve-is-awesome.md
2012-09-12-how-to-write-a-blog.md
前答:
是您的_posts文件夹位于您的网站的根目录?
另外我的主要建议是创建一个专门用于显示索引的布局(在布局文件夹中)(因此制作一个普通的网页并复制并粘贴index.md文件的当前非主体内容)。我的理解是,如果它不是Liquid或Markdown,那么您的代码将按原样显示,而不是用于构建网站的读取/处理。即使你的index.md页面有一个完全空白的底部,但据我的理解,它应该显示你的帖子。
谢谢你的回答。的确,'_posts'文件夹位于根目录。我会尝试按照你的建议创建一个布局。 – mtleis
'_layouts'中有一个'default.html'文件。如果我编辑它,静态更改将显示。所以我想问题是变量不被读取。 – mtleis
你可以分享default.html文件吗?我描述的方法是我如何做自己的布局,所以虽然我认为能够通过markdown文件插入它(如您所做的那样)会更好,但这是我所做的妥协。所以我很好奇你的文件可能会发生什么。 – jncmaguire
发布您位于'_posts'文件夹中的帖子及其文件名。还有'_config.yml'。 – marcanuy
感谢@marcanuy为您的评论和编辑我的问题中的标记。我只是编辑帖子,希望它更清楚 – mtleis
似乎没问题,它应该在根文件夹(即包含'_config.yml'的文件夹)上运行'jekyll serve' – marcanuy