似乎无法让Jekyll看到根文件夹中子目录中的帖子 [英] Can't seem to get Jekyll to see posts that are in subdirectories from the root folder

查看:125
本文介绍了似乎无法让Jekyll看到根文件夹中子目录中的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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?

谢谢.

推荐答案

OP tom-mai78101 Hemanth.HM

已经证实了我的猜测,即子目录仅由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 the blog directory instead of the directory it is currently using.

(在您的情况下,blogprojects)

首先在本地创建目录,在其中设置Jekyll blog.
该目录将位于_posts_sitecss等侧面.
这只会保存非发布文件,例如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 as index.html.
The blog 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 our blog 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆