Skip to content

Commit 2bcd518

Browse files
committed
fix: image not displayed in book summary page, html contains error when handing <> with jpStyle, and more
1 parent d5dde9d commit 2bcd518

3 files changed

Lines changed: 50 additions & 28 deletions

File tree

2epub.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type SpecialTag = {
6262
const specialTag: SpecialTag = {
6363
'dialog': ['「', '」'],
6464
'quote': ['【', '『', '】', '』'],
65-
'comment': ['<', '>', '(', ')']
65+
'comment': ['(', ')']
6666
};
6767

6868
function addTags(text: string, sTag = specialTag): string {
@@ -238,7 +238,7 @@ export function processTXTContent(text: string, jpFormat = false) {
238238
return it ? `<img src="${it.replaceAll('一', '-')}" referrerpolicy="no-referrer" />` : ''
239239
});
240240
// [comment]
241-
text = text.replaceAll(/\[comment\](.+?)\[\/comment\]/g, '<!-- $1 -->');
241+
text = text.replaceAll(/\[comment\](.+?)\[\/comment\]/g, (_, it) => '<!-- ' + removeTags(it) + ' -->');
242242
const tagSt = [] as Array<string>;
243243
text = text.replaceAll(/\[(\/)?([a-z]{1,10})\]/g, (_, has_slash, tag) => {
244244
const popRes = has_slash ? tagSt.pop() : undefined;

server.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
后续服务端传输HTML到前端,直接显示到dialog
2121
*/
2222

23-
import { checkIsTraditional, downloadNovel, exists, Status, getAppDataDir, defaultGetInfo, traditionalAsyncWrapper, moduleExists } from "./main.ts";
23+
import { checkIsTraditional, downloadNovel, exists, Status, getAppDataDir, defaultGetInfo, traditionalAsyncWrapper, moduleExists, sleep } from "./main.ts";
2424
import mainPage from "./static/server.html" with { type: "text" };
2525
import { render } from "npm:ejs";
2626
import { processTXTContent } from "./2epub.ts";
@@ -230,7 +230,7 @@ async function handleContentRequest(_: Request, url: URL) {
230230
// 使用SQLite缓存
231231
const cachedInfo = await cache.get(novelURL.href);
232232
if (cachedInfo) {
233-
Deno.stdout.writeSync(new TextEncoder().encode('HIT '));
233+
await Deno.stdout.write(new TextEncoder().encode('HIT '));
234234
info = cachedInfo;
235235
} else {
236236
let basicInfo: TraditionalConfig;
@@ -336,6 +336,8 @@ async function handleContentRequest(_: Request, url: URL) {
336336
});
337337
} else if (info.content) {
338338
info.content = processTXTContent(info.content, info.jpStyle);
339+
} else if (info.summary) {
340+
info.summary = processTXTContent(info.summary, info.jpStyle);
339341
}
340342

341343
// render page
@@ -524,9 +526,16 @@ export default async function main() {
524526
return res;
525527
});
526528

529+
let $shutting = false;
527530
Deno.addSignalListener("SIGINT", async () => {
531+
if($shutting) return console.log("Server is already shutting down...");
532+
$shutting = true;
528533
kv.close();
529-
await $s.shutdown();
534+
console.log("Server shutting down...(timeout 3s)");
535+
await Promise.race([
536+
$s.shutdown(),
537+
sleep(3)
538+
]);
530539
console.log("Server stopped");
531540
Deno.exit(0);
532541
});

static/chapter.html.ejs

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,6 @@
9898
margin: 2rem auto;
9999
}
100100
101-
article {
102-
font-size: 1.1rem;
103-
line-height: 1.8;
104-
}
105-
106-
article p {
107-
text-indent: 2em;
108-
margin-bottom: 1.5rem;
109-
overflow: hidden;
110-
word-wrap: break-word;
111-
}
112-
113-
article img {
114-
max-width: 100%;
115-
display: block;
116-
margin: 1rem auto;
117-
border-radius: 8px;
118-
box-shadow: var(--shadow);
119-
}
120-
121101
.progress-bar {
122102
height: 4px;
123103
background-color: var(--light-gray);
@@ -142,6 +122,11 @@
142122
overflow: hidden;
143123
}
144124
125+
.info {
126+
word-break: break-all;
127+
word-break: break-word;
128+
}
129+
145130
@media screen and (min-width: 512px) {
146131
.main {
147132
display: flex;
@@ -162,13 +147,41 @@
162147
margin: 2rem 0;
163148
text-align: left;
164149
padding: 0 1rem;
150+
151+
max-height: 60vh;
152+
overflow-y: auto;
153+
overflow-x: hidden;
154+
155+
/* for scrollbar */
156+
margin-right: -1rem;
157+
padding-right: .5rem;
165158
}
166159
167160
.start-button {
168161
padding: 1rem 2rem;
169162
font-size: 1.1rem;
170163
}
171164
/* <% } %> */
165+
166+
article {
167+
font-size: 1.1rem;
168+
line-height: 1.8;
169+
}
170+
171+
article p {
172+
text-indent: 2em;
173+
margin-bottom: 1.5rem;
174+
overflow: hidden;
175+
word-wrap: break-word;
176+
}
177+
178+
article img {
179+
max-width: 100%;
180+
display: block;
181+
margin: 1rem auto;
182+
border-radius: 8px;
183+
box-shadow: var(--shadow);
184+
}
172185
173186
@media (max-width: 768px) {
174187
.container {
@@ -295,9 +308,9 @@
295308
</h1>
296309
297310
<% if(summary) { %>
298-
<div class="summary">
299-
<p><%= summary %></p>
300-
</div>
311+
<article class="summary">
312+
<p><%- summary %></p>
313+
</article>
301314
<% } %>
302315
303316
<div class="navigation">

0 commit comments

Comments
 (0)