【问题标题】:Using front matter title as for url permalink使用前面的标题作为 url 永久链接
【发布时间】:2019-06-10 20:48:39
【问题描述】:

我怎样才能用我的前面的东西作为 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. 或类似的。

【问题讨论】:

    标签: jekyll yaml-front-matter


    【解决方案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/"
    

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

    【讨论】:

    • 谢谢,大卫这工作,从来没有真正弄清楚蛞蝓是如何工作的。谢谢你解释。但你是对的,我可以更改文件名。大声笑我想我已经学会了如何使用蛞蝓虽然我想我真的希望使用标题,并且 jekyll 一些如何替换空格 - 哈
    【解决方案2】:

    _config.yml

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-07
      • 1970-01-01
      • 2011-11-18
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 2010-10-07
      • 1970-01-01
      相关资源
      最近更新 更多