Repository navigation
Expand file tree
/
Copy patheditor.html
More file actions
636 lines (542 loc) · 18.3 KB
/
Copy patheditor.html
File metadata and controls
636 lines (542 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
<!doctype html>
<html lang="zh-CN" data-theme="mist-cyan">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>nobody's note · editor</title>
<meta name="robots" content="noindex,nofollow,noarchive" />
<style>
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;500;600;700&display=swap');
:root{
--bg:#e8efef;
--bg2:#f7fbfb;
--paper:#fafcfb;
--paper-soft:#f1f6f5;
--glass:rgba(250,252,251,.68);
--line:#d3dddd;
--text:#24373a;
--muted:#6f8587;
--title:#203235;
--shadow:0 18px 40px rgba(90,120,120,.09);
--accent:#59797b;
--accent-soft:#dce8e7;
--ui-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;
}
html[data-theme="moon-paper"]{
--bg:#f2f4f5;--bg2:#fafbfb;--paper:#fdfdfd;--paper-soft:#f7f8f9;--glass:rgba(255,255,255,.72);--line:#dfe4e6;--text:#2a3338;--muted:#7a8489;--title:#202a2f;--shadow:0 18px 40px rgba(120,130,135,.08);--accent:#677a83;--accent-soft:#e5eaed;
}
html[data-theme="mist-cyan"]{
--bg:#e8efef;--bg2:#f7fbfb;--paper:#fafcfb;--paper-soft:#f1f6f5;--glass:rgba(250,252,251,.68);--line:#d3dddd;--text:#24373a;--muted:#6f8587;--title:#203235;--shadow:0 18px 40px rgba(90,120,120,.09);--accent:#59797b;--accent-soft:#dce8e7;
}
html[data-theme="ink-night"]{
--bg:#1d2530;--bg2:#2a3440;--paper:#28313d;--paper-soft:#313b48;--glass:rgba(40,49,61,.78);--line:#44515e;--text:#dce5ea;--muted:#96a7b2;--title:#edf3f6;--shadow:0 18px 40px rgba(7,13,18,.32);--accent:#9db7c3;--accent-soft:#34404c;
}
html[data-theme="parchment"]{
--bg:#f5ecda;--bg2:#faf5ea;--paper:#fffaf0;--paper-soft:#f6efe0;--glass:rgba(255,250,240,.78);--line:#e0d3b8;--text:#4a3c2a;--muted:#8a7558;--title:#3e3020;--shadow:0 18px 40px rgba(148,124,88,.10);--accent:#8a6d4e;--accent-soft:#f1e4cf;
}
html[data-theme="violet-mist"]{
--bg:#efeaf7;--bg2:#faf8fd;--paper:#fbf9ff;--paper-soft:#f4effb;--glass:rgba(251,249,255,.64);--line:#ddd3ec;--text:#342d45;--muted:#7e7594;--title:#2d2540;--shadow:0 18px 40px rgba(112,94,145,.12);--accent:#7b6a99;--accent-soft:#ebe3f8;
}
html[data-theme="clear-blue"]{
--bg:#eaf4ff;--bg2:#f8fcff;--paper:#fbfdff;--paper-soft:#f1f7fc;--glass:rgba(251,253,255,.72);--line:#d7e5f1;--text:#23384a;--muted:#6e879c;--title:#21384f;--shadow:0 18px 40px rgba(104,148,186,.10);--accent:#6da9d8;--accent-soft:#dcecf8;
}
html[data-theme="rose-ash"]{
--bg:#f6eef1;--bg2:#fbf8f9;--paper:#fffafb;--paper-soft:#f8eff2;--glass:rgba(255,250,251,.74);--line:#e7d8de;--text:#4a3138;--muted:#8f717a;--title:#412830;--shadow:0 18px 40px rgba(152,108,122,.10);--accent:#b77987;--accent-soft:#f0dfe4;
}
*{box-sizing:border-box}
html,body{
margin:0;
padding:0;
color:var(--text);
background:radial-gradient(circle at 10% 12%,rgba(255,255,255,.55),transparent 18%),linear-gradient(180deg,var(--bg),var(--bg2));
font-family:"STFangsong","FangSong","Songti SC","Noto Serif SC","Source Han Serif SC",serif;
}
.wrap{
max-width:1280px;
margin:0 auto;
padding:26px 18px 42px;
}
.hero{
position:relative;
margin-bottom:20px;
}
.theme-corner{
position:absolute;
top:0;
right:0;
z-index:5;
}
.theme-corner select{
min-width:112px;
width:auto;
padding:7px 10px;
font-size:11px;
border-radius:999px;
border:1px solid var(--line);
background:var(--glass);
color:var(--muted);
outline:none;
box-shadow:var(--shadow);
font-family:var(--ui-font);
backdrop-filter:blur(10px);
-webkit-backdrop-filter:blur(10px);
}
.hero-card,.panel{
background:var(--glass);
border:1px solid var(--line);
border-radius:24px;
box-shadow:var(--shadow);
backdrop-filter:blur(12px);
-webkit-backdrop-filter:blur(12px);
}
.hero-card{
padding:24px 24px 22px;
}
.eyebrow{
display:inline-flex;
padding:4px 10px;
border-radius:999px;
border:1px solid var(--line);
background:var(--paper-soft);
color:var(--muted);
font-size:12px;
letter-spacing:.10em;
text-transform:uppercase;
font-family:var(--ui-font);
}
.title{
margin:14px 0 0;
font-family:"Cormorant Garamond",Georgia,serif;
font-size:46px;
font-weight:600;
line-height:1.02;
color:var(--title);
}
.sub{
margin:12px 0 0;
font-size:16px;
line-height:1.8;
color:var(--text);
max-width:780px;
}
.layout{
display:grid;
grid-template-columns:1fr 1fr;
gap:18px;
}
.panel-hd{
padding:16px 18px;
border-bottom:1px solid var(--line);
display:flex;
justify-content:space-between;
gap:10px;
align-items:flex-end;
flex-wrap:wrap;
}
.panel-hd h2{
margin:0;
font-size:18px;
font-weight:500;
color:var(--title);
}
.panel-hd p{
margin:6px 0 0;
color:var(--muted);
font-size:13px;
font-family:var(--ui-font);
}
.panel-bd{
padding:18px;
}
.grid{
display:grid;
grid-template-columns:1fr 1fr;
gap:14px;
}
.full{grid-column:1/-1}
label{
display:block;
margin-bottom:6px;
color:var(--muted);
font-size:13px;
font-family:var(--ui-font);
letter-spacing:.04em;
}
input,textarea{
width:100%;
border:1px solid var(--line);
background:var(--paper-soft);
color:var(--text);
border-radius:14px;
padding:11px 12px;
font:inherit;
outline:none;
}
textarea{
resize:vertical;
min-height:120px;
line-height:1.85;
}
.actions{
display:flex;
gap:10px;
flex-wrap:wrap;
margin-top:16px;
}
button{
cursor:pointer;
border:none;
border-radius:12px;
padding:10px 14px;
color:#fff;
background:linear-gradient(135deg,var(--accent),var(--accent-soft));
font:inherit;
font-family:var(--ui-font);
}
button.secondary{
background:var(--paper-soft);
color:var(--text);
border:1px solid var(--line);
}
.hint{
margin-top:12px;
color:var(--muted);
font-size:13px;
line-height:1.75;
font-family:var(--ui-font);
}
.hint code{
background:var(--paper-soft);
border:1px solid var(--line);
border-radius:6px;
padding:2px 6px;
font-size:12px;
}
pre{
margin:0;
white-space:pre-wrap;
word-break:break-word;
background:var(--paper-soft);
border:1px solid var(--line);
border-radius:14px;
padding:14px;
font-size:13px;
line-height:1.75;
overflow:auto;
min-height:250px;
font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}
@media (max-width:980px){
.layout{grid-template-columns:1fr}
}
@media (max-width:720px){
.wrap{padding:22px 14px 34px}
.grid{grid-template-columns:1fr}
.title{font-size:36px}
}
</style>
</head>
<body>
<div class="wrap">
<section class="hero">
<div class="theme-corner">
<select id="themeSelect">
<option value="moon-paper">月白纸页</option>
<option value="mist-cyan">雾青札记</option>
<option value="ink-night">墨蓝夜读</option>
<option value="parchment">羊皮旧卷</option>
<option value="violet-mist">鸢紫薄雾</option>
<option value="clear-blue">晴川映水</option>
<option value="rose-ash">绛雪残笺</option>
</select>
</div>
<div class="hero-card">
<span class="eyebrow">editor</span>
<h1 class="title">nobody's note · editor</h1>
<p class="sub">
在这里写文章,生成新版文章页 HTML 与更新后的 <code>posts.json</code>。
以后发文只要上传新文章文件和新的 <code>posts.json</code>,首页就会自动显示。
</p>
</div>
</section>
<section class="layout">
<section class="panel">
<div class="panel-hd">
<div>
<h2>写作区</h2>
<p>写完后会生成文章页 HTML 与新的 posts.json。</p>
</div>
</div>
<div class="panel-bd">
<div class="grid">
<div class="full">
<label for="postTitle">文章标题</label>
<input id="postTitle" placeholder="例如:夜里想起一些不值得反复回看的东西" />
</div>
<div>
<label for="postDate">日期</label>
<input id="postDate" placeholder="例如:2026-04-05" />
</div>
<div>
<label for="fileName">文章文件名</label>
<input id="fileName" placeholder="例如:night-thoughts.html" />
</div>
<div class="full">
<label for="postExcerpt">首页摘要</label>
<textarea id="postExcerpt" placeholder="写两三句适合显示在首页列表里的摘要。"></textarea>
</div>
<div class="full">
<label for="postBody">正文</label>
<textarea id="postBody" style="min-height:320px;" placeholder="直接写正文。段落之间请空一行。"></textarea>
</div>
<div class="full">
<label for="postsJsonInput">当前 posts.json 内容</label>
<textarea id="postsJsonInput" style="min-height:220px;" placeholder='把你当前的 posts.json 内容粘进来,生成时会自动把新文章插到最前面。'></textarea>
</div>
</div>
<div class="actions">
<button id="generateBtn">生成文章与 posts.json</button>
<button class="secondary" id="copyArticleBtn">复制文章 HTML</button>
<button class="secondary" id="downloadArticleBtn">下载文章 HTML</button>
<button class="secondary" id="copyPostsBtn">复制 posts.json</button>
<button class="secondary" id="downloadPostsBtn">下载 posts.json</button>
</div>
<div class="hint">
正文支持以下格式:<br>
· 段落之间空一行<br>
· <code>img:./images/photo.jpg</code> 插入图片<br>
· <code>---</code> 插入分割线<br>
· <code>## 小标题</code> 插入二级标题<br>
· <code>### 小标题</code> 插入三级标题<br>
· <code>> 引用文字</code> 插入引用块
</div>
</div>
</section>
<section class="panel">
<div class="panel-hd">
<div>
<h2>生成结果</h2>
<p>上面是文章 HTML,下面是更新后的 posts.json。</p>
</div>
</div>
<div class="panel-bd">
<label>文章页 HTML</label>
<pre id="articleOutput"></pre>
<div style="height:14px;"></div>
<label>更新后的 posts.json</label>
<pre id="postsOutput"></pre>
</div>
</section>
</section>
</div>
<script>
const $ = (id) => document.getElementById(id);
const STORAGE_KEY = "nobodys_note_theme";
function applyTheme(theme) {
const finalTheme = theme || "mist-cyan";
document.documentElement.setAttribute("data-theme", finalTheme);
localStorage.setItem(STORAGE_KEY, finalTheme);
$("themeSelect").value = finalTheme;
}
function initTheme() {
const saved = localStorage.getItem(STORAGE_KEY) || "mist-cyan";
applyTheme(saved);
$("themeSelect").addEventListener("change", () => applyTheme($("themeSelect").value));
}
function escapeHtml(str = "") {
return str
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">");
}
function splitParagraphs(text) {
return String(text)
.split(/\n\s*\n/g)
.map(s => s.trim())
.filter(Boolean);
}
function safeJsonParse(text, fallback = null) {
try { return JSON.parse(text); } catch { return fallback; }
}
function isImageLine(line) {
return /^img:(.+)$/i.test(line.trim());
}
function getImagePath(line) {
const m = line.trim().match(/^img:(.+)$/i);
return m ? m[1].trim() : "";
}
function isHrLine(line) {
return /^-{3,}$/.test(line.trim());
}
function isHeading2(line) {
return /^##\s+(.+)$/.test(line.trim());
}
function isHeading3(line) {
return /^###\s+(.+)$/.test(line.trim());
}
function isBlockquote(line) {
return /^>\s+(.+)$/.test(line.trim());
}
function getHeadingText(line, level) {
const re = level === 2 ? /^##\s+(.+)$/ : /^###\s+(.+)$/;
const m = line.trim().match(re);
return m ? m[1].trim() : "";
}
function getQuoteText(line) {
const m = line.trim().match(/^>\s+(.+)$/);
return m ? m[1].trim() : "";
}
function paragraphToHtml(block) {
if (isImageLine(block)) {
const src = getImagePath(block);
return ` <img src="${escapeHtml(src)}" alt="" loading="lazy" />`;
}
if (isHrLine(block)) {
return ` <hr />`;
}
if (isHeading2(block)) {
const text = getHeadingText(block, 2);
return ` <h2>${escapeHtml(text)}</h2>`;
}
if (isHeading3(block)) {
const text = getHeadingText(block, 3);
return ` <h3>${escapeHtml(text)}</h3>`;
}
if (isBlockquote(block)) {
const text = getQuoteText(block);
return ` <blockquote><p>${escapeHtml(text)}</p></blockquote>`;
}
return ` <p>${escapeHtml(block)}</p>`;
}
function buildArticleHtml({ title, date, theme, bodyParagraphs }) {
const bodyHtml = bodyParagraphs.map(p => paragraphToHtml(p)).join("\n\n");
return `<!doctype html>
<html lang="zh-CN" data-theme="${theme}">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>${escapeHtml(title)} · nobody's note</title>
<meta name="robots" content="noindex,nofollow,noarchive" />
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div class="reading-bar" id="readingBar"></div>
<div class="site-wrap reading-page">
<header class="article-header">
<div class="article-topline">
<a class="back-link" href="./index.html">← 返回首页</a>
<span class="article-stamp">archive note</span>
</div>
<h1 class="article-title">${escapeHtml(title)}</h1>
<div class="article-date-row">
<time class="article-date">${escapeHtml(date)}</time>
</div>
</header>
<main class="article-main">
<article class="article-body">
${bodyHtml}
</article>
<nav class="article-pager" id="articlePager"></nav>
</main>
<footer class="site-footer">
<div class="footer-line"></div>
<p>nobody's note</p>
</footer>
</div>
<button class="back-top" id="backTopBtn" title="返回顶部">↑</button>
<script src="./app.js"><\/script>
</body>
</html>`;
}
function download(filename, content, type = "text/plain;charset=utf-8") {
const blob = new Blob([content], { type });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
setTimeout(() => URL.revokeObjectURL(url), 1500);
}
async function copyText(text) {
await navigator.clipboard.writeText(text);
}
function generate() {
const title = $("postTitle").value.trim();
const date = $("postDate").value.trim();
const fileName = $("fileName").value.trim();
const excerpt = $("postExcerpt").value.trim();
const body = $("postBody").value.trim();
const theme = $("themeSelect").value;
const postsRaw = $("postsJsonInput").value.trim();
if (!title || !date || !fileName || !excerpt || !body) {
alert("请先把标题、日期、文件名、摘要和正文都填完整。");
return;
}
if (!postsRaw) {
alert("请先把当前的 posts.json 内容粘进来。");
return;
}
const currentPosts = safeJsonParse(postsRaw, null);
if (!Array.isArray(currentPosts)) {
alert("posts.json 内容格式不正确,必须是 JSON 数组。");
return;
}
const bodyParagraphs = splitParagraphs(body);
const articleHtml = buildArticleHtml({ title, date, theme, bodyParagraphs });
const newItem = {
title,
date,
excerpt,
file: fileName
};
const nextPosts = [
newItem,
...currentPosts.filter(item => item.file !== fileName)
];
$("articleOutput").textContent = articleHtml;
$("postsOutput").textContent = JSON.stringify(nextPosts, null, 2);
}
$("generateBtn").addEventListener("click", generate);
$("copyArticleBtn").addEventListener("click", async () => {
const text = $("articleOutput").textContent.trim();
if (!text) {
alert("请先生成文章 HTML。");
return;
}
await copyText(text);
alert("文章 HTML 已复制。");
});
$("downloadArticleBtn").addEventListener("click", () => {
const text = $("articleOutput").textContent.trim();
const fn = $("fileName").value.trim();
if (!text) {
alert("请先生成文章 HTML。");
return;
}
if (!fn) {
alert("请先填写文章文件名。");
return;
}
download(fn, text, "text/html;charset=utf-8");
});
$("copyPostsBtn").addEventListener("click", async () => {
const text = $("postsOutput").textContent.trim();
if (!text) {
alert("请先生成 posts.json。");
return;
}
await copyText(text);
alert("posts.json 已复制。");
});
$("downloadPostsBtn").addEventListener("click", () => {
const text = $("postsOutput").textContent.trim();
if (!text) {
alert("请先生成 posts.json。");
return;
}
download("posts.json", text, "application/json;charset=utf-8");
});
initTheme();
</script>
</body>
</html>