简体   繁体   English

Keystone 6 中的内容版本控制

[英]Content versioning in Keystone 6

In a previous project in Keystone 4, I was able to work with content versioning.在之前的 Keystone 4 项目中,我能够使用内容版本控制。 That is, if I were to update a content entity (eg BlogPost), I would have the possibility to toggle between the previous version of the blog post, and the current one.也就是说,如果我要更新内容实体(例如 BlogPost),我将有可能在博文的前一版本和当前版本之间切换。

I can't see any options for this in the documentation for Keystone 6, and I also find it hard to find any resources on this subject online.我在 Keystone 6 的文档中看不到这方面的任何选项,而且我也发现很难在网上找到关于这个主题的任何资源。 Does someone have any insight in this?有人对此有任何见解吗? If it's not possible out-of-the-box - do you have any advice on how to accomplish it manually?如果不可能开箱即用 - 您对如何手动完成它有什么建议吗?

Thanks in advance提前致谢

Content versioning is something the Keystone team has discussed a lot internally but it's quite a complicated area.内容版本控制是 Keystone 团队在内部讨论过很多的东西,但这是一个相当复杂的领域。 There are just so many different ways to approach the problem, even when versioning within a single item.有很多不同的方法来解决这个问题,即使是在单个项目中进行版本控制时也是如此。 If you bring relationships in to it and versioning across multiple items the problem space grows quickly.如果您将关系引入其中并跨多个项目进行版本控制,问题空间会迅速扩大。

If a first party solution did get built it would probably be built "on top of" Keystone – similar to the @keystone-6/auth package – that is, a separate, configurable package that uses the documented Keystone APIs to add functionality.如果确实构建了第一方解决方案,它可能会构建在 Keystone“之上”——类似于@keystone-6/auth package——即,一个单独的、可配置的 package,它使用记录的 Keystone API 来添加功能。 Regardless, as it stands right now, versioning and publishing workflows are something you'll need to design and build out yourself.无论如何,就目前而言,版本控制和发布工作流程是您需要自己设计和构建的。

My advice would be to first get clear on exactly what you need to version and what you don't.我的建议是首先明确您需要版本化的内容和不需要的版本。 Somethings to consider:需要考虑的事项:

  • Do you need to version the whole item or maybe just a few fields?您需要对整个项目进行版本控制还是只需要对几个字段进行版本控制?
  • Do you need a history of changes or is it enough to have a "published" version and an optional "draft" version that's editable?您是否需要更改历史记录,或者拥有一个“已发布”版本和一个可选的可编辑“草稿”版本就足够了吗?
  • Will you need to "revert" changes, or is an "update only" model sufficient?您需要“还原”更改,还是“仅更新”model 就足够了?
  • Do you care about related items?你关心相关项目吗? (Eg. say your blog posts are related to a list of Tags , does editing the tags constitute a new "version" of the post or is that "outside" of the versioned part?) (例如,假设您的博客帖子与Tags列表相关,编辑标签是否构成帖子的新“版本”,或者是版本化部分的“外部”?)
  • What about collaboration;合作呢? will multiple people be trying to edit a single post/draft at the same time?会有多人同时尝试编辑一篇文章/草稿吗?
  • Can you have multiple draft version or just one?你可以有多个草稿版本还是只有一个?
  • Do you you need to consider previewing changes or (worse) sets of changes?您是否需要考虑预览更改或(更糟糕的)更改集?
  • Do you require some kind of integrated approval workflow or can anyone creating content publish/revert it?您是否需要某种集成的批准工作流程,或者任何创建内容的人都可以发布/恢复它吗?

Some basic approaches that spring to mind: spring 记住的一些基本方法:

Draft/Published Fields草稿/发布字段

For something relatively simple like aa blog post you maybe able to get away with a draft/published workflow implemented within the item, at the field level.对于诸如博客文章之类的相对简单的内容,您也许能够在字段级别的项目中实施草稿/发布工作流。 Something like this:是这样的:

  Post: list({
    fields: {
      slug: text({ validation: { isRequired: true }, isIndexed: 'unique' }),
      publishedTitle: text({ validation: { isRequired: true } }),
      publishedBody: document({ /* ... */ }),
      draftTitle: text({ validation: { isRequired: true } }),
      draftBody: document({ /* ... */ }),
    },
    // access, hooks, etc.
  }),

Your frontend displays only the published... field but you restrict the backend to only allow the draft... fields to be edited (you could even hide the published fields from the Admin UI).您的前端仅显示已published...字段,但您将后端限制为仅允许编辑draft...字段(您甚至可以从管理 UI 隐藏已发布的字段)。 A hook or custom mutation can be added to "promote" the draft content to published by copying it between fields.可以添加挂钩或自定义突变以通过在字段之间复制来“促进”草稿内容发布。 With the right access control, you could even setup the frontend to preview the draft content institchu with a magic URL param or something.通过正确的访问控制,您甚至可以设置前端以使用神奇的 URL 参数或其他东西预览草稿内容。

It's pretty basic, but easy to setup and use.它非常基本,但易于设置和使用。

Item Per Version每个版本的项目

A more powerful alternative would be to represent versions with separate items and use a field to track which version is the currently published content:一个更强大的替代方案是用单独的项目表示版本,并使用一个字段来跟踪哪个版本是当前发布的内容:

  Post: list({
    fields: {
      slug: text({ validation: { isRequired: true }, isIndexed: true }),
      title: text({ validation: { isRequired: true } }),
      body: document({ /* ... */ }),
      isPublished: checkbox(),
    },
    // access, hooks, etc.
  }),

In this scenario the slug field isn't unique in the list – each post can have multiple items, representing either upcoming drafts or historical versions.在这种情况下, slug字段在列表中不是唯一的——每个帖子可以有多个项目,代表即将到来的草稿或历史版本。 When a version of a post is published (by setting isPublished to true), a hook ensures any items with the same slug have the isPublished flag set to false.发布帖子的一个版本时(通过将isPublished设置为 true),挂钩确保具有相同 slug 的任何项目都将isPublished标志设置为 false。 The front end simply filters by isPublished to get the current version (enforced by access control if needed).前端简单地通过isPublished过滤以获取当前版本(如果需要,通过访问控制强制执行)。 This lets you both publish updates and roll back to any previous version.这使您既可以发布更新又可以回滚到任何以前的版本。 It also solves for relationships to some extent – eg.它还在某种程度上解决了关系——例如。 if you have a related list of Tags , linked many-to-many with Posts , updates to the post's tags are versioned along with the content.如果您有一个相关的Tags列表,与Posts多对多链接,则对帖子标签的更新与内容一起进行版本控制。

To smooth the workflow out, it would probably be useful to have a custom mutation that duplicated an existing post, allowing you to make changes to existing content with ease.为了使工作流程顺畅,拥有一个复制现有帖子的自定义突变可能会很有用,这样您就可以轻松地对现有内容进行更改。 And maybe a custom Admin UI page to help visualising a posts history and managing revert actions, etc.也许还有一个自定义的管理 UI 页面,以帮助可视化帖子历史记录和管理恢复操作等。


These are just two examples but there would be dozens of other ways to approach the problem.这些只是两个例子,但还有许多其他方法可以解决这个问题。 Just be clear on your requirements then do the simplest thing that works: :)只要清楚你的要求,然后做最简单的事情::)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM