dsh-half-page 0.3.33 → 0.3.34

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.
Files changed (3) hide show
  1. package/client.js +4 -3
  2. package/index.js +20 -1
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -336,13 +336,14 @@ window.__ModuleLoader__.load({
336
336
  const page = Math.min(v.page || 0, pages - 1)
337
337
  // 排序:章节升 / 章节降 / 时间新在前(没写时间的排在后面)
338
338
  const sortLabels = ['章节 \u2191', '章节 \u2193', '时间 \u2193']
339
- const sortMode = v.sort || 0
339
+ const sortMode = (v.sort === undefined ? ((state && state.noteSort) || 0) : v.sort) % 3
340
340
  const sorted = bk.chapters.slice()
341
341
  if (sortMode === 1) sorted.sort((a, b) => (chapterNo(b.title) || -1) - (chapterNo(a.title) || -1))
342
342
  else if (sortMode === 2) sorted.sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')))
343
343
  else sorted.sort((a, b) => (chapterNo(a.title) || 1e9) - (chapterNo(b.title) || 1e9))
344
344
  const list = all ? sorted : sorted.slice(page * NOTE_PAGE, page * NOTE_PAGE + NOTE_PAGE)
345
345
  const setView = (patch) => setNoteView(Object.assign({}, noteView, { [bi]: Object.assign({}, v, patch) }))
346
+ const saveSort = (n) => { try { getJson('/dsh-reading.notesort', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ sort: n }) }) } catch (e) {} }
346
347
  const paged = total > NOTE_PAGE
347
348
  const tabs = h('div', { style: { ...S.row, gap: 6, marginBottom: 8, flexWrap: 'wrap' } },
348
349
  notes.map((n, ni) => h('button', {
@@ -360,10 +361,10 @@ window.__ModuleLoader__.load({
360
361
  paged ? h('div', { style: { ...S.dim, minWidth: 46, textAlign: 'center' } }, all ? '全部' : ((page + 1) + ' / ' + pages)) : null,
361
362
  paged ? h('button', { style: S.btn, disabled: all || page >= pages - 1, onClick: () => setView({ page: page + 1 }) }, '›') : null,
362
363
  paged ? h('button', { style: all ? S.btnOn : S.btn, onClick: () => setView({ all: !all, page: 0 }) }, all ? '分页' : '全部') : null,
363
- h('button', { style: sortMode === 2 ? S.btn : S.btnOn, onClick: () => setView({ sort: sortMode === 1 ? 0 : (sortMode === 0 ? 1 : 0), page: 0 }) }, sortMode === 1 ? '章节 ↓' : '章节 ↑'),
364
- h('button', { style: sortMode === 2 ? S.btnOn : S.btn, onClick: () => setView({ sort: 2, page: 0 }) }, '时间 ↓'),
364
+ h('button', { style: S.btnOn, onClick: () => { const next = (sortMode + 1) % 3; setView({ sort: next, page: 0 }); saveSort(next) } }, sortLabels[sortMode]),
365
365
  h('button', { style: S.btn, onClick: () => copy(bk.chapters.map((c) => '## ' + c.title + '\n' + c.lines.join('\n')).join('\n\n')) }, '复制这本'),
366
366
  ),
367
+ (sortMode === 2 && bk.chapters.filter((c) => !c.at).length) ? h('div', { style: { ...S.dim, marginBottom: 6 } }, '有 ' + bk.chapters.filter((c) => !c.at).length + ' 段早期笔记当时没记时间,排在最后。') : null,
367
368
  list.map((c, ci) => h('div', { key: ci, style: { marginBottom: 6 } },
368
369
  h('div', { style: S.row },
369
370
  h('div', { style: { ...S.dim, color: C.warn } }, c.title),
package/index.js CHANGED
@@ -268,7 +268,7 @@ export function apply(ctx) {
268
268
  let notes = ''
269
269
  try { notes = await readFile(await notesPath(dir), 'utf8') } catch {}
270
270
  res.setHeader('content-type', 'application/json; charset=utf-8')
271
- res.end(JSON.stringify({ ok: true, dir, perDay, today: today(), readToday: rt, current: st.current, books, notes }))
271
+ res.end(JSON.stringify({ ok: true, dir, perDay, today: today(), readToday: rt, current: st.current, books, notes, noteSort: Number(cfgNow.noteSort) || 0 }))
272
272
  },
273
273
  }),
274
274
  )
@@ -742,6 +742,25 @@ async function signWork(rel, who) {
742
742
  }),
743
743
  )
744
744
 
745
+ // 读后感的排序方式(0=章节升 1=章节降 2=时间降),存在 reading.config.json 里
746
+ ctx.effect(() =>
747
+ ctx.webServer.register({
748
+ kind: 'exact',
749
+ path: '/dsh-reading.notesort',
750
+ async handler(req, res) {
751
+ let body = ''
752
+ for await (const chunk of req) body += chunk
753
+ let patch = {}
754
+ try { patch = JSON.parse(body || '{}') } catch {}
755
+ const sort = Math.max(0, Math.min(2, Number(patch.sort) || 0))
756
+ const cfg = { ...(await config()) }
757
+ await writeJson(CONFIG, { ...cfg, noteSort: sort })
758
+ res.setHeader('content-type', 'application/json; charset=utf-8')
759
+ res.end(JSON.stringify({ ok: true, noteSort: sort }))
760
+ },
761
+ }),
762
+ )
763
+
745
764
  // 书籍状态:在读 / 已读完 / 弃坑(空 status 表示清掉)
746
765
  ctx.effect(() =>
747
766
  ctx.webServer.register({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-half-page",
3
- "version": "0.3.33",
3
+ "version": "0.3.34",
4
4
  "private": false,
5
5
  "author": "鹿野 <luye@dsh.local>",
6
6
  "license": "MIT",