dsh-half-page 0.3.29 → 0.3.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +20 -2
- package/index.js +21 -4
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -54,7 +54,17 @@ window.__ModuleLoader__.load({
|
|
|
54
54
|
ch = { title: line.replace(/^###\s+/, '').trim(), lines: [] }
|
|
55
55
|
if (book) book.chapters.push(ch)
|
|
56
56
|
} else if (/^[-*]\s+/.test(line)) {
|
|
57
|
-
if (ch)
|
|
57
|
+
if (ch) {
|
|
58
|
+
const t = line.replace(/^[-*]\s+/, '')
|
|
59
|
+
ch.lines.push(t)
|
|
60
|
+
// 署名行里带着时间:- ↳ 来自:鹿野 · 2026-11-10 20:31
|
|
61
|
+
if (/^↳/.test(t)) {
|
|
62
|
+
const m = t.match(/(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2})/)
|
|
63
|
+
if (m) ch.at = m[1] + ' ' + m[2]
|
|
64
|
+
const b = t.replace(/^\u21b3\s*\u6765\u81ea\uff1a/, '').split('\u00b7')[0].trim()
|
|
65
|
+
if (b) ch.by = b
|
|
66
|
+
}
|
|
67
|
+
}
|
|
58
68
|
}
|
|
59
69
|
}
|
|
60
70
|
return out
|
|
@@ -322,7 +332,14 @@ window.__ModuleLoader__.load({
|
|
|
322
332
|
const total = bk.chapters.length
|
|
323
333
|
const pages = Math.max(1, Math.ceil(total / NOTE_PAGE))
|
|
324
334
|
const page = Math.min(v.page || 0, pages - 1)
|
|
325
|
-
|
|
335
|
+
// 排序:章节升 / 章节降 / 时间新在前(没写时间的排在后面)
|
|
336
|
+
const sortLabels = ['章节 \u2191', '章节 \u2193', '时间 \u2193']
|
|
337
|
+
const sortMode = v.sort || 0
|
|
338
|
+
const sorted = bk.chapters.slice()
|
|
339
|
+
if (sortMode === 1) sorted.sort((a, b) => (chapterNo(b.title) || -1) - (chapterNo(a.title) || -1))
|
|
340
|
+
else if (sortMode === 2) sorted.sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')))
|
|
341
|
+
else sorted.sort((a, b) => (chapterNo(a.title) || 1e9) - (chapterNo(b.title) || 1e9))
|
|
342
|
+
const list = all ? sorted : sorted.slice(page * NOTE_PAGE, page * NOTE_PAGE + NOTE_PAGE)
|
|
326
343
|
const setView = (patch) => setNoteView(Object.assign({}, noteView, { [bi]: Object.assign({}, v, patch) }))
|
|
327
344
|
const paged = total > NOTE_PAGE
|
|
328
345
|
const tabs = h('div', { style: { ...S.row, gap: 6, marginBottom: 8, flexWrap: 'wrap' } },
|
|
@@ -341,6 +358,7 @@ window.__ModuleLoader__.load({
|
|
|
341
358
|
paged ? h('div', { style: { ...S.dim, minWidth: 46, textAlign: 'center' } }, all ? '全部' : ((page + 1) + ' / ' + pages)) : null,
|
|
342
359
|
paged ? h('button', { style: S.btn, disabled: all || page >= pages - 1, onClick: () => setView({ page: page + 1 }) }, '›') : null,
|
|
343
360
|
paged ? h('button', { style: all ? S.btnOn : S.btn, onClick: () => setView({ all: !all, page: 0 }) }, all ? '分页' : '全部') : null,
|
|
361
|
+
h('button', { style: S.btn, onClick: () => setView({ sort: (sortMode + 1) % 3, page: 0 }) }, sortLabels[sortMode]),
|
|
344
362
|
h('button', { style: S.btn, onClick: () => copy(bk.chapters.map((c) => '## ' + c.title + '\n' + c.lines.join('\n')).join('\n\n')) }, '复制这本'),
|
|
345
363
|
),
|
|
346
364
|
list.map((c, ci) => h('div', { key: ci, style: { marginBottom: 6 } },
|
package/index.js
CHANGED
|
@@ -205,11 +205,28 @@ export async function appendNote(dir, bookTitle, chapterTitle, lines, by) {
|
|
|
205
205
|
const p = await notesPath(dir)
|
|
206
206
|
let raw = ''
|
|
207
207
|
try { raw = await readFile(p, 'utf8') } catch {}
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
const esc = bookTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
209
|
+
let block = `\n### ${chapterTitle}\n` + lines.map((l) => `- ${l}`).join('\n') + '\n'
|
|
210
|
+
if (by) {
|
|
211
|
+
const d = new Date()
|
|
212
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
213
|
+
const ts = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
|
214
|
+
block += `- \u21b3 \u6765\u81ea\uff1a${by} \u00b7 ${ts}\n`
|
|
215
|
+
}
|
|
216
|
+
const headRe = new RegExp(`^##\\s+${esc}\\s*$`, 'm')
|
|
217
|
+
const m = headRe.exec(raw)
|
|
218
|
+
if (!m) {
|
|
219
|
+
raw = (raw.trim() ? raw.replace(/\s*$/, '') + '\n\n' : '') + `## ${bookTitle}\n` + block
|
|
220
|
+
} else {
|
|
221
|
+
const at0 = m.index + m[0].length
|
|
222
|
+
const next = raw.slice(at0).search(/^##\s+/m)
|
|
223
|
+
if (next < 0) {
|
|
224
|
+
raw = raw.replace(/\s*$/, '') + '\n' + block
|
|
225
|
+
} else {
|
|
226
|
+
const at = at0 + next
|
|
227
|
+
raw = raw.slice(0, at).replace(/\s*$/, '') + '\n' + block + '\n' + raw.slice(at)
|
|
228
|
+
}
|
|
210
229
|
}
|
|
211
|
-
raw += `\n### ${chapterTitle}\n` + lines.map((l) => `- ${l}`).join('\n') + '\n'
|
|
212
|
-
if (by) raw += `- ↳ 来自:${by}\n`
|
|
213
230
|
await writeFile(p, raw, 'utf8')
|
|
214
231
|
return p
|
|
215
232
|
}
|