- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
昨天我必须将所有 AEM 标签导出到 Excel 文件中。在寻找最佳解决方案时,我发现几乎每个人都建议编写自定义代码,将所有标签输入到 Excel 文件中。
我认为这个解决方案很好,但由于有很多人第一次做这样的事情,他们可能需要一些时间才能弄清楚如何做到这一点。
让我们为他们分享一些解决此问题的方法。
最佳答案
要获取逗号分隔的标签列表,我建议使用命令行,内置 AEM query builder , curl
和jq
(https://stedolan.github.io/jq/)。
一般方法:
/etc/tags
的 JSON 表示形式curl
“下载”JSONjq
“解析”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
这将发送 GET
向您的本地 AEM 实例 ( http://localhost:4502
) 发出请求,以用户 admin
身份进行身份验证有密码admin
(AEM 的默认设置),使用查询生成器 API ( /bin/querybuilder.json
) 获取类型为 cq:Tag
的所有资源下面/etc/tags
在这些资源中,它将“选择”属性 jcr:path
, jcr:title
和jcr: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
,它将使用“查询”.hits[] | [."jcr:path", ."jcr:title", ."jcr:description"]
只读取hits
数组以及该数组中的每个项目的 jcr:path
, jcr:title
和jcr:description
。然后将生成的数组用作 @csv
的输入jq
的“字符串格式化程序” ,这将创建正确的逗号分隔输出。
上面的 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:title
和jcr:title.de
。如果你想要翻译,你必须扩展 p.properties
并添加jcr:title.de
等等
关于java - 如何将 AEM 标签导出到 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55529458/
我是一名优秀的程序员,十分优秀!