如何将AEM标记导出到Excel [英] How to export AEM tags into Excel

查看:98
本文介绍了如何将AEM标记导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Yesterday I had to export all AEM tags into Excel file. While surfing for the best solution to do this, I've found out that almost everyone advices writing custom code that takes all of tags and enters it into Excel file.

我认为该解决方案很好,但是由于有很多人第一次做这种事情,所以他们可能需要一些时间来弄清楚该怎么做。

I consider that solution good, but since there are a lot of people that do things like this for the first time and it will probably take some time for them to figure out how to do this.

对于他们,让我们分享一些解决此问题的方法。

For them, let's share some workarounds for this problem.

推荐答案

我建议使用命令行,内置 AEM查询生成器 curl jq https://stedolan.github.io/jq/ )。

To get a comma separated list of tags I would recommend using the command line, the build-in AEM query builder, curl and jq (https://stedolan.github.io/jq/).

常规方法:


  1. 使用查询生成器建立 / etc / tags

  2. 使用 curl 的JSON表示形式,下载 JSON

  3. 使用 jq 来解析 JSON并创建CSV

  1. Use query builder to build a JSON representation of /etc/tags
  2. Use curl to "download" the JSON
  3. Use jq to "parse" the JSON and create a CSV

示例:

导出 / etc /以下的所有标签标签及其路径,标题和描述如下:

Exporting all tags below /etc/tags with their path, title and description would look like this:

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

这将发送 GET 请求到本地AEM实例( http:// localhost:4502 ),以用户 admin 身份验证,密码为 admin (AEM的默认设置),使用查询生成器API( /bin/querybuilder.json )来获取所有资源在 / etc / tags 下面键入 cq:Tag ,在这些资源中,它将选择属性 jcr:path jcr:title jcr:description

This would send a GET request to your local AEM instance (http://localhost:4502), authenticate as user admin with password admin(default settings for AEM), use the query builder API (/bin/querybuilder.json) to get all resources with type cq:Tag below /etc/tags and of those resources it would "select" the properties jcr:path, jcr:title and jcr:description.

生成的JSON如下所示:

The resulting JSON looks like this:

{
  "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 ,它将使用查询 .hits [] | [。 jcr:path,。 jcr:title,。 jcr:description] 仅读取 hits 数组和该数组中的每个项目都只有 jcr:path jcr:title jcr:description 。然后将所得的数组用作 jq @csv 字符串格式化程序的输入,这将创建适当的逗号-

Next, the command above will pipe the resulting JSON from the query builder to jq, which will use the "query" .hits[] | [."jcr:path", ."jcr:title", ."jcr:description"] to read only the hits array and of every item in that array only jcr:path, jcr:title and jcr:description. The resulting arrays are then used as input for @csv "string formatter" of jq, which will create proper comma-separated output.

上面的JSON格式为:

The JSON from above would be formatted to:

"/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 的文件,而不是命令行。

The last part of the command > tags.csv will just redirect the output to a file called tags.csv instead of the command line.

AEM有一个查询生成器调试器,可用于创建查询,然后将其用于命令行命令:

AEM has a query builder debugger which you can use to create queries that you then can use in your command line command:

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

我在工具中使用的查询参数如下:

The query parameters I used above would look like this in the tool:

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

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

You can add properties as you like, but for them to show up in the CSV you also have to update the query used by jq.

如果将翻译添加到标签中,它们将被存储在名为 jcr:title。< language-code> 的属性中。例如,如果将标签翻译为德语,则将具有两个属性: jcr:title jcr:title.de 。如果要翻译,则必须扩展 p.properties 并添加 jcr:title.de 等。

If you add translations to your tags they will be stored in a property called jcr:title.<language-code>. If you translate your tags to German for example, you would have two properties: jcr:title and jcr:title.de. If you want the translation you have to extend the p.properties and add jcr:title.de etc.

这篇关于如何将AEM标记导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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