halo icon indicating copy to clipboard operation
halo copied to clipboard

评论数据没有适配#annotations.get()

Open chengzhongxue opened this issue 10 months ago • 10 comments

系统信息

2.15.0-rc.1

使用的哪种方式运行?

Docker

发生了什么?

${#annotations.get(comment.spec.owner, 'email-hash')} 获取不到元数据

相关日志输出

No response

附加信息

No response

chengzhongxue avatar Apr 27 '24 10:04 chengzhongxue

um,没懂你这个使用方式,${#annotations.get()} 的第一个参数可以传 comment,但是你传的 comment.spec.owner 你可以试试 ${#annotations.get(comment, 'email-hash')},参考文档 theme annotations

guqing avatar Apr 28 '24 03:04 guqing

/kind support

guqing avatar Apr 28 '24 03:04 guqing

um,没懂你这个使用方式,${#annotations.get()} 的第一个参数可以传 comment,但是你传的 comment.spec.owner 你可以试试 ${#annotations.get(comment, 'email-hash')},参考文档 theme annotations

那我就是搞错了,这个好像没有支持元数据获取

chengzhongxue avatar Apr 28 '24 03:04 chengzhongxue

那我就是搞错了,这个好像没有支持元数据获取

不是所有叫 annotations 的字段都可以使用 ${annotations.get} 表达式,它只能获取 metadata.annotations 的值,你可以试试 <p th:text="${comment.spec.owner.annotations['email-hash']}"></p>

guqing avatar Apr 28 '24 03:04 guqing

那我就是搞错了,这个好像没有支持元数据获取

不是所有叫 annotations 的字段都可以使用 ${annotations.get} 表达式,它只能获取 metadata.annotations 的值,你可以试试 <p th:text="${comment.spec.owner.annotations['email-hash']}"></p>

那我试试

chengzhongxue avatar Apr 28 '24 04:04 chengzhongxue

可以了

chengzhongxue avatar Apr 28 '24 04:04 chengzhongxue

那我就是搞错了,这个好像没有支持元数据获取

不是所有叫 annotations 的字段都可以使用 ${annotations.get} 表达式,它只能获取 metadata.annotations 的值,你可以试试 <p th:text="${comment.spec.owner.annotations['email-hash']}"></p>

这样虽然可以获取到数据,但仍然可能出现问题,如果 annotations 中没有 email-hash 字段将会导致模板渲染异常,而且在模板中也不是很好判断属性是否存在。

ruibaby avatar Apr 28 '24 05:04 ruibaby

这样虽然可以获取到数据,但仍然可能出现问题,如果 annotations 中没有 email-hash 字段将会导致模板渲染异常,而且在模板中也不是很好判断属性是否存在。

https://github.com/halo-dev/halo/blob/d86ddf4a048cbac30cdc7faffc235e5c337f5034/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java#L173-L174

目前出现这种现象的条件只有 StringUtils.isNotBlank(owner.getEmail()) == false

而anonymous或user的comment/reply都会携带邮箱字段,所以除非有脏数据,否则 email-hash 都应该是存在的

ShiinaKin avatar Apr 28 '24 06:04 ShiinaKin

目前邮箱是必填的,应该没有这种情况

guqing avatar Apr 28 '24 06:04 guqing

metadata.creationTimestamp 也是不可能出现为空的,但以前还是出现过。

ruibaby avatar Apr 28 '24 06:04 ruibaby

metadata.creationTimestamp 也是不可能出现为空的,但以前还是出现过。

如果有用户反馈出现为空的情况,可以通过提前判断 comment.spec.owner.annotations 是否存在再取值,目前这里的 annotations 使用并不频繁(需要多次或在多处从里面取值),因此我认为可以不考虑这个问题

guqing avatar May 09 '24 04:05 guqing