autoblogger 0.1.14 → 0.1.15
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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -1
- package/dist/index.mjs.map +1 -1
- package/dist/ui.js +33 -23
- package/dist/ui.js.map +1 -1
- package/dist/ui.mjs +33 -23
- package/dist/ui.mjs.map +1 -1
- package/package.json +1 -1
package/dist/ui.mjs
CHANGED
|
@@ -7106,12 +7106,15 @@ function EditorPage({ slug, onEditorStateChange: onEditorStateChangeProp }) {
|
|
|
7106
7106
|
if (!reader) return;
|
|
7107
7107
|
const decoder = new TextDecoder();
|
|
7108
7108
|
let fullContent = "";
|
|
7109
|
+
let titleExtracted = false;
|
|
7110
|
+
let subtitleExtracted = false;
|
|
7111
|
+
let bodyStartIndex = 0;
|
|
7109
7112
|
while (true) {
|
|
7110
7113
|
const { done, value } = await reader.read();
|
|
7111
7114
|
if (done) break;
|
|
7112
7115
|
const chunk = decoder.decode(value, { stream: true });
|
|
7113
|
-
const
|
|
7114
|
-
for (const line of
|
|
7116
|
+
const sseLines = chunk.split("\n");
|
|
7117
|
+
for (const line of sseLines) {
|
|
7115
7118
|
if (line.startsWith("data: ")) {
|
|
7116
7119
|
const data = line.slice(6);
|
|
7117
7120
|
if (data === "[DONE]") continue;
|
|
@@ -7119,35 +7122,42 @@ function EditorPage({ slug, onEditorStateChange: onEditorStateChangeProp }) {
|
|
|
7119
7122
|
const parsed = JSON.parse(data);
|
|
7120
7123
|
if (parsed.text) {
|
|
7121
7124
|
fullContent += parsed.text;
|
|
7122
|
-
|
|
7125
|
+
if (!titleExtracted && fullContent.includes("\n")) {
|
|
7126
|
+
const firstLine = fullContent.split("\n")[0];
|
|
7127
|
+
if (firstLine.startsWith("# ")) {
|
|
7128
|
+
const title = firstLine.slice(2).trim();
|
|
7129
|
+
setPost((prev) => ({ ...prev, title }));
|
|
7130
|
+
titleExtracted = true;
|
|
7131
|
+
bodyStartIndex = firstLine.length + 1;
|
|
7132
|
+
}
|
|
7133
|
+
}
|
|
7134
|
+
if (titleExtracted && !subtitleExtracted) {
|
|
7135
|
+
const afterTitle = fullContent.slice(bodyStartIndex);
|
|
7136
|
+
if (afterTitle.includes("\n")) {
|
|
7137
|
+
const secondLine = afterTitle.split("\n")[0].trim();
|
|
7138
|
+
const italicMatch = secondLine.match(/^\*(.+)\*$/) || secondLine.match(/^_(.+)_$/);
|
|
7139
|
+
if (italicMatch) {
|
|
7140
|
+
const subtitle = italicMatch[1];
|
|
7141
|
+
setPost((prev) => ({ ...prev, subtitle }));
|
|
7142
|
+
subtitleExtracted = true;
|
|
7143
|
+
bodyStartIndex += secondLine.length + 1;
|
|
7144
|
+
} else if (secondLine) {
|
|
7145
|
+
subtitleExtracted = true;
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
7148
|
+
}
|
|
7149
|
+
const bodyContent = fullContent.slice(bodyStartIndex).trim();
|
|
7150
|
+
setPost((prev) => ({ ...prev, markdown: bodyContent }));
|
|
7123
7151
|
}
|
|
7124
7152
|
} catch {
|
|
7125
7153
|
}
|
|
7126
7154
|
}
|
|
7127
7155
|
}
|
|
7128
7156
|
}
|
|
7129
|
-
const
|
|
7130
|
-
let title = "";
|
|
7131
|
-
let subtitle = "";
|
|
7132
|
-
let markdownStart = 0;
|
|
7133
|
-
if (lines[0]?.startsWith("# ")) {
|
|
7134
|
-
title = lines[0].slice(2).trim();
|
|
7135
|
-
markdownStart = 1;
|
|
7136
|
-
const nextLine = lines[1]?.trim();
|
|
7137
|
-
if (nextLine) {
|
|
7138
|
-
const italicMatch = nextLine.match(/^\*(.+)\*$/) || nextLine.match(/^_(.+)_$/);
|
|
7139
|
-
if (italicMatch) {
|
|
7140
|
-
subtitle = italicMatch[1];
|
|
7141
|
-
markdownStart = 2;
|
|
7142
|
-
}
|
|
7143
|
-
}
|
|
7144
|
-
}
|
|
7145
|
-
const remainingMarkdown = lines.slice(markdownStart).join("\n").trim();
|
|
7157
|
+
const finalBody = fullContent.slice(bodyStartIndex).trim();
|
|
7146
7158
|
setPost((prev) => ({
|
|
7147
7159
|
...prev,
|
|
7148
|
-
|
|
7149
|
-
subtitle: subtitle || prev.subtitle,
|
|
7150
|
-
markdown: remainingMarkdown || fullContent
|
|
7160
|
+
markdown: finalBody
|
|
7151
7161
|
}));
|
|
7152
7162
|
} catch (err) {
|
|
7153
7163
|
console.error("Generation error:", err);
|