Skip to content

Commit f1cc19c

Browse files
committed
update
1 parent 51e1249 commit f1cc19c

3 files changed

Lines changed: 386 additions & 246 deletions

File tree

src/components/BlogIndexEditorDialog.jsx

Lines changed: 11 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { useCallback, useEffect, useState } from 'react'
22
import { GitHubApiError, fetchRepoFileText, getFileSha, upsertFile } from '../lib/github'
33
import { getFriendlyGithubError } from '../lib/githubFriendlyMessages'
4-
import { MARKER_BLOCK_SNIPPET, analyzeIndexMarkers, defaultIndexHtml } from '../lib/blogIndex'
4+
import { analyzeIndexMarkers, defaultIndexHtml } from '../lib/blogIndex'
55
import { BLOG_INDEX } from '../lib/blogPaths'
6-
import {
7-
DEFAULT_INDEX_ENTRY_TEMPLATE,
8-
loadIndexEntryTemplate,
9-
persistIndexEntryTemplate,
10-
} from '../lib/indexEntryTemplate'
116

127
export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
138
const indexPath = BLOG_INDEX
@@ -17,12 +12,9 @@ export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
1712
const [loadErrorDetail, setLoadErrorDetail] = useState('')
1813
const [busyLoad, setBusyLoad] = useState(true)
1914
const [busySave, setBusySave] = useState(false)
20-
const [markerCheck, setMarkerCheck] = useState(null)
21-
const [entryTpl, setEntryTpl] = useState(() => loadIndexEntryTemplate())
2215
const [saveError, setSaveError] = useState('')
2316
const [saveErrorDetail, setSaveErrorDetail] = useState('')
2417
const [confirmOpen, setConfirmOpen] = useState(false)
25-
const [copyHint, setCopyHint] = useState('')
2618
const [baselineHtml, setBaselineHtml] = useState('')
2719

2820
const reloadFromGithub = useCallback(async () => {
@@ -35,7 +27,6 @@ export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
3527
setBusyLoad(true)
3628
setLoadError('')
3729
setLoadErrorDetail('')
38-
setMarkerCheck(null)
3930
try {
4031
const res = await fetchRepoFileText({ token, owner, repo, path: indexPath, branch })
4132
setHtml(res.text)
@@ -64,27 +55,6 @@ export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
6455
return () => window.clearTimeout(id)
6556
}, [reloadFromGithub])
6657

67-
useEffect(() => {
68-
const t = window.setTimeout(() => persistIndexEntryTemplate(entryTpl), 400)
69-
return () => window.clearTimeout(t)
70-
}, [entryTpl])
71-
72-
function runMarkerCheck() {
73-
const a = analyzeIndexMarkers(html)
74-
setMarkerCheck(a)
75-
}
76-
77-
async function copyMarkers() {
78-
try {
79-
await navigator.clipboard.writeText(MARKER_BLOCK_SNIPPET)
80-
setCopyHint('Copied to clipboard.')
81-
window.setTimeout(() => setCopyHint(''), 2500)
82-
} catch {
83-
setCopyHint('Could not copy — select the block above and copy manually.')
84-
window.setTimeout(() => setCopyHint(''), 4000)
85-
}
86-
}
87-
8858
function requestSave() {
8959
setSaveError('')
9060
setSaveErrorDetail('')
@@ -129,7 +99,6 @@ export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
12999
message: `Update homepage: ${indexPath}`,
130100
sha,
131101
})
132-
persistIndexEntryTemplate(entryTpl)
133102
const newSha = body?.content?.sha ?? null
134103
setRemoteSha(newSha ?? (await getFileSha({ token, owner, repo, path: indexPath, branch })))
135104
setBaselineHtml(html)
@@ -147,7 +116,6 @@ export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
147116
}
148117

149118
const dirty = html !== baselineHtml
150-
const markerOk = markerCheck ? markerCheck.kind === 'ok' : false
151119

152120
return (
153121
<div className="dialog-backdrop" role="presentation" onMouseDown={onClose}>
@@ -158,11 +126,10 @@ export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
158126
aria-labelledby="blog-index-title"
159127
onMouseDown={(ev) => ev.stopPropagation()}
160128
>
161-
<h2 id="blog-index-title">Edit homepage (index.html)</h2>
129+
<h2 id="blog-index-title">Save homepage to GitHub</h2>
162130
<p className="dialog-hint dialog-hint--soft">
163-
This is the <strong>homepage file</strong> at <code>{indexPath}</code> in your connected repo. You edit the
164-
raw HTML here. <strong>Marker comments</strong> are invisible notes in the HTML that tell this app where to
165-
drop new post cards after you publish.
131+
Upload the full <code>{indexPath}</code> file. Marker checks and listing templates are in the Code view
132+
advanced sections.
166133
</p>
167134

168135
{busyLoad ? <p className="dialog-hint">Loading from GitHub…</p> : null}
@@ -179,43 +146,16 @@ export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
179146
) : null}
180147

181148
<div className="blog-index__toolbar">
182-
<button type="button" className="btn btn--ghost btn--small" onClick={() => reloadFromGithub()} disabled={busyLoad || busySave}>
149+
<button
150+
type="button"
151+
className="btn btn--ghost btn--small"
152+
onClick={() => reloadFromGithub()}
153+
disabled={busyLoad || busySave}
154+
>
183155
Reload from GitHub
184156
</button>
185-
<button type="button" className="btn btn--ghost btn--small" onClick={runMarkerCheck} disabled={busyLoad}>
186-
Check for markers
187-
</button>
188-
<button type="button" className="btn btn--ghost btn--small" onClick={copyMarkers} disabled={busyLoad}>
189-
Copy marker block
190-
</button>
191157
</div>
192158

193-
{copyHint ? <p className="dialog-hint dialog-hint--compact">{copyHint}</p> : null}
194-
195-
<div className="blog-index__markers-help">
196-
<p className="dialog-hint dialog-hint--compact">
197-
To automatically add new posts to your homepage, paste these two marker comments into your{' '}
198-
<code>index.html</code> where you want new posts to appear. New posts will be added <strong>between</strong>{' '}
199-
them after publishing (newest first). They do not show up on the public page — they are only instructions
200-
for this app.
201-
</p>
202-
<pre className="blog-index__snippet" aria-label="Marker block to copy">
203-
{MARKER_BLOCK_SNIPPET}
204-
</pre>
205-
</div>
206-
207-
{markerCheck ? (
208-
<div className={`blog-index__check ${markerOk ? 'is-ok' : 'is-warn'}`} role="status">
209-
<strong>{markerOk ? 'Markers look good.' : 'Marker check'}</strong>
210-
<span>
211-
{' '}
212-
{markerOk
213-
? 'Exactly one start and one end, in the right order.'
214-
: markerCheck.message}
215-
</span>
216-
</div>
217-
) : null}
218-
219159
{dirty ? (
220160
<p className="dialog-hint dialog-hint--compact">
221161
You have unsaved edits ({Math.abs(html.length - baselineHtml.length)} characters different from last load).
@@ -226,7 +166,7 @@ export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
226166

227167
<label className="field" htmlFor="blog-index-html">
228168
<span>Homepage HTML</span>
229-
<span className="field-help">The full file. Saving replaces this file on GitHub for the branch you connected.</span>
169+
<span className="field-help">Saving replaces this file on GitHub for the branch you connected.</span>
230170
<textarea
231171
id="blog-index-html"
232172
className="blog-index__textarea"
@@ -237,24 +177,6 @@ export function BlogIndexEditorDialog({ settings, onClose, onSaved }) {
237177
/>
238178
</label>
239179

240-
<label className="field" htmlFor="blog-index-entry-tpl">
241-
<span>Post listing template (each new post)</span>
242-
<span className="field-help">
243-
HTML for one post on the homepage. Placeholders:{' '}
244-
<code>{'{{title}}'}</code>, <code>{'{{url}}'}</code> (link to the .html file), <code>{'{{date}}'}</code>{' '}
245-
(readable date), <code>{'{{dateIso}}'}</code> (machine date), <code>{'{{excerpt}}'}</code>,{' '}
246-
<code>{'{{slug}}'}</code>, <code>{'{{category}}'}</code>. Values are escaped for safety.
247-
</span>
248-
<textarea
249-
id="blog-index-entry-tpl"
250-
className="blog-index__textarea blog-index__textarea--short"
251-
value={entryTpl}
252-
onChange={(e) => setEntryTpl(e.target.value)}
253-
spellCheck={false}
254-
placeholder={DEFAULT_INDEX_ENTRY_TEMPLATE}
255-
/>
256-
</label>
257-
258180
{saveError ? <p className="dialog-error">{saveError}</p> : null}
259181
{saveErrorDetail ? (
260182
<details className="dialog-error-details">

0 commit comments

Comments
 (0)