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/ui.js CHANGED
@@ -7148,12 +7148,15 @@ function EditorPage({ slug, onEditorStateChange: onEditorStateChangeProp }) {
7148
7148
  if (!reader) return;
7149
7149
  const decoder = new TextDecoder();
7150
7150
  let fullContent = "";
7151
+ let titleExtracted = false;
7152
+ let subtitleExtracted = false;
7153
+ let bodyStartIndex = 0;
7151
7154
  while (true) {
7152
7155
  const { done, value } = await reader.read();
7153
7156
  if (done) break;
7154
7157
  const chunk = decoder.decode(value, { stream: true });
7155
- const lines2 = chunk.split("\n");
7156
- for (const line of lines2) {
7158
+ const sseLines = chunk.split("\n");
7159
+ for (const line of sseLines) {
7157
7160
  if (line.startsWith("data: ")) {
7158
7161
  const data = line.slice(6);
7159
7162
  if (data === "[DONE]") continue;
@@ -7161,35 +7164,42 @@ function EditorPage({ slug, onEditorStateChange: onEditorStateChangeProp }) {
7161
7164
  const parsed = JSON.parse(data);
7162
7165
  if (parsed.text) {
7163
7166
  fullContent += parsed.text;
7164
- setPost((prev) => ({ ...prev, markdown: fullContent }));
7167
+ if (!titleExtracted && fullContent.includes("\n")) {
7168
+ const firstLine = fullContent.split("\n")[0];
7169
+ if (firstLine.startsWith("# ")) {
7170
+ const title = firstLine.slice(2).trim();
7171
+ setPost((prev) => ({ ...prev, title }));
7172
+ titleExtracted = true;
7173
+ bodyStartIndex = firstLine.length + 1;
7174
+ }
7175
+ }
7176
+ if (titleExtracted && !subtitleExtracted) {
7177
+ const afterTitle = fullContent.slice(bodyStartIndex);
7178
+ if (afterTitle.includes("\n")) {
7179
+ const secondLine = afterTitle.split("\n")[0].trim();
7180
+ const italicMatch = secondLine.match(/^\*(.+)\*$/) || secondLine.match(/^_(.+)_$/);
7181
+ if (italicMatch) {
7182
+ const subtitle = italicMatch[1];
7183
+ setPost((prev) => ({ ...prev, subtitle }));
7184
+ subtitleExtracted = true;
7185
+ bodyStartIndex += secondLine.length + 1;
7186
+ } else if (secondLine) {
7187
+ subtitleExtracted = true;
7188
+ }
7189
+ }
7190
+ }
7191
+ const bodyContent = fullContent.slice(bodyStartIndex).trim();
7192
+ setPost((prev) => ({ ...prev, markdown: bodyContent }));
7165
7193
  }
7166
7194
  } catch {
7167
7195
  }
7168
7196
  }
7169
7197
  }
7170
7198
  }
7171
- const lines = fullContent.trim().split("\n");
7172
- let title = "";
7173
- let subtitle = "";
7174
- let markdownStart = 0;
7175
- if (lines[0]?.startsWith("# ")) {
7176
- title = lines[0].slice(2).trim();
7177
- markdownStart = 1;
7178
- const nextLine = lines[1]?.trim();
7179
- if (nextLine) {
7180
- const italicMatch = nextLine.match(/^\*(.+)\*$/) || nextLine.match(/^_(.+)_$/);
7181
- if (italicMatch) {
7182
- subtitle = italicMatch[1];
7183
- markdownStart = 2;
7184
- }
7185
- }
7186
- }
7187
- const remainingMarkdown = lines.slice(markdownStart).join("\n").trim();
7199
+ const finalBody = fullContent.slice(bodyStartIndex).trim();
7188
7200
  setPost((prev) => ({
7189
7201
  ...prev,
7190
- title: title || prev.title,
7191
- subtitle: subtitle || prev.subtitle,
7192
- markdown: remainingMarkdown || fullContent
7202
+ markdown: finalBody
7193
7203
  }));
7194
7204
  } catch (err) {
7195
7205
  console.error("Generation error:", err);