似乎无法让Jekyll看到根文件夹中子目录中的帖子 [英] Can't seem to get Jekyll to see posts that are in subdirectories from the root folder
问题描述
我在Jekyll网站上使用了GitHub Pages的集合.我试图让Jekyll看到集合文件夹_projects
中的Markdown文件.
I have used collections in my Jekyll website for GitHub Pages. I'm trying to get Jekyll to see the Markdown files inside the collection folder, _projects
.
以下是文件结构的摘要:
Here's a rundown of the file structure:
root
│
├─ _projects
│ │
│ ├─ project_1.md
│ └─ project_2.md
│
└─ /*Rest of the Jekyll folders and files, _posts, _includes, etc.*/
此刻,我意识到您必须将Markdown文件放在根目录中,因此,当您单击通过永久链接指向它们的链接后,Jekyll可以查看和解析文件以显示它们.但是,经过一段时间的测试,如果文件不在根文件夹中,它就无法看到" Markdown文件.
At the moment, I realized that you must put the Markdown files in the root, so Jekyll can be able to see and parse the files to display them when after you clicked a link that points to them via permalinks. But it cannot "see" the Markdown files if the files are not in the root folder, after testing quite a while.
有没有办法让Jekyll看到并解析子文件夹_projects
中的文件,就像它可以看到根文件夹中的文件一样?我猜我可能需要在_config.yml
中进行设置吗?
Is there a way to let Jekyll see and parse files inside the subfolder, _projects
, just like how it can see files in the root folder? Maybe I need to set something up in the _config.yml
, I guess?
谢谢.
推荐答案
已经证实了我的猜测,即子目录仅由Markdown文件中的固定链接定义,而不是通过存储库中的文件夹定义.
我很快编写了一个代码段,并创建了此处显示的一些Markdown文件,现在我可以了使用嵌套在_posts
文件夹中的Markdown文件创建网页.
简而言之,无需使用_config.yml
中的集合,而只需使用默认的_posts
.
如果有一种方法可以更改_config.yml
中的默认永久链接设置,那就更好了.
has confirmed my guesses that subdirectories are only defined by the permalinks in the Markdown files, and not through the folders within the repository.
I quickly wrote a code snippet, and created a few Markdown files shown here, I am now able to create webpages using Markdown files nested within the_posts
folder.
In short, there's no need to use collections in the_config.yml
, and just use the default_posts
.
It would've been better if there is a way to change the default permalink setup in the_config.yml
.
问题" Jekyll无法在子文件夹中生成页面"可能是相关的,以便使某些页面在子文件夹.
The question "Jekyll not generating pages in subfolders" could be relevant, in order to make some pages being generated in a subfolder.
或者您可以使用其他基本网址. (Jekyll 1.0 +)
Or you could use a different baseurl. (Jekyll 1.0+)
或使用_include
文件夹(请参阅" Jekyll分页blog
作为子目录")
Or use the _include
folder (see "Jekyll paginate blog
as subdirectory")
或者,文章" Josh Branchaud )似乎可以解决您的情况:
Or, The article "Running Your Jekyll Blog from a Subdirectory" (from Josh Branchaud) seems to address your situation:
在公共html目录(即您的域指向的目录)中创建一个名为
blog
的目录. 假设您使用某种部署方案( GitHub页面或
Create a directory called
blog
in your public html directory (that is, in the directory that your domain points to). Assuming you are using some sort of deployment scheme (GitHub pages or deployment methods), you need to have that deployment scheme tell Jekyll to deploy to theblog
directory instead of the directory it is currently using.
(在您的情况下,blog
为projects
)
首先在本地创建目录,在其中设置Jekyll
blog
.
该目录将位于_posts
,_site
,css
等侧面.
这只会保存非发布文件,例如index.html
.
blog
帖子仍将保留在_posts目录中.
Start by creating a directory locally where you have your Jekyll
blog
setup.
This directory will sit along side_posts
,_site
,css
, etc.
This is only going to hold non-post files such asindex.html
.
Theblog
posts will still go in the _posts directory.
接下来,我们将告诉Jekyll,我们希望它接收博客文章,并在生成博客文章时将其放置在名为blog的目录中.
这可以通过将永久链接设置添加到_config.yml
文件来完成.
在文件顶部添加如下一行:
Next, we are going to tell Jekyll that we want it to take our blog posts and put them inside a directory called blog when it generates them.
This can be done by adding a permalink setting to the _config.yml
file.
Add a line like this to the top of the file:
permalink: /blog/:categories/:year/:month/:day/:title.html.
默认值(您可能一直在使用)将
posts
放在目录结构中,该目录结构以类别开头,然后是日期,最后是博客文章的标题作为html文件的名称. > 指出的是
The default (which you have probably been using) puts
posts
in a directory structure starting with the category, followed by the date, and finally with the title of the blog post as the name of the html file.
Which, spelled out would be
/:categories/:year/:month/:day/:title.html.
这看起来很熟悉吗?当然可以.这是我们上面使用的,没有
/blog
部分.
我们实质上是在模仿默认目录结构,并在开头添加blog
目录.
Does that look familiar? Sure does. It is what we have used above, sans the
/blog
part.
We are essentially emulating the default directory structure and while adding ourblog
directory at the beginning.
最后,您将要向创建的blog
目录中添加index.html
文件.
这样,当某人访问mydomain.com/blog/
时,他们可以看到您必须提供的blog
帖子.
该索引页面将或多或少地完全反映您最初为列出您的blog
帖子而设置的设置.
Lastly, you are going to want to add an index.html
file to the blog
directory that you created.
This way, when a person goes to mydomain.com/blog/
they can see what blog
posts you have to offer.
This index page is going to more or less mirror exactly what you had setup originally for listing your blog
posts.
这篇关于似乎无法让Jekyll看到根文件夹中子目录中的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!