Rename a page during jekyll build

时间:2018-02-03 08:58:06

标签: jekyll

I would like to rename a file denoted as someFancyPage.md to index.md during jekyll build. However, the file needs to remain in the same directory.

So far I tried permalink, which however seems to be always interpreting the value as absolute.

I would like to use this behavior, as I created a plugin, which executes on folders containing someFancyPage.md and does some magic.

2 个答案:

答案 0 :(得分:0)

如果您想使用 pure jekyll执行此操作,则必须使用permalink并在每个页面中将其设置为具有相同名称的路径文件夹。这将导致生成的页面为index.html

例如,假设您有这样的结构:

/404.html
/index.html
/folder-01/someFancyPage.md
/folder-02/someFancyPage.md

在前面的内容中,您声明permalink是文件夹的完整路径,没有文件名。例如:

  

/folder-01/someFancyPage.md

---
layout: page
title: Folder 01
permalink: /folder-01/
---

This is folder 01
  

/folder-02/someFancyPage.md

---
layout: page
title: Folder 02
permalink: /folder-02/
---

This is folder 02

这将按照您要查找的方式重命名这些页面。

注意:由于您要覆盖永久链接,因此文件系统中物理文件夹的名称无关紧要。如果您有/dennis/someFancyPage.md但覆盖/folder-01/的固定链接,那么jekyll将尊重该内容并创建/folder-01/index.html

答案 1 :(得分:0)

我采用的解决方案(它不是很好)使用前面的信息,而文件名仍为index.md

---
layout: picture-gallery
---

在我的插件中,我现在搜索具有此布局的页面。 添加自定义前端问题(在我的情况下,使用layout)。

    def generate(site)
        paginator_directories = Array.new
        pages do |sf|
            #next unless sf.respond_to?(:layout)
            #This is a workaround to check if "layout: picture-gallery" is set.
            next unless File.readlines(sf.path).grep(/picture\-gallery/).size > 0

            paginator_directories.insert(-1, File.dirname(sf.path))
        end

        #Do some really fancy magic here.
   end