Skip to content

Commit 32a377b

Browse files
committed
🐛 修复非小写扩展名导致下载失败
1 parent a480997 commit 32a377b

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/main/java/com/pcdd/sonovel/convert/ChapterConverter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public class ChapterConverter {
2929
private final TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH));
3030

3131
public Chapter convert(Chapter chapter) {
32-
String extName = config.getExtName();
32+
String extName = config.getExtName().toLowerCase();
3333
String filteredContent = new ChapterFilter(config).filter(chapter);
3434
String content = new ChapterFormatter(config).format(filteredContent);
3535

36-
if ("txt".equalsIgnoreCase(extName)) {
36+
if ("txt".equals(extName)) {
3737
// 全角空格,用于首行缩进
3838
String ident = "\u3000".repeat(2);
3939
Matcher matcher = Pattern.compile("<p>(.*?)</p>").matcher(content);
@@ -47,7 +47,7 @@ public Chapter convert(Chapter chapter) {
4747

4848
content = chapter.getTitle() + "\n".repeat(2) + result;
4949
}
50-
if ("epub".equalsIgnoreCase(extName) || "html".equalsIgnoreCase(extName)) {
50+
if ("epub".equals(extName) || "html".equals(extName)) {
5151
chapter.setContent(content);
5252
content = templateRender(chapter, extName);
5353
}
@@ -60,7 +60,7 @@ public Chapter convert(Chapter chapter) {
6060
* 根据扩展名渲染对应模板
6161
*/
6262
private String templateRender(Chapter chapter, String extName) {
63-
// 符合 epub 标准的模板
63+
// epub 或 html 模板
6464
Template template = engine.getTemplate(StrUtil.format("chapter_{}.flt", extName));
6565
Map<String, String> map = new HashMap<>();
6666
map.put("title", chapter.getTitle());

src/main/java/com/pcdd/sonovel/handle/CrawlerPostHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public class CrawlerPostHandler {
2222

2323
@SneakyThrows
2424
public void handle(Book book, File saveDir) {
25-
String extName = config.getExtName();
25+
String extName = config.getExtName().toLowerCase();
2626
StringBuilder s = new StringBuilder(StrUtil.format("\n<== 《{}》({})下载完毕,", book.getBookName(), book.getAuthor()));
2727

2828
if (extName.matches("(?i)txt|epub")) {
2929
s.append("正在合并为 ").append(extName.toUpperCase());
3030
}
31-
if ("html".equalsIgnoreCase(extName)) {
31+
if ("html".equals(extName)) {
3232
s.append("正在生成 HTML 目录文件");
3333
}
3434
Console.log(s.append(" ..."));

src/main/resources/templates/chapter_html.flt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@
7878
})
7979
</script>
8080

81-
</html>
81+
</html>

0 commit comments

Comments
 (0)