punktde/archivist

一个Neos CMS包,可以自动将节点排序到动态创建的预定义结构中。

安装次数: 27,916

依赖项: 0

建议者: 0

安全性: 0

星标: 16

关注者: 8

分支: 9

公开问题: 2

类型:neos-package

2.8.3 2024-02-20 07:43 UTC

README

Travis Build Status Latest Stable Version Total Downloads

此包的用途:自动将节点排序到动态创建的预定义结构中。

Neos有一些缺点,如果你在同一个层级上存储了很多节点,比如新闻,那么后端树会变得缓慢且混乱。此包会自动将此类节点按配置和自动创建的层次结构排序。

配置

你可以为每个触发节点类型配置不同的行为。配置选项的最佳解释是通过示例。以下示例来自Configuration/Testing/Settings.yaml,因此它们会自动进行测试。

简单示例

对于节点类型 'PunktDe.Archivist.TriggerNode' 的配置。当创建此类型的节点或更改此节点的属性时,将触发排序。此节点将在配置的其他部分作为 'node' 可用

PunktDe: Archivist: 排序说明

  'PunktDe.Archivist.TriggerNode':

    # The query selecting the root node of the automatically created hierarchy
    hierarchyRoot: "${q(site).find('[instanceof Neos.ContentRepository.Testing:Page]').get(0)}"

    # Optional: The sorting of the nodes inside the target hierarchy. Can be the name of a property
    # or an eel expression like seen below
    sorting: title

    # Optional: Trigger sorting only, when condition is met. Can be used to make sure that required properties are set as expected.
    condition: "${node.properties.date != null}"

    # In the context is evaluated first. You can define variables here which you can use in
    # the remaining configuration
    context:
      publishDate: "${node.properties.date}"

    # Automatically publish the created document hierarchy
    publishHierarchy: true

    # Definition of the auto-generated hierarchy
    hierarchy:
      -
        # The type of the hierarchy-node
        type: 'PunktDe.Archivist.HierarchyNode'

        # Properties of the new created node.
        properties:
          name: "${Date.year(publishDate)}"
          title: "${Date.year(publishDate)}"
          hiddenInIndex: "${true}"

        # The property which is identical throughout all nodes of this level
        identity: title

        # An eel query that describes the sorting condition
        sorting: "${q(a).property('title') < q(b).property('title')}"
      -
        type: 'PunktDe.Archivist.HierarchyNode'
        properties:
          name: "${Date.month(publishDate)}"
          title: "${Date.month(publishDate)}"
        identity: title

        # Simple sorting on a property
        sorting: title

带有触发内容节点的示例

内容节点触发其父文档节点的移动。例如,如果你有一个标题节点,它应该被视为移动页面。

PunktDe:
  Archivist:
    sortingInstructions:
      'PunktDe.Archivist.TriggerContentNode':

        # The query selecting the root node of the automatically created hierarchy
        hierarchyRoot: "${q(site).find('[instanceof Neos.ContentRepository.Testing:Page]').get(0)}"

        # Optional: The node to be moved, described by an Eel query.
        # This defaults to the triggering node if not set. The triggering node is available as "node".
        # If the affected node is not found by the operation is skipped.
        # This can for example be used if a change in a content node should move its parent document node
        #
        affectedNode: "${q(node).parent('[instanceof Neos.ContentRepository.Testing:Document]').get(0)}"

        # Definition of the auto-generated hierarchy
        hierarchy:
          -
            # The type of the hierarchy-node
            type: 'PunktDe.Archivist.HierarchyNode'

            # Properties of the new created node.
            properties:
              name: "${Archivist.buildSortingCharacter(title)}"
              title: "${Archivist.buildSortingCharacter(title)}"

为相同的节点类型定义多个配置

除了

PunktDe:
  Archivist:
    sortingInstructions:
      MyNode.Type:
        hierarchyRoot: # ...

你现在可以这样做

PunktDe:
  Archivist:
    sortingInstructions:
      MyNode.Type:
        foo1:
          hierarchyRoot:  # ...
        foo2:
          hierarchyRoot:  # ...

确保定义一个条件以防止在同一个节点动作上运行多个配置。

Archivist Eel Helper

Archivist.buildSortingCharacter(string, position = 0, length = 1) 从给定的字符串生成大写排序字符。起始位置和长度可以定义。