首页 > 解决方案 > 使用前面的标题作为 url 永久链接

问题描述

如何将我的前端内容用作 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.或类似的。

标签: jekyllyaml-front-matter

解决方案


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文件名。;-)


推荐阅读