From 04a39c9ecd8fa6c912236a5ffa296ceac76b21f1 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:48:18 +0800 Subject: [PATCH] fix: replace author tag with dc:creator to specify the author (#48) --- app/src/main/java/run/halo/feed/RssXmlBuilder.java | 5 ++++- app/src/test/java/run/halo/feed/RSS2Test.java | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/run/halo/feed/RssXmlBuilder.java b/app/src/main/java/run/halo/feed/RssXmlBuilder.java index f555634..5305b5e 100644 --- a/app/src/main/java/run/halo/feed/RssXmlBuilder.java +++ b/app/src/main/java/run/halo/feed/RssXmlBuilder.java @@ -64,6 +64,7 @@ public String toXmlString() { Element root = DocumentHelper.createElement("rss"); root.addAttribute("version", "2.0"); + root.addNamespace("dc", "http://purl.org/dc/elements/1.1/"); root.addNamespace("media", "http://search.yahoo.com/mrss/"); document.setRootElement(root); @@ -167,7 +168,9 @@ private void createItemElementToChannel(Element channel, RSS2.Item item) { .addText(item.getGuid()); if (StringUtils.isNotBlank(item.getAuthor())) { - itemElement.addElement("author").addText(item.getAuthor()); + // https://www.rssboard.org/rss-validator/docs/error/InvalidContact.html + itemElement.addElement("dc:creator") + .addText(item.getAuthor()); } if (StringUtils.isNotBlank(item.getEnclosureUrl())) { diff --git a/app/src/test/java/run/halo/feed/RSS2Test.java b/app/src/test/java/run/halo/feed/RSS2Test.java index 34271d5..80cb37d 100644 --- a/app/src/test/java/run/halo/feed/RSS2Test.java +++ b/app/src/test/java/run/halo/feed/RSS2Test.java @@ -45,7 +45,8 @@ void toXmlString() { // language=xml var expected = """ - + title link @@ -109,7 +110,7 @@ void extractRssTagsTest() { // language=xml var expected = """ - title @@ -161,7 +162,8 @@ void invalidCharTest() { // language=xml var expected = """ - + title link