dsh-half-page 0.3.30 → 0.3.32
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 +2 -1
- package/index.js +17 -5
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -358,7 +358,8 @@ window.__ModuleLoader__.load({
|
|
|
358
358
|
paged ? h('div', { style: { ...S.dim, minWidth: 46, textAlign: 'center' } }, all ? '全部' : ((page + 1) + ' / ' + pages)) : null,
|
|
359
359
|
paged ? h('button', { style: S.btn, disabled: all || page >= pages - 1, onClick: () => setView({ page: page + 1 }) }, '›') : null,
|
|
360
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
|
|
361
|
+
h('button', { style: sortMode === 2 ? S.btn : S.btnOn, onClick: () => setView({ sort: sortMode === 1 ? 0 : (sortMode === 0 ? 1 : 0), page: 0 }) }, sortMode === 1 ? '章节 ↓' : '章节 ↑'),
|
|
362
|
+
h('button', { style: sortMode === 2 ? S.btnOn : S.btn, onClick: () => setView({ sort: 2, page: 0 }) }, '时间 ↓'),
|
|
362
363
|
h('button', { style: S.btn, onClick: () => copy(bk.chapters.map((c) => '## ' + c.title + '\n' + c.lines.join('\n')).join('\n\n')) }, '复制这本'),
|
|
363
364
|
),
|
|
364
365
|
list.map((c, ci) => h('div', { key: ci, style: { marginBottom: 6 } },
|
package/index.js
CHANGED
|
@@ -205,15 +205,27 @@ 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
|
-
|
|
210
|
-
}
|
|
211
|
-
raw += `\n### ${chapterTitle}\n` + lines.map((l) => `- ${l}`).join('\n') + '\n'
|
|
208
|
+
const esc = bookTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
209
|
+
let block = `\n### ${chapterTitle}\n` + lines.map((l) => `- ${l}`).join('\n') + '\n'
|
|
212
210
|
if (by) {
|
|
213
211
|
const d = new Date()
|
|
214
212
|
const pad = (n) => String(n).padStart(2, '0')
|
|
215
213
|
const ts = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
|
216
|
-
|
|
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
|
+
}
|
|
217
229
|
}
|
|
218
230
|
await writeFile(p, raw, 'utf8')
|
|
219
231
|
return p
|