Skip to content

Commit

Permalink
fix: replace author tag with dc:creator to specify the author
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Dec 16, 2024
1 parent 3db0428 commit 413d2e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/src/main/java/run/halo/feed/RssXmlBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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())) {
Expand Down
8 changes: 5 additions & 3 deletions app/src/test/java/run/halo/feed/RSS2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void toXmlString() {
// language=xml
var expected = """
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<rss xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>title</title>
<link>link</link>
Expand Down Expand Up @@ -109,7 +110,7 @@ void extractRssTagsTest() {
// language=xml
var expected = """
<?xml version="1.0" encoding="UTF-8"?>
<rss
<rss xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>title</title>
Expand Down Expand Up @@ -161,7 +162,8 @@ void invalidCharTest() {
// language=xml
var expected = """
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<rss xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>title</title>
<link>link</link>
Expand Down

0 comments on commit 413d2e1

Please sign in to comment.