Wagtail MultiSite - 交叉发布内容 [英] Wagtail MultiSite - Cross posting content

查看:24
本文介绍了Wagtail MultiSite - 交叉发布内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在通过单个 Wagtail 安装构建两个站点.这些网站是为一家公司和它的姊妹公司准备的,内容有一些重叠.理想情况下,我们不想两次发布相同的内容.特别是我们在两个网站上都有一个活动页面,可能有与两家公司相关的活动.

I am currently building two sites out of a single Wagtail installation. The sites are for a company and it's sister company and there is some overlap in content. Ideally we don't want to have to post the same content twice. In particular we have an Events page on both sites and there may be events that are relevant to both companies.

问题是 Wagtail 页面一次只能存在于树中的一个位置.我已经考虑过创建一个MirroredEventPage"模型,其中只有一个原始 EventPage 模型的外键字段,尽管这种方法在编写 EventIndex 页面和重用模板时存在问题.

The problem is that a Wagtail page can only exist in one place in the tree at once. I have considered creating a "MirroredEventPage" model with only one foreign key field to the original EventPage model, although this approach has it's problems when it comes to writing the EventIndex page and reusing templates.

我也考虑过将 Events 创建为 vanilla Django 模型,这也不理想.

I've also considered creating Events as a vanilla Django model which isn't ideal either.

有没有人遇到过类似的问题并找到了好的解决方案?

Has anyone had a similar issue and found a good solution?

推荐答案

一个想法是在事件索引页面上混合使用 Wagtail Snippets 和 RoutablePageMixin.

An idea would be to use a mix of using Wagtail Snippets and the RoutablePageMixin on your Events Index Pages.

1.制作事件片段

将活动页面的共享内容制作成 Wagtail 片段.您将无法访问更改的版本,但可以获得跨站点共享的能力.

Make the shared content of your Events page into a Wagtail Snippet. You will loose the ability to access versions of changes but gain the ability to share across sites.

http://docs.wagtail.io/en/v1.13/topics/snippets.html

2.更新您的事件索引页面模型以使用 RoutablePageMixin

http://docs.wagtail.io/en/v1.13/reference/contrib/routablepage.html

然后,如果任何事件索引页面具有类似于 mydomain.com/events/123-event-name-as-slug 的内容,您就可以挂钩这些页面的 URL 调用.这可以加载自定义模板(可以共享或不共享,具体取决于站点),以及通过上下文发送的事件索引和事件片段.

You can then hook into the URL calls for any of the Events Index pages if they have something like mydomain.com/events/123-event-name-as-slug. This can load a custom template (which can be shared or not, depending on the site), with the events index and the event snippet sent via the context.

这些 URL 将是它们自己的唯一 URL,但实际上它们后面没有页面.请记住考虑您的 SEO 影响,确保管理员编辑人员可以管理代码段中的元描述等内容(或研究如何自动传播).

These URLs will be their own unique URL but not actually have a page behind them. Remember to consider your SEO implications, ensure that the admin editors can manage things like meta description on the snippet (or work through how that will propagate automatically).

您还可以连接到 Wagtail 按钮(称为 Wagtail Userbar),以便当编辑者单击前端 Wagtail 按钮并单击编辑事件"时,它可以直接将他们带到管理中的 Snippet 编辑页面.

You can also hook into the Wagtail button (called Wagtail Userbar) so that when editors click the front end Wagtail button and click 'edit Event' it can take them directly to the Snippet editing page in admin.

http://docs.wagtail.io/en/v1.13/reference/hooks.html#construct-wagtail-userbar

3.更新事件索引列表

如果您不希望在两个站点上都有一些事件,您可以为您运营的两个站点添加复选框(默认情况下都打勾).这意味着事件索引"页面将仅显示与该站点相关的事件.

If there are some events you do not want on both sites, you could add checkboxes (both ticked by default) for the two sites you operate. This means the Events Index page will only show the events relevant to that site.

您可以通过覆盖页面模型上的 serve 方法来做到这一点.

You can do this by overriding the serve method on the page model.

注意:在此示例中,您没有将每个事件明确链接到每个站点的事件索引页面.您只需加载相关事件的查询并将其传递给事件索引模板.

Note: In this example you are not explicitly linking each and every event to each site's event index page. You are simply loading a query of relevant events and passing it to the events index template.

4.更复杂的集成

如果您真的希望每个站点下的每个事件"都有一个单独的页面,您可以在 Snippet create/edit/delete 上创建自定义信号.

If you really want an individual page for each 'Event' under each site, you could create a custom signal on Snippet create/edit/delete.

Wagtail 信号介绍:http://docs.wagtail.io/en/v1.13/参考/signals.html

Intro to Wagtail Signals: http://docs.wagtail.io/en/v1.13/reference/signals.html

您希望确保这些字段在页面编辑时不可编辑,但可以在片段下编辑.然后,您只需将事情与您的信号保持同步,虽然有点乱,但会在 Admin 中为您提供一个实际的页面".

You would want to ensure that the fields are non-editable on the Page edit, but would be editable under snippets. Then you just keep things in sync with your signals, bit messy but gives you an actual 'Page' in the Admin.

这篇关于Wagtail MultiSite - 交叉发布内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆