如何将 AEM 标签导出到 Excel

How to export AEM tags into Excel

昨天我不得不将所有 AEM 标签 导出到 Excel 文件中。在寻找最佳解决方案时,我发现几乎每个人都建议编写自定义代码,将所有标签输入到 Excel 文件中。

我认为这个解决方案很好,但由于有很多人是第一次做这样的事情,他们可能需要一些时间才能弄清楚如何做。

为了他们,让我们分享一些解决这个问题的方法。

如果您需要导出标签,这里是关于如何轻松导出它们的简单解决方案,然后有几种方法可以在 Excel 中导入它,而无需为此编写自定义代码。

要导出 AEM 标签,请执行以下 5 个步骤:

  1. Open package manager
  2. Create package (give it some meaningful name)
  3. Edit created package
  4. Done, Save
  5. Build package
  6. Download Package

然后所有标签都在 {download_package_name}/jcr_root/etc/tags.

现在有几种 方法可以将下载的标签下载到Excel 文件中。这是在 Windows -

上执行此操作的方法

来源:有没有办法将文件夹结构导出到 excel?

Find the folder in Windows Explorer, then Shift Right click on that folder and select "Open Command Window Here". Type the following prompt:

dir /a /s /b > filelist.txt

That gives you a text file saved in your top folder, which you can open in notebook, then copy and paste into an Excel document.

要获得逗号分隔的标签列表,我建议使用命令行 build-in AEM query builder, curl and jq (https://stedolan.github.io/jq/).

一般做法:

  1. 使用查询生成器构建 /etc/tags
  2. 的 JSON 表示
  3. 使用curl到"download" JSON
  4. 使用 jq 到 "parse" JSON 并创建 CSV

示例:

导出 /etc/tags 下面的所有标签及其路径、标题和描述如下所示:

curl \
    --user admin:admin \
    --silent \
    "http://localhost:4502/bin/querybuilder.json?p.hits=selective&p.limit=-1&p.properties=jcr%3atitle%20jcr%3apath%20jcr%3adescription&path=%2fetc%2ftags&type=cq%3aTag" \
    | jq --raw-output '.hits[] | [."jcr:path", ."jcr:title", ."jcr:description"] | @csv' \
    > tags.csv

这将向您的本地 AEM 实例 (http://localhost:4502) 发送 GET 请求,以用户 admin 身份验证,密码 admin(AEM 的默认设置),使用查询生成器 API (/bin/querybuilder.json) 获取类型 cq:Tag 低于 /etc/tags 的所有资源,并且在这些资源中它将 "select" 属性 jcr:pathjcr:titlejcr:description.

结果 JSON 如下所示:

{
  "success": true,
  "results": 2,
  "total": 2,
  "more": false,
  "offset": 0,
  "hits": [
    {
      "jcr:path": "/etc/tags/experience-fragments",
      "jcr:description": "Tag structured used by the Experience Fragments feature",
      "jcr:title": "Experience Fragments"
    },
    {
      "jcr:path": "/etc/tags/experience-fragments/variation",
      "jcr:description": "A tag used by the experience fragments variations",
      "jcr:title": "Variation"
    },
  ]
}

接下来,上面的命令会将生成的 JSON 从查询生成器通过管道传输到 jq,这将使用 "query" .hits[] | [."jcr:path", ."jcr:title", ."jcr:description"] 来只读取 hits 数组和该数组中的每个项目仅 jcr:pathjcr:titlejcr:description。然后将生成的数组用作 @csv "string formatter" 或 jq 的输入,这将创建适当的 comma-separated 输出。

上面的 JSON 将被格式化为:

"/etc/tags/experience-fragments","Experience Fragments","Tag structured used by the Experience Fragments feature"
"/etc/tags/experience-fragments/variation","Variation","A tag used by the experience fragments variations"

命令 > tags.csv 的最后一部分只会将输出重定向到名为 tags.csv 的文件,而不是命令行。

AEM 有一个查询生成器调试器,您可以使用它来创建查询,然后您可以在命令行命令中使用这些查询:

http://localhost:4502/libs/cq/search/content/querydebug.html

我上面使用的查询参数在工具中看起来像这样:

path=/etc/tags
type=cq:Tag
p.hits=selective
p.limit=-1
p.properties=jcr:title jcr:path jcr:description

您可以根据需要添加属性,但要让它们显示在 CSV 中,您还必须更新 jq 使用的查询。

如果您向标签添加翻译,它们将存储在名为 jcr:title.<language-code> 的 属性 中。例如,如果将标签翻译成德语,您将拥有两个属性:jcr:titlejcr:title.de。如果你想要翻译,你必须扩展 p.properties 并添加 jcr:title.de

A​​EM 中有一个 GUI 可以将内容导出为 excel [好吧几乎]。要在系统中获取标签的 tsv 文件,可以使用 AEM 的批量编辑器。导航到服务器上的“/etc/importers/bulkeditor.html”。将路径设置为“/etc/tags”或子树。在查询字段中键入 'type:Tag'。 Select需要导出的属性,点击搜索。然后可以通过导出按钮将结果导出到 tsv 文件。

参考资料

我无权对已接受的答案发表评论,但认为添加到优秀的已接受答案中会很有用:如果您使用的是 >= 6.4,那么您可能需要更改您的路径查询 /content/cq:tags (1) 或查询两个路径,如果您的安装已随时间升级并且您有长期存在的标签。尽管我在查看 http://localhost:4502/tagging

时可以看到数百次,但我的点击率却为 0

(1) https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/tagging-issue-in-aem-6-4/qaq-p/320994

希望这个非答案不会被过度反对。