使用前题标题作为url永久链接

时间:2019-01-16 17:45:03

标签: jekyll yaml-front-matter

我该如何使用我的首页而不是文件名?

我在_config.yml中设置了一个收藏集

collections:
      news:
        output: true

我希望能够使用page.title作为我的网址,这是我的首要任务

---
layout: newspost
title:  "Fracture announces exclusive 3 year deal with Drake & Morgan."
date:   2019-01-16
---

当前url是.md文件的文件名,如下所示:

http://localhost:4000/news/drake_and_morgan.html

我希望url的输出如下:

http://localhost:4000/news/Fracture-announces-exclusive-3-year-deal with-Drake-&-Morgan.或类似的

2 个答案:

答案 0 :(得分:1)

您可以在前面的事物中定义slug

---
layout: newspost
title:  "Fracture announces exclusive 3 year deal with Drake & Morgan."
date:   2019-01-16
slug: "fracture-announces-exclusive-3-year-deal-with-drake-and-morgan"
---

并为新闻定义默认的permalink

collections:
  news:
    output: true
    permalink: "/:collection/:slug/"

OR

您可以在文件名上做更多工作,最后使用 fracture-announces-exclusive-3-year-deal-with-drake-and-morgan.md 文件名。 ;-)

答案 1 :(得分:0)

_config.yml

collections:
  news:
    output: true
    permalink: /news/:title