1

如何将我的前端内容用作 url 而不是文件名?

我在我的收藏夹中设置了一个集合_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.或类似的。

4

2 回答 2

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并为 news定义一个默认值:

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

或者

您可以在文件名上多做一些工作,最终得到一个fracture-announces-exclusive-3-year-deal-with-drake-and-morgan.md文件名。;-)

于 2019-01-16T19:39:53.313 回答
0

_config.yml

collections:
  news:
    output: true
    permalink: /news/:title
于 2019-01-16T19:33:36.190 回答