fix(epub): ignores non-publication dates for published metadata (#2226)

This commit is contained in:
James Ward
2026-08-05 17:18:09 -04:00
committed by GitHub
parent be2ac14446
commit c077551926
2 changed files with 32 additions and 19 deletions
@@ -399,8 +399,15 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
}
}
case "date" -> {
String event = el.getAttributeNS(OPF_NS, "event");
// Epub3 publication date has no `event` specified.
// Epub2 publication date has an `event` of `publication`.
// This handles both to cover our bases.
boolean isPublishedDate = event.isBlank() || event.equalsIgnoreCase("publication");
LocalDate parsed = parseDate(text);
if (parsed != null) builderMeta.publishedDate(parsed);
if (parsed != null && isPublishedDate) {
builderMeta.publishedDate(parsed);
}
}
}
}
@@ -413,22 +420,6 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
else if ("subtitle".equals(type)) builderMeta.subtitle(value);
}
if (builderMeta.build().getPublishedDate() == null) {
for (int i = 0; i < children.getLength(); i++) {
if (!(children.item(i) instanceof Element el)) continue;
if (!"meta".equals(el.getLocalName())) continue;
String prop = el.getAttribute("property").trim().toLowerCase();
String content = el.hasAttribute("content") ? el.getAttribute("content").trim() : el.getTextContent().trim();
if ("dcterms:modified".equals(prop)) {
LocalDate parsed = parseDate(content);
if (parsed != null) {
builderMeta.publishedDate(parsed);
break;
}
}
}
}
for (Map.Entry<String, String> entry : creatorsById.entrySet()) {
String id = entry.getKey();
String value = entry.getValue();