用Prismic建立类别?

时间:2019-09-17 06:44:56

标签: graphql gatsby prismic.io

我有一个现有的Gatsby / Prismic博客。我现在正尝试使用类别来组织我的内容。有谁知道一个好的教程?实际上,我已经找到了1个文档,但实际上并没有帮助。有谁知道使用盖茨比和Prismic创建和显示类别的步骤?

1 个答案:

答案 0 :(得分:1)

  1. 在“ Prismic”中添加一个名为“ category”的“可重复类型”的新“ Content Type”。

  2. 要构建类别结构,可以使用右侧的“构建模式”或“ JSON编辑器”。如果选择“ JSON编辑器” 粘贴。

{
  "Main" : {
    "name" : {
      "type" : "Text",
      "config" : {
        "label" : "name",
        "placeholder" : "Name of the category"
      }
    }
  }
}

...然后保存。

  1. 现在像添加新博客文章一样添加新类别。单击新内容,然后单击“类别”,然后输入一个类别名称,例如:events,然后按“保存”和“发布”。
  2. 现在编辑您的博客文章内容库。如果单击JSON编辑器,则添加到Meta

{
  "Main" : {
 //Here is your code for the blog post add the Meta below
  "Meta" : {
    "categories" : {
      "type" : "Group",
      "config" : {
        "fields" : {
          "category" : {
            "type" : "Link",
            "config" : {
              "select" : "document",
              "customtypes" : [ "category" ],
              "label" : "category",
              "placeholder" : "Category"
            }
          }
        },
        "label" : "Categories"
      }
    }
  }
}

  1. 单击您也想添加类别的旧博客帖子。现在,在Main旁边应该有一个Meta标签。当您单击它时,您将看到有一个类别字段,当您单击该列表时会列出您创建的类别字段。选择一个。

  2. 现在,您可以按类别过滤博客文章。如何执行此操作取决于您自己,也许是查询以获取您放入下拉菜单中的所有类别名称? 盖茨比入门https://github.com/LekoArts/gatsby-starter-prismic-i18n

  3. 是一个很好的例子