dsh-reading-inbox 0.3.0 → 0.5.0
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/README.en.md +17 -9
- package/README.md +17 -9
- package/VERIFY.md +14 -0
- package/index.js +3 -2
- package/package.json +1 -1
- package/src/config.js +3 -0
- package/src/fetch.js +67 -5
- package/src/markdown.js +8 -1
- package/src/routes.js +67 -0
- package/src/store.js +420 -12
- package/src/tools.js +53 -0
- package/web/app.js +118 -4
- package/web/index.html +20 -0
- package/web/style.css +66 -0
package/web/app.js
CHANGED
|
@@ -26,7 +26,19 @@ const els = {
|
|
|
26
26
|
clipForm: $('#clip-form'),
|
|
27
27
|
clipUrl: $('#clip-url'),
|
|
28
28
|
clipTags: $('#clip-tags'),
|
|
29
|
+
clipAssets: $('#clip-assets'),
|
|
29
30
|
clipSubmit: $('#clip-submit'),
|
|
31
|
+
saveTextToggle: $('#save-text-toggle'),
|
|
32
|
+
textPanel: $('#text-panel'),
|
|
33
|
+
textForm: $('#text-form'),
|
|
34
|
+
textTitle: $('#text-title'),
|
|
35
|
+
textUrl: $('#text-url'),
|
|
36
|
+
textTags: $('#text-tags'),
|
|
37
|
+
textBody: $('#text-body'),
|
|
38
|
+
textCancel: $('#text-cancel'),
|
|
39
|
+
exportAll: $('#export-all'),
|
|
40
|
+
importToggle: $('#import-toggle'),
|
|
41
|
+
importFile: $('#import-file'),
|
|
30
42
|
tagFilter: $('#tag-filter'),
|
|
31
43
|
tagFilterName: $('#tag-filter-name'),
|
|
32
44
|
tagClear: $('#tag-clear'),
|
|
@@ -101,7 +113,6 @@ function toast(message, isError = false) {
|
|
|
101
113
|
|
|
102
114
|
async function api(path, options = {}) {
|
|
103
115
|
const response = await fetch(`./api${path}`, {
|
|
104
|
-
credentials: 'same-origin',
|
|
105
116
|
...options,
|
|
106
117
|
headers: {
|
|
107
118
|
...(options.body === undefined ? {} : { 'content-type': 'application/json' }),
|
|
@@ -558,6 +569,7 @@ function renderDetail() {
|
|
|
558
569
|
const author = item.author ? `<span>${escapeHtml(item.author)}</span><span>·</span>` : ''
|
|
559
570
|
const published = item.published ? `<span>${escapeHtml(item.published.slice(0, 10))}</span><span>·</span>` : ''
|
|
560
571
|
const truncated = item.truncated ? '<p class="article-note">原文较长,保存时已截断。</p>' : ''
|
|
572
|
+
const sourceLink = item.url ? `<a href="${escapeAttr(item.url)}" target="_blank" rel="noopener noreferrer">打开原文</a>` : ''
|
|
561
573
|
const annotations = Array.isArray(item.annotations) ? item.annotations : []
|
|
562
574
|
const annotationMeta = annotations.length > 0
|
|
563
575
|
? `<span>·</span><span>${annotations.length} 批注</span>`
|
|
@@ -573,8 +585,7 @@ function renderDetail() {
|
|
|
573
585
|
</div>
|
|
574
586
|
<h2>${escapeHtml(item.title)}</h2>
|
|
575
587
|
<div class="detail-sub">
|
|
576
|
-
${author}${published}
|
|
577
|
-
<a href="${escapeAttr(item.url)}" target="_blank" rel="noopener noreferrer">打开原文</a>
|
|
588
|
+
${author}${published}${sourceLink}
|
|
578
589
|
</div>
|
|
579
590
|
<div class="actions">
|
|
580
591
|
<button type="button" class="button ghost mobile-back" data-action="back">返回</button>
|
|
@@ -593,6 +604,13 @@ function renderDetail() {
|
|
|
593
604
|
${renderAnnotationSection(annotations)}
|
|
594
605
|
`
|
|
595
606
|
|
|
607
|
+
for (const image of els.detail.querySelectorAll('.article img')) {
|
|
608
|
+
const source = image.getAttribute('src') ?? ''
|
|
609
|
+
if (source.startsWith('assets/')) {
|
|
610
|
+
image.src = `./asset/${encodeURIComponent(item.id)}/${source.slice('assets/'.length)}`
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
596
614
|
applyHighlights(els.detail.querySelector('.article'), annotations)
|
|
597
615
|
}
|
|
598
616
|
|
|
@@ -665,7 +683,11 @@ els.clipForm.addEventListener('submit', async event => {
|
|
|
665
683
|
try {
|
|
666
684
|
const data = await api('/clip', {
|
|
667
685
|
method: 'POST',
|
|
668
|
-
body: JSON.stringify({
|
|
686
|
+
body: JSON.stringify({
|
|
687
|
+
url,
|
|
688
|
+
tags,
|
|
689
|
+
assets: els.clipAssets?.checked ? 'local' : undefined,
|
|
690
|
+
}),
|
|
669
691
|
})
|
|
670
692
|
const clip = data.clip
|
|
671
693
|
toast(clip.duplicate ? '这个链接已经在收件箱里了' : '已保存到阅读收件箱')
|
|
@@ -683,6 +705,98 @@ els.clipForm.addEventListener('submit', async event => {
|
|
|
683
705
|
})
|
|
684
706
|
|
|
685
707
|
let searchTimer
|
|
708
|
+
function showTextPanel() {
|
|
709
|
+
if (!els.textPanel) return
|
|
710
|
+
els.textPanel.hidden = false
|
|
711
|
+
els.textTitle.value = ''
|
|
712
|
+
els.textUrl.value = ''
|
|
713
|
+
els.textTags.value = ''
|
|
714
|
+
els.textBody.value = ''
|
|
715
|
+
els.textBody.focus()
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function hideTextPanel() {
|
|
719
|
+
if (!els.textPanel) return
|
|
720
|
+
els.textPanel.hidden = true
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (els.saveTextToggle) els.saveTextToggle.addEventListener('click', showTextPanel)
|
|
724
|
+
if (els.textCancel) els.textCancel.addEventListener('click', hideTextPanel)
|
|
725
|
+
if (els.textForm) {
|
|
726
|
+
els.textForm.addEventListener('submit', async event => {
|
|
727
|
+
event.preventDefault()
|
|
728
|
+
const text = els.textBody.value.trim()
|
|
729
|
+
if (text === '') {
|
|
730
|
+
els.textBody.focus()
|
|
731
|
+
return
|
|
732
|
+
}
|
|
733
|
+
const submit = els.textForm.querySelector('button[type="submit"]')
|
|
734
|
+
if (submit) submit.disabled = true
|
|
735
|
+
try {
|
|
736
|
+
const data = await api('/save-text', {
|
|
737
|
+
method: 'POST',
|
|
738
|
+
body: JSON.stringify({
|
|
739
|
+
title: els.textTitle.value.trim(),
|
|
740
|
+
url: els.textUrl.value.trim(),
|
|
741
|
+
tags: els.textTags.value.split(/[,,]/).map(value => value.trim()).filter(Boolean),
|
|
742
|
+
text,
|
|
743
|
+
}),
|
|
744
|
+
})
|
|
745
|
+
const clip = data.clip
|
|
746
|
+
hideTextPanel()
|
|
747
|
+
toast(clip.duplicate ? '这个链接已经在收件箱里了' : '已保存到阅读收件箱')
|
|
748
|
+
await loadStats()
|
|
749
|
+
await loadList()
|
|
750
|
+
await select(clip.id)
|
|
751
|
+
} catch (error) {
|
|
752
|
+
toast(error.message, true)
|
|
753
|
+
} finally {
|
|
754
|
+
if (submit) submit.disabled = false
|
|
755
|
+
}
|
|
756
|
+
})
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
async function exportAll() {
|
|
760
|
+
try {
|
|
761
|
+
const response = await fetch('./api/export?format=json')
|
|
762
|
+
if (!response.ok) throw new Error(`导出失败:HTTP ${response.status}`)
|
|
763
|
+
const blob = await response.blob()
|
|
764
|
+
const link = document.createElement('a')
|
|
765
|
+
const url = URL.createObjectURL(blob)
|
|
766
|
+
link.href = url
|
|
767
|
+
link.download = 'dsh-reading-inbox.json'
|
|
768
|
+
document.body.append(link)
|
|
769
|
+
link.click()
|
|
770
|
+
link.remove()
|
|
771
|
+
setTimeout(() => URL.revokeObjectURL(url), 1_000)
|
|
772
|
+
toast('已导出全部')
|
|
773
|
+
} catch (error) {
|
|
774
|
+
toast(error.message, true)
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (els.exportAll) els.exportAll.addEventListener('click', exportAll)
|
|
779
|
+
if (els.importToggle && els.importFile) {
|
|
780
|
+
els.importToggle.addEventListener('click', () => els.importFile.click())
|
|
781
|
+
els.importFile.addEventListener('change', async () => {
|
|
782
|
+
const file = els.importFile.files?.[0]
|
|
783
|
+
if (!file) return
|
|
784
|
+
try {
|
|
785
|
+
const bundle = JSON.parse(await file.text())
|
|
786
|
+
const data = await api('/import', { method: 'POST', body: JSON.stringify(bundle) })
|
|
787
|
+
const errors = Array.isArray(data.errors) && data.errors.length > 0 ? `,${data.errors.length} 条错误` : ''
|
|
788
|
+
toast(`导入 ${data.imported} 篇,跳过 ${data.skipped} 篇${errors}`)
|
|
789
|
+
await loadStats()
|
|
790
|
+
await loadList()
|
|
791
|
+
await loadViews()
|
|
792
|
+
} catch (error) {
|
|
793
|
+
toast(error.message, true)
|
|
794
|
+
} finally {
|
|
795
|
+
els.importFile.value = ''
|
|
796
|
+
}
|
|
797
|
+
})
|
|
798
|
+
}
|
|
799
|
+
|
|
686
800
|
els.search.addEventListener('input', () => {
|
|
687
801
|
clearTimeout(searchTimer)
|
|
688
802
|
searchTimer = setTimeout(() => {
|
package/web/index.html
CHANGED
|
@@ -22,11 +22,31 @@
|
|
|
22
22
|
<div class="clip-inputs">
|
|
23
23
|
<input id="clip-url" type="text" inputmode="url" placeholder="粘贴网页链接,回车保存" autocomplete="off" required>
|
|
24
24
|
<input id="clip-tags" type="text" placeholder="标签,逗号分隔(可选)" autocomplete="off">
|
|
25
|
+
<label class="clip-assets"><input id="clip-assets" type="checkbox"> 本地图片</label>
|
|
25
26
|
</div>
|
|
26
27
|
<button type="submit" class="primary" id="clip-submit">保存</button>
|
|
27
28
|
</form>
|
|
29
|
+
<button type="button" id="save-text-toggle" class="button">粘贴文本</button>
|
|
30
|
+
<button type="button" id="export-all" class="button">导出</button>
|
|
31
|
+
<button type="button" id="import-toggle" class="button">导入</button>
|
|
32
|
+
<input id="import-file" type="file" accept="application/json,.json" hidden>
|
|
28
33
|
</header>
|
|
29
34
|
|
|
35
|
+
<section id="text-panel" class="text-panel" hidden>
|
|
36
|
+
<form id="text-form" class="text-form">
|
|
37
|
+
<div class="text-form-row">
|
|
38
|
+
<input id="text-title" type="text" placeholder="标题(可选)">
|
|
39
|
+
<input id="text-url" type="text" placeholder="来源链接(可选)">
|
|
40
|
+
<input id="text-tags" type="text" placeholder="标签,逗号分隔(可选)">
|
|
41
|
+
</div>
|
|
42
|
+
<textarea id="text-body" rows="8" placeholder="粘贴正文、Markdown 或 HTML…" required></textarea>
|
|
43
|
+
<div class="text-form-actions">
|
|
44
|
+
<button type="submit" class="button primary">保存到收件箱</button>
|
|
45
|
+
<button type="button" id="text-cancel" class="button ghost">取消</button>
|
|
46
|
+
</div>
|
|
47
|
+
</form>
|
|
48
|
+
</section>
|
|
49
|
+
|
|
30
50
|
<main class="layout" id="layout">
|
|
31
51
|
<aside class="list-pane">
|
|
32
52
|
<div class="list-head">
|
package/web/style.css
CHANGED
|
@@ -812,3 +812,69 @@ mark.hl.pulse {
|
|
|
812
812
|
border-radius: 8px;
|
|
813
813
|
background: var(--panel-2);
|
|
814
814
|
}
|
|
815
|
+
|
|
816
|
+
.text-panel {
|
|
817
|
+
padding: 12px 18px;
|
|
818
|
+
background: var(--panel);
|
|
819
|
+
border-bottom: 1px solid var(--border);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
.text-panel[hidden] { display: none; }
|
|
823
|
+
|
|
824
|
+
.text-form {
|
|
825
|
+
display: flex;
|
|
826
|
+
flex-direction: column;
|
|
827
|
+
gap: 8px;
|
|
828
|
+
max-width: 980px;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
.text-form-row {
|
|
832
|
+
display: flex;
|
|
833
|
+
gap: 8px;
|
|
834
|
+
flex-wrap: wrap;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
.text-form-row input {
|
|
838
|
+
flex: 1 1 220px;
|
|
839
|
+
min-width: 0;
|
|
840
|
+
height: 30px;
|
|
841
|
+
padding: 0 8px;
|
|
842
|
+
border: 1px solid var(--border);
|
|
843
|
+
border-radius: 8px;
|
|
844
|
+
background: var(--panel-2);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
.text-form textarea {
|
|
848
|
+
width: 100%;
|
|
849
|
+
min-height: 140px;
|
|
850
|
+
resize: vertical;
|
|
851
|
+
padding: 9px;
|
|
852
|
+
border: 1px solid var(--border);
|
|
853
|
+
border-radius: 8px;
|
|
854
|
+
background: var(--panel-2);
|
|
855
|
+
color: var(--text);
|
|
856
|
+
font: inherit;
|
|
857
|
+
line-height: 1.5;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
.text-form-actions { display: flex; gap: 6px; }
|
|
861
|
+
|
|
862
|
+
@media (max-width: 820px) {
|
|
863
|
+
.text-panel { padding: 10px 12px; }
|
|
864
|
+
.text-form-row input { flex-basis: 100%; }
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
.clip-assets {
|
|
868
|
+
display: inline-flex;
|
|
869
|
+
align-items: center;
|
|
870
|
+
gap: 4px;
|
|
871
|
+
color: var(--muted);
|
|
872
|
+
font-size: 12px;
|
|
873
|
+
white-space: nowrap;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
.clip-assets input {
|
|
877
|
+
width: auto;
|
|
878
|
+
height: auto;
|
|
879
|
+
accent-color: var(--accent);
|
|
880
|
+
}
|