Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(content): export the page as Excel and CSV too, files first and the platforms folded under them (#1453)

Cihan62d319cfdf00
diff --git a/web/messages/en.json b/web/messages/en.json
index cdd603617..a4852df17 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -4242,6 +4242,8 @@
"button": "Export",
"hint": "Download the page as it is now",
"docx": "Export Word",
+ "xlsx": "Export Excel",
+ "csv": "Export CSV",
"html": "Export HTML",
"md": "Export Markdown",
"failed": "Couldn't export the page. Try again."
@@ -4388,13 +4390,18 @@
"exportDialog": {
"title": "Export",
"untitled": "Untitled",
- "destination": "Where it goes",
+ "formats": "Files",
+ "platforms": "Platforms",
+ "show": "Show",
+ "hide": "Hide",
"destinations": {
"webflow": "Webflow",
"wordpress": "WordPress",
"shopify": "Shopify",
"docs": "Google Docs",
"docx": "Word",
+ "xlsx": "Excel",
+ "csv": "CSV",
"md": "Markdown",
"html": "HTML"
},
@@ -4404,6 +4411,8 @@
"shopify": "Copy, then paste into the blog post or description editor. The H1 is left out: the title goes in the title field.",
"docs": "Copy, then paste into a new Google Doc.",
"docx": "A Word file, with the page fields in a table on page 1 to delete or keep.",
+ "xlsx": "An Excel sheet with the page as one row for a CMS import: the title in its own column, the page fields, the text and the HTML without the H1. A cell holds up to 32,767 characters: for a long page, CSV keeps the HTML whole.",
+ "csv": "A CSV file with the page as one row for a CMS import: the title in its own column, the page fields, the text and the HTML without the H1.",
"md": "A Markdown file, with the page fields as front matter (the title there, not as an H1).",
"html": "The page's HTML only, for an HTML field or a code view. The page fields are below."
},
@@ -4472,6 +4481,8 @@
"shopify": "Copy for Shopify",
"docs": "Copy for Google Docs",
"docx": "Download Word",
+ "xlsx": "Download Excel",
+ "csv": "Download CSV",
"md": "Download Markdown",
"html": "Copy HTML",
"downloadHtml": "Download HTML"
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
index f3b98fa40..23ee5b599 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
@@ -1519,7 +1519,7 @@ export function DraftEditor({
);
};
- /** Export: the page as Copy HTML gives it, as a Word, HTML or Markdown file. */
+ /** Export: the page as Copy HTML gives it, as a Word, Excel, CSV, HTML or Markdown file. */
const exportPage = async (format: DraftExportFormat) => {
if (!editor) return;
const html = publishableHtml(
@@ -1527,7 +1527,10 @@ export function DraftEditor({
);
const name = title.trim() || t('untitled');
try {
- saveBlob(await draftExportBlob(format, name, html), draftExportFileName(name, format));
+ saveBlob(
+ await draftExportBlob(format, name, html, undefined, draft.sourceUrl),
+ draftExportFileName(name, format),
+ );
} catch (err) {
console.error('Failed to export the page:', err);
toast.error(t('export.failed'));
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.test.tsx
index 0a1c06004..3654048a9 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.test.tsx
@@ -122,7 +122,7 @@ afterEach(() => {
describe('ExportDialog', () => {
it('holds the export while a placeholder is open, and fills it or leaves its sentence out', async () => {
- await render();
+ await render({ initialDestination: 'webflow' });
expect(dialog().querySelector('[role="alert"]')!.textContent).toContain(
'1 placeholder is still open. Exports never contain [ ] text.',
);
@@ -151,6 +151,7 @@ describe('ExportDialog', () => {
it('holds a placeholder in the title or a heading until it is filled', async () => {
await render({
html: '<h2>What [name of a real person] uses</h2><p>Use [figure, source] g.</p>',
+ initialDestination: 'webflow',
});
await act(async () => button('Export without them')!.click());
expect(dialog().querySelector('[role="status"]')!.textContent).toContain(
@@ -178,7 +179,7 @@ describe('ExportDialog', () => {
it('copies as HTML, and says so, where rich text is refused', async () => {
vi.stubGlobal('ClipboardItem', undefined);
document.execCommand = vi.fn(() => false);
- await render({ html: '<h1>Pour-over</h1><p>Done.</p>' });
+ await render({ html: '<h1>Pour-over</h1><p>Done.</p>', initialDestination: 'webflow' });
await act(async () => button('Copy for Webflow')!.click());
expect(writeText).toHaveBeenCalledWith('<p>Done.</p>');
expect(toast.success).toHaveBeenCalledWith(
@@ -269,15 +270,15 @@ describe('ExportDialog', () => {
// The dialog moves focus in after it opens: once it has, it won't take
// focus back from the arrow keys (it did on a busy machine).
await vi.waitFor(() => expect(dialog().contains(document.activeElement)).toBe(true));
- // Arrow keys move along the destinations.
- destination('Webflow').focus();
+ // Arrow keys move along the files, from Word back round to Markdown.
+ destination('Word').focus();
await act(async () => {
- destination('Webflow').dispatchEvent(
+ destination('Word').dispatchEvent(
new KeyboardEvent('keydown', { key: 'ArrowLeft', bubbles: true }),
);
});
- expect(destination('HTML').getAttribute('aria-checked')).toBe('true');
- expect(document.activeElement).toBe(destination('HTML'));
+ expect(destination('Markdown').getAttribute('aria-checked')).toBe('true');
+ expect(document.activeElement).toBe(destination('Markdown'));
await act(async () => destination('Word').click());
expect(dialog().textContent).toContain(
'A Word file, with the page fields in a table on page 1',
@@ -304,6 +305,96 @@ describe('ExportDialog', () => {
expect(fields.front).not.toHaveProperty('lastmod');
});
+ it('lists the files first, each with its icon, and the platforms folded under them', async () => {
+ await render({ html: '<p>Done.</p>' });
+ const files = dialog().querySelector('[role="radiogroup"][aria-label="Files"]')!;
+ expect([...files.querySelectorAll('[role="radio"]')].map((r) => r.textContent)).toEqual([
+ 'Word',
+ 'Excel',
+ 'CSV',
+ 'HTML',
+ 'Markdown',
+ ]);
+ expect(files.querySelectorAll('[role="radio"] svg')).toHaveLength(5);
+ // Word to start with, the platforms folded away.
+ expect(destination('Word').getAttribute('aria-checked')).toBe('true');
+ const bar = dialog().querySelector<HTMLButtonElement>('button[aria-expanded]')!;
+ expect(bar.textContent).toBe('PlatformsShow');
+ expect(bar.getAttribute('aria-expanded')).toBe('false');
+ const platforms = dialog().querySelector<HTMLElement>(
+ '[role="radiogroup"][aria-label="Platforms"]',
+ )!;
+ expect(platforms.parentElement!.hidden).toBe(true);
+
+ await act(async () => bar.click());
+ expect(bar.getAttribute('aria-expanded')).toBe('true');
+ expect(bar.textContent).toBe('PlatformsHide');
+ expect(platforms.parentElement!.hidden).toBe(false);
+ expect([...platforms.querySelectorAll('[role="radio"]')].map((r) => r.textContent)).toEqual([
+ 'Webflow',
+ 'WordPress',
+ 'Shopify',
+ 'Google Docs',
+ ]);
+ // Each with its logo.
+ expect(platforms.querySelectorAll('img')).toHaveLength(4);
+ await act(async () => destination('WordPress').click());
+ expect(button('Copy for WordPress')).toBeDefined();
+ // Folded again, the platform picked is still named.
+ await act(async () => bar.click());
+ expect(bar.textContent).toBe('PlatformsWordPressShow');
+ });
+
+ it('opens on the platforms when one was picked last, focus on it', async () => {
+ localStorage.setItem('aeo:content-export-destination', 'shopify');
+ await render({ html: '<p>Done.</p>' });
+ const bar = dialog().querySelector<HTMLButtonElement>('button[aria-expanded]')!;
+ expect(bar.getAttribute('aria-expanded')).toBe('true');
+ expect(destination('Shopify').getAttribute('aria-checked')).toBe('true');
+ // Focus starts on it: Enter keeps Shopify, not the first file.
+ await vi.waitFor(() => expect(document.activeElement).toBe(destination('Shopify')));
+ // Each row is its own group: the files' tab stop is their first.
+ expect(destination('Word').tabIndex).toBe(0);
+ expect(destination('Excel').tabIndex).toBe(-1);
+ // Arrow keys go round the platforms, never into the files.
+ await act(async () => {
+ destination('Shopify').dispatchEvent(
+ new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true }),
+ );
+ });
+ expect(destination('Google Docs').getAttribute('aria-checked')).toBe('true');
+ await act(async () => {
+ destination('Google Docs').dispatchEvent(
+ new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true }),
+ );
+ });
+ expect(destination('Webflow').getAttribute('aria-checked')).toBe('true');
+ expect(document.activeElement).toBe(destination('Webflow'));
+ });
+
+ it('downloads Excel and CSV with the page fields', async () => {
+ await render({ html: '<p>Done.</p>' });
+ await act(async () => destination('Excel').click());
+ expect(dialog().textContent).toContain('An Excel sheet with the page as one row');
+ await act(async () => button('Download Excel')!.click());
+ expect(draftExportBlob).toHaveBeenLastCalledWith(
+ 'xlsx',
+ 'Pour-over',
+ '<p>Done.</p>',
+ expect.objectContaining({ front: expect.objectContaining({ slug: 'pour-over' }) }),
+ );
+ expect(saveBlob).toHaveBeenLastCalledWith(expect.any(Blob), 'ansvisor_content_pour-over.xlsx');
+ await act(async () => destination('CSV').click());
+ await act(async () => button('Download CSV')!.click());
+ expect(draftExportBlob).toHaveBeenLastCalledWith(
+ 'csv',
+ 'Pour-over',
+ '<p>Done.</p>',
+ expect.anything(),
+ );
+ expect(saveBlob).toHaveBeenLastCalledWith(expect.any(Blob), 'ansvisor_content_pour-over.csv');
+ });
+
it("dates a live page's Markdown as updated today, keeping its published date", async () => {
await render({
html: '<p>Done.</p>',
@@ -321,7 +412,11 @@ describe('ExportDialog', () => {
it("puts the brand's byline line under the H1, not in the page fields", async () => {
vi.stubGlobal('ClipboardItem', undefined);
document.execCommand = vi.fn(() => false);
- await render({ html: '<h1>Pour-over</h1><p>Done.</p>', byline: 'By Ada Lovelace' });
+ await render({
+ html: '<h1>Pour-over</h1><p>Done.</p>',
+ byline: 'By Ada Lovelace',
+ initialDestination: 'webflow',
+ });
await act(async () => button('Copy for Webflow')!.click());
expect(writeText).toHaveBeenCalledWith('<p>By Ada Lovelace</p><p>Done.</p>');
expect(dialog().textContent).toContain('Meta descriptionDone.');
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.tsx
index 990e2397d..c1e8605a8 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-dialog.tsx
@@ -1,9 +1,10 @@
'use client';
-import { useMemo, useRef, useState, type KeyboardEvent } from 'react';
+import { useId, useMemo, useRef, useState, type KeyboardEvent } from 'react';
+import Image from 'next/image';
import { useTranslations } from 'next-intl';
import { toast } from 'sonner';
-import { AlertTriangle, Check } from 'lucide-react';
+import { AlertTriangle, Check, ChevronDown, Globe } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
Dialog,
@@ -15,6 +16,7 @@ import {
} from '@/components/ui/dialog';
import type { ContentAuthor } from '@/lib/content/authors';
import {
+ DRAFT_EXPORT_FORMATS,
draftExportBlob,
draftExportFileName,
draftText,
@@ -31,14 +33,37 @@ import {
withoutPlaceholders,
type PasteChecks,
} from '@/lib/content/ready-to-publish';
+import { ExportFormatIcon } from '@/components/content/export-format-icon';
import { saveBlob } from '@/lib/download';
+import { getFaviconUrl } from '@/lib/favicon';
import { cn } from '@/lib/utils';
import { copyToClipboard } from './_html-block';
-/** Where the page goes (Quality spec §7b), and how: pasted rich, downloaded, or as HTML. */
-const DESTINATIONS = ['webflow', 'wordpress', 'shopify', 'docs', 'docx', 'md', 'html'] as const;
+/**
+ * Where the page goes (Quality spec §7b), and how: a file to save (Word,
+ * Excel, CSV, Markdown; HTML copied, or saved), or pasted rich into a
+ * platform's editor. The platforms fold away under the files: more come as
+ * integrations land.
+ */
+const PLATFORMS = ['webflow', 'wordpress', 'shopify', 'docs'] as const;
+type Platform = (typeof PLATFORMS)[number];
+const DESTINATIONS = [...DRAFT_EXPORT_FORMATS, ...PLATFORMS] as const;
export type ExportDestination = (typeof DESTINATIONS)[number];
-const FILES: Partial<Record<ExportDestination, DraftExportFormat>> = { docx: 'docx', md: 'md' };
+const FILES: Partial<Record<ExportDestination, DraftExportFormat>> = {
+ docx: 'docx',
+ xlsx: 'xlsx',
+ csv: 'csv',
+ md: 'md',
+};
+/** Each platform's site, for its logo (its favicon, as citations show sites). */
+const PLATFORM_SITES: Record<Platform, string> = {
+ webflow: 'webflow.com',
+ wordpress: 'wordpress.org',
+ shopify: 'shopify.com',
+ docs: 'docs.google.com',
+};
+const isPlatform = (d: ExportDestination): d is Platform =>
+ (PLATFORMS as readonly string[]).includes(d);
/**
* Destinations whose title field holds the page's title: its H1 isn't in
* the content too (Markdown's front matter has it: draftMarkdown leaves it out).
@@ -57,7 +82,34 @@ function storedDestination(): ExportDestination {
} catch {
// Storage unavailable: the first one.
}
- return 'webflow';
+ return 'docx';
+}
+
+/** A destination's mark: a file's icon in its colour (the pill's own when picked), a platform's logo. */
+function DestinationIcon({
+ destination,
+ picked,
+}: {
+ destination: ExportDestination;
+ picked: boolean;
+}) {
+ const [failed, setFailed] = useState(false);
+ if (isPlatform(destination)) {
+ // Its logo didn't load (blocked, offline): a globe, as a site's favicon falls back to.
+ if (failed) return <Globe aria-hidden className="h-3.5 w-3.5 shrink-0" />;
+ return (
+ <Image
+ src={getFaviconUrl(PLATFORM_SITES[destination], 32)}
+ alt=""
+ width={14}
+ height={14}
+ unoptimized
+ className="h-3.5 w-3.5 rounded-sm bg-white object-contain"
+ onError={() => setFailed(true)}
+ />
+ );
+ }
+ return <ExportFormatIcon format={destination} plain={picked} />;
}
/**
@@ -145,7 +197,10 @@ export function ExportDialog({
() => initialDestination ?? storedDestination(),
);
const [skipPlaceholders, setSkipPlaceholders] = useState(false);
- const radios = useRef<(HTMLButtonElement | null)[]>([]);
+ // Open when the page goes to a platform; folded away otherwise.
+ const [platformsOpen, setPlatformsOpen] = useState(() => isPlatform(destination));
+ const platformsId = useId();
+ const radios = useRef<Partial<Record<ExportDestination, HTMLButtonElement | null>>>({});
const placeholders = useMemo(
() => exportPlaceholders(html) + titlePlaceholders(title, html),
[html, title],
@@ -182,17 +237,43 @@ export function ExportDialog({
// The choice just won't be remembered.
}
};
- // Arrow keys move along the destinations, as in any radio group.
- const onRadioKey = (event: KeyboardEvent, i: number) => {
+ // Arrow keys move along a row's destinations, as in any radio group.
+ const onRadioKey = (event: KeyboardEvent, row: readonly ExportDestination[], i: number) => {
const step = ({ ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 } as const)[
event.key as 'ArrowRight'
];
if (!step) return;
event.preventDefault();
- const next = (i + step + DESTINATIONS.length) % DESTINATIONS.length;
- pick(DESTINATIONS[next]);
+ const next = row[(i + step + row.length) % row.length];
+ pick(next);
radios.current[next]?.focus();
};
+ // A row of destinations: one radio group, its picked one (else its first) the tab stop.
+ const radioRow = (row: readonly ExportDestination[], label: string) => (
+ <div role="radiogroup" aria-label={label} className="flex flex-wrap gap-1.5">
+ {row.map((d, i) => (
+ <button
+ key={d}
+ ref={(el) => void (radios.current[d] = el)}
+ type="button"
+ role="radio"
+ aria-checked={d === destination}
+ tabIndex={(row.includes(destination) ? d === destination : i === 0) ? 0 : -1}
+ onClick={() => pick(d)}
+ onKeyDown={(event) => onRadioKey(event, row, i)}
+ className={cn(
+ 'inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs font-medium',
+ d === destination
+ ? 'border-foreground bg-foreground text-background'
+ : 'bg-card text-muted-foreground hover:text-foreground',
+ )}
+ >
+ <DestinationIcon destination={d} picked={d === destination} />
+ {t(`destinations.${d}`)}
+ </button>
+ ))}
+ </div>
+ );
const exportFields: ExportFields = {
table: {
note: t('fields.note'),
@@ -336,34 +417,54 @@ export function ExportDialog({
return (
<Dialog open onOpenChange={(open) => !open && onClose()}>
- <DialogContent className="max-h-[calc(100dvh-2rem)] overflow-y-auto sm:max-w-xl">
+ <DialogContent
+ className="max-h-[calc(100dvh-2rem)] overflow-y-auto sm:max-w-xl"
+ // Focus starts on the destination picked, as a radio group's does:
+ // Enter or Space then keeps it, not the first file's.
+ initialFocus={() => radios.current[destination] ?? true}
+ >
<DialogHeader>
<DialogTitle>{t('title')}</DialogTitle>
</DialogHeader>
- <div className="space-y-1.5">
- <div role="radiogroup" aria-label={t('destination')} className="flex flex-wrap gap-1.5">
- {DESTINATIONS.map((d, i) => (
+ <div className="space-y-2">
+ {radioRow(DRAFT_EXPORT_FORMATS, t('formats'))}
+ <section
+ aria-labelledby={`${platformsId}-title`}
+ className="overflow-hidden rounded-xl border"
+ >
+ {/* The whole bar opens it: "Show" and a chevron pointing down say so. */}
+ <h3 className="text-xs font-medium">
<button
- key={d}
- ref={(el) => void (radios.current[i] = el)}
type="button"
- role="radio"
- aria-checked={d === destination}
- tabIndex={d === destination ? 0 : -1}
- onClick={() => pick(d)}
- onKeyDown={(event) => onRadioKey(event, i)}
- className={cn(
- 'rounded-full border px-2.5 py-1 text-xs font-medium',
- d === destination
- ? 'border-foreground bg-foreground text-background'
- : 'bg-card text-muted-foreground hover:text-foreground',
- )}
+ aria-expanded={platformsOpen}
+ aria-controls={platformsId}
+ onClick={() => setPlatformsOpen((open) => !open)}
+ className="group flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left transition-colors hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:outline-none focus-visible:ring-inset"
>
- {t(`destinations.${d}`)}
+ <span id={`${platformsId}-title`}>{t('platforms')}</span>
+ {/* Folded, the platform picked is still named. */}
+ {!platformsOpen && isPlatform(destination) && (
+ <span className="font-normal text-muted-foreground">
+ {t(`destinations.${destination}`)}
+ </span>
+ )}
+ <span className="ml-auto flex items-center gap-1 text-foreground group-hover:underline">
+ {platformsOpen ? t('hide') : t('show')}
+ <ChevronDown
+ aria-hidden
+ className={cn(
+ 'h-4 w-4 shrink-0 transition-transform',
+ platformsOpen && 'rotate-180',
+ )}
+ />
+ </span>
</button>
- ))}
- </div>
+ </h3>
+ <div id={platformsId} hidden={!platformsOpen} className="px-3 pb-2.5">
+ {radioRow(PLATFORMS, t('platforms'))}
+ </div>
+ </section>
<DialogDescription className="text-xs">{t(`hints.${destination}`)}</DialogDescription>
</div>
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-menu.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-menu.tsx
index 3a454daf3..221e8aaba 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-menu.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_export-menu.tsx
@@ -1,7 +1,7 @@
'use client';
import { useTranslations } from 'next-intl';
-import { ChevronDown, Download, FileCode, FileText, FileType } from 'lucide-react';
+import { ChevronDown, Download } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
@@ -9,18 +9,14 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
-import type { DraftExportFormat } from '@/lib/content/draft-export';
-
-const FORMATS = [
- { format: 'docx', icon: FileType },
- { format: 'html', icon: FileCode },
- { format: 'md', icon: FileText },
-] as const satisfies readonly { format: DraftExportFormat; icon: unknown }[];
+import { ExportFormatIcon } from '@/components/content/export-format-icon';
+import { DRAFT_EXPORT_FORMATS, type DraftExportFormat } from '@/lib/content/draft-export';
/**
- * Export in the editor's header: the page as written now, as Word, HTML or
- * Markdown. Labelled from a tablet's width up, so it is there to find; an
- * icon on a phone, where the header's one row has no room for the word.
+ * Export in the editor's header: the page as written now, as Word, Excel,
+ * CSV, HTML or Markdown. Labelled from a tablet's width up, so it is there
+ * to find; an icon on a phone, where the header's one row has no room for
+ * the word.
*/
export function ExportMenu({
disabled,
@@ -43,9 +39,9 @@ export function ExportMenu({
<ChevronDown className="hidden h-3.5 w-3.5 text-muted-foreground sm:block" />
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-48">
- {FORMATS.map(({ format, icon: Icon }) => (
+ {DRAFT_EXPORT_FORMATS.map((format) => (
<DropdownMenuItem key={format} className="gap-2" onClick={() => onExport(format)}>
- <Icon className="h-3.5 w-3.5" />
+ <ExportFormatIcon format={format} />
{t(format)}
</DropdownMenuItem>
))}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
index 11cf41652..57e4f8cf7 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
@@ -1755,10 +1755,12 @@ describe('the content editor', () => {
const items = [...document.querySelectorAll<HTMLElement>('[role="menuitem"]')];
expect(items.map((i) => i.textContent)).toEqual([
'Export Word',
+ 'Export Excel',
+ 'Export CSV',
'Export HTML',
'Export Markdown',
]);
- await act(async () => items[2].click());
+ await act(async () => items[4].click());
await act(async () => {});
expect(saveBlob).toHaveBeenCalledTimes(1);
@@ -3440,7 +3442,7 @@ describe('the side panel', () => {
expect(dialog()!.textContent).toContain('Content · ready to paste');
expect(dialog()!.textContent).toContain('Meta titlePipeline forecasting');
expect(dialog()!.textContent).toContain('AuthorAcme Team → your CMS author field');
- expect(inDialog('Copy for Webflow').disabled).toBe(false);
+ expect(inDialog('Download Word').disabled).toBe(false);
});
it('names the team in the page’s language in the CMS author field', async () => {
@@ -3547,7 +3549,7 @@ describe('the side panel', () => {
expect(dialog()!.textContent).toContain(ready);
await act(async () => inDialog('Continue to export').click());
expect(dialog()!.querySelector('[role="alert"]')).toBeNull();
- expect(inDialog('Copy for Webflow').disabled).toBe(false);
+ expect(inDialog('Download Word').disabled).toBe(false);
await act(async () => inDialog('Cancel').click());
await act(async () => button('Mark ready')!.click());
expect(dialog()!.textContent).toContain(ready);
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/library/_library-export.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/library/_library-export.tsx
index d1473a31a..5769fa88b 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/library/_library-export.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/library/_library-export.tsx
@@ -3,7 +3,8 @@
import { useState } from 'react';
import { useTranslations } from 'next-intl';
import { toast } from 'sonner';
-import { ChevronDown, Download, FileSpreadsheet, FileText, FileType } from 'lucide-react';
+import { ChevronDown, Download } from 'lucide-react';
+import { ExportFormatIcon } from '@/components/content/export-format-icon';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
@@ -36,8 +37,8 @@ import { saveBlob } from '@/lib/download';
/**
* The Library's Export (CE-002): the drafts listed (the tab, within the
- * Created range) with their pages, as CSV, an Excel sheet or one Word
- * document; and one draft from its row, as the editor's Export does.
+ * Created range) with their pages, as one Word document, an Excel sheet or
+ * a CSV; and one draft from its row, as the editor's Export does.
*/
export function useLibraryExport(brandId: string | null) {
const t = useTranslations('contentEditor.library');
@@ -117,7 +118,13 @@ export function useLibraryExport(brandId: string | null) {
if (!page) throw new Error('not_found');
const title = titleOf(draft);
saveBlob(
- await draftExportBlob(format, title, publishableHtml(page.bodyHtml)),
+ await draftExportBlob(
+ format,
+ title,
+ publishableHtml(page.bodyHtml),
+ undefined,
+ page.sourceUrl,
+ ),
draftExportFileName(title, format),
);
} catch (err) {
@@ -129,13 +136,10 @@ export function useLibraryExport(brandId: string | null) {
return { exporting, exportList, exportDraft };
}
-const FORMATS = [
- { format: 'csv', icon: FileText },
- { format: 'xlsx', icon: FileSpreadsheet },
- { format: 'docx', icon: FileType },
-] as const satisfies readonly { format: LibraryExportFormat; icon: unknown }[];
+/** The formats, in the order the editor's Export lists them. */
+const FORMATS = ['docx', 'xlsx', 'csv'] as const satisfies readonly LibraryExportFormat[];
-/** Export in the Library's header: the drafts listed, as CSV, Excel or Word. */
+/** Export in the Library's header: the drafts listed, as Word, Excel or CSV. */
export function LibraryExportMenu({
disabled,
exporting,
@@ -158,9 +162,9 @@ export function LibraryExportMenu({
<ChevronDown className="h-3.5 w-3.5 text-muted-foreground" />
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-44">
- {FORMATS.map(({ format, icon: Icon }) => (
+ {FORMATS.map((format) => (
<DropdownMenuItem key={format} className="gap-2" onClick={() => onExport(format)}>
- <Icon className="h-3.5 w-3.5" />
+ <ExportFormatIcon format={format} />
{t(format)}
</DropdownMenuItem>
))}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/library/_library-table.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/library/_library-table.tsx
index 72ccb6ebf..9a97d84ac 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/library/_library-table.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/library/_library-table.tsx
@@ -8,7 +8,6 @@ import {
Bot,
Check,
Clock,
- Download,
ExternalLink,
FileText,
MoreHorizontal,
@@ -16,6 +15,7 @@ import {
Trash2,
} from 'lucide-react';
import { Link } from '@/i18n/navigation';
+import { ExportFormatIcon } from '@/components/content/export-format-icon';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Badge } from '@/components/ui/badge';
import { Checkbox } from '@/components/ui/checkbox';
@@ -52,7 +52,7 @@ import {
type LibraryTab,
} from '@/lib/content/drafts';
import type { CmsStatus } from '@/lib/content/cms-send-client';
-import type { DraftExportFormat } from '@/lib/content/draft-export';
+import { DRAFT_EXPORT_FORMATS, type DraftExportFormat } from '@/lib/content/draft-export';
import { formatDate, formatMonthDay } from '@/lib/format';
/** A date this year as "Oct 16", an older one with its year, so the table fits at 1024 px. */
@@ -249,9 +249,9 @@ function RowMenu({ draft, actions }: { draft: ContentDraftListItem; actions: Lib
))}
</DropdownMenuGroup>
<DropdownMenuSeparator />
- {(['docx', 'html', 'md'] as const).map((format) => (
+ {DRAFT_EXPORT_FORMATS.map((format) => (
<DropdownMenuItem key={format} onClick={() => actions.onExport(draft, format)}>
- <Download className="h-4 w-4" />
+ <ExportFormatIcon format={format} className="h-4 w-4" />
{tExport(format)}
</DropdownMenuItem>
))}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx
index 09a27f61e..1c615198e 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx
@@ -667,6 +667,8 @@ describe('a Library row’s menu (00233)', () => {
'Ready',
'Published',
'Export Word',
+ 'Export Excel',
+ 'Export CSV',
'Export HTML',
'Export Markdown',
'Send to CMS',
@@ -694,6 +696,8 @@ describe('a Library row’s menu (00233)', () => {
'Ready',
'Published',
'Export Word',
+ 'Export Excel',
+ 'Export CSV',
'Export HTML',
'Export Markdown',
]);
@@ -761,6 +765,19 @@ describe('a Library row’s menu (00233)', () => {
expect(await readText(blob)).toBe('# Pipeline forecasting\n\nTeams trust it.\n');
});
+ it("gives an optimize draft's CSV the live page's slug, for a CMS import to update it", async () => {
+ getContentDrafts.mockResolvedValue([row({})]);
+ await renderPage();
+ await pick('Pipeline forecasting', 'Export CSV');
+ await act(async () => {});
+ const [blob, name] = saveBlob.mock.calls[0] as [Blob, string];
+ expect(name).toBe('ansvisor_content_pipeline-forecasting.csv');
+ const [header, line] = (await readText(blob)).replace(/^\uFEFF/, '').split('\n');
+ expect(header.split(',')[3]).toBe('Slug');
+ // Title, Meta title, Meta description, then the live page's slug.
+ expect(line).toMatch(/^Pipeline forecasting,Pipeline forecasting,Teams trust it\.,pricing,/);
+ });
+
it('says so when the server refuses the archive', async () => {
archiveContentDraft.mockRejectedValue(new Error('forbidden'));
getContentDrafts.mockResolvedValue([row({})]);
@@ -783,6 +800,8 @@ describe('the Library’s Export and Created filter (CE-002)', () => {
});
return [...document.body.querySelectorAll<HTMLElement>('[role="menuitem"]')];
};
+ /** CSV: the quickest of the files to write. */
+ const csvItem = (items: HTMLElement[]) => items.find((el) => el.textContent === 'Export CSV')!;
it('reads a long list’s pages fifty at a time, in order', async () => {
getContentDrafts.mockResolvedValue(
@@ -790,7 +809,7 @@ describe('the Library’s Export and Created filter (CE-002)', () => {
);
await renderPage();
const items = await openExport();
- await act(async () => items[0].click());
+ await act(async () => csvItem(items).click());
await act(async () => {});
const calls = getContentDraftPages.mock.calls as [string, string[]][];
@@ -818,7 +837,7 @@ describe('the Library’s Export and Created filter (CE-002)', () => {
}));
await renderPage();
const items = await openExport();
- await act(async () => items[0].click());
+ await act(async () => csvItem(items).click());
await act(async () => {});
const calls = getContentDraftPages.mock.calls as [string, string[]][];
@@ -838,11 +857,11 @@ describe('the Library’s Export and Created filter (CE-002)', () => {
await renderPage();
const items = await openExport();
expect(items.map((el) => el.textContent)).toEqual([
- 'Export CSV',
- 'Export Excel',
'Export Word',
+ 'Export Excel',
+ 'Export CSV',
]);
- await act(async () => items[0].click());
+ await act(async () => csvItem(items).click());
await act(async () => {});
expect(getContentDraftPages).toHaveBeenCalledWith('brand-1', ['d1', 'd2']);
@@ -868,7 +887,7 @@ describe('the Library’s Export and Created filter (CE-002)', () => {
expect(container.textContent).not.toContain('Old page');
const items = await openExport();
- await act(async () => items[0].click());
+ await act(async () => csvItem(items).click());
await act(async () => {});
expect(getContentDraftPages).toHaveBeenCalledWith('brand-1', ['new']);
});
diff --git a/web/src/components/content/export-format-icon.tsx b/web/src/components/content/export-format-icon.tsx
new file mode 100644
index 000000000..0f2ed462d
--- /dev/null
+++ b/web/src/components/content/export-format-icon.tsx
@@ -0,0 +1,37 @@
+import {
+ FileCode,
+ FileSpreadsheet,
+ FileText,
+ FileType,
+ Sheet,
+ type LucideIcon,
+} from 'lucide-react';
+import type { DraftExportFormat } from '@/lib/content/draft-export';
+import { cn } from '@/lib/utils';
+
+/** Each export format's icon, in the colour its app is known by. */
+const FORMAT_ICONS: Record<DraftExportFormat, { icon: LucideIcon; className: string }> = {
+ docx: { icon: FileType, className: 'text-blue-600 dark:text-blue-400' },
+ xlsx: { icon: FileSpreadsheet, className: 'text-emerald-600 dark:text-emerald-400' },
+ csv: { icon: Sheet, className: 'text-teal-600 dark:text-teal-400' },
+ html: { icon: FileCode, className: 'text-orange-600 dark:text-orange-400' },
+ md: { icon: FileText, className: 'text-muted-foreground' },
+};
+
+/**
+ * An export format's icon, wherever a page or a list is exported (the
+ * editor's Export, the Library's): in its colour, or in the text's own on a
+ * picked pill (`plain`).
+ */
+export function ExportFormatIcon({
+ format,
+ plain = false,
+ className,
+}: {
+ format: DraftExportFormat;
+ plain?: boolean;
+ className?: string;
+}) {
+ const { icon: Icon, className: colour } = FORMAT_ICONS[format];
+ return <Icon aria-hidden className={cn('h-3.5 w-3.5 shrink-0', !plain && colour, className)} />;
+}
diff --git a/web/src/lib/content/draft-export.test.ts b/web/src/lib/content/draft-export.test.ts
index b5525ce7f..bc60b38ff 100644
--- a/web/src/lib/content/draft-export.test.ts
+++ b/web/src/lib/content/draft-export.test.ts
@@ -13,6 +13,9 @@ import {
libraryExportFileName,
libraryRows,
libraryWorkbook,
+ pageCsv,
+ pageSheetRow,
+ pageWorkbook,
type LibraryExportItem,
} from './draft-export';
@@ -223,6 +226,78 @@ describe('draftExportBlob and draftExportFileName', () => {
);
expect(draftExportFileName('—', 'md')).toBe('ansvisor_content_page.md');
});
+
+ it('gives CSV marked as UTF-8 for Excel, and Excel as a workbook', async () => {
+ const csv = await draftExportBlob('csv', 'T', '<h1>T</h1><p>Ünlü.</p>');
+ expect(csv.type).toBe('text/csv;charset=utf-8;');
+ const bytes = await read(csv);
+ expect([...bytes.slice(0, 3)]).toEqual([0xef, 0xbb, 0xbf]);
+ expect(strFromU8(bytes.slice(3))).toContain('Ünlü.');
+ const xlsx = await draftExportBlob('xlsx', 'T', '<h1>T</h1><p>Done.</p>');
+ const files = unzipSync(await read(xlsx));
+ expect(Object.keys(files)).toContain('xl/workbook.xml');
+ expect(draftExportFileName('T', 'xlsx')).toBe('ansvisor_content_t.xlsx');
+ });
+});
+
+describe('one page as a spreadsheet row (Excel, CSV)', () => {
+ const fields = {
+ table: { note: '', rows: [] as [string, string][] },
+ front: {
+ title: 'Pipeline forecasting: a guide',
+ description: 'How teams forecast.',
+ slug: 'pipeline-forecasting',
+ author: 'Ada Lovelace',
+ image: 'https://acme.example/cover.png',
+ },
+ head: { title: '', description: '', author: '' },
+ };
+
+ it('holds the title, the page fields, its words and its HTML without the H1', () => {
+ expect(pageSheetRow('Pipeline forecasting', PAGE, fields)).toMatchObject({
+ Title: 'Pipeline forecasting',
+ 'Meta title': 'Pipeline forecasting: a guide',
+ 'Meta description': 'How teams forecast.',
+ Slug: 'pipeline-forecasting',
+ Author: 'Ada Lovelace',
+ 'Featured image': 'https://acme.example/cover.png',
+ Content: expect.stringMatching(
+ /^Teams trust it, every week\. See our pricing\.\nHow it works\n/,
+ ),
+ HTML: expect.stringMatching(/^<p>Teams <strong>trust<\/strong>/),
+ });
+ // Without Export's fields (the Library's row, the header's menu): read
+ // from the page as Export reads them, with no author.
+ expect(pageSheetRow('Pour-over guide', '<p>Done.</p>')).toMatchObject({
+ 'Meta title': 'Pour-over guide',
+ 'Meta description': 'Done.',
+ Slug: 'pour-over-guide',
+ Author: '',
+ Characters: 5,
+ });
+ // An optimize draft's slug is its live page's: a CMS import updates it.
+ expect(
+ pageSheetRow('Pour-over guide', '<p>Done.</p>', undefined, 'https://acme.com/blog/pour-over/')
+ .Slug,
+ ).toBe('pour-over');
+ // A list's items with "•": a cell starting "-" would be read as a formula.
+ expect(pageSheetRow('T', '<h1>T</h1><ul><li>HubSpot</li></ul>').Content).toBe('• HubSpot');
+ expect(pageCsv('T', '<h1>T</h1><ul><li>HubSpot</li></ul>')).toContain(',• HubSpot,');
+ });
+
+ it('writes CSV with its header, and Excel with a cell cut at its limit', () => {
+ const csv = pageCsv('T', '<p>Done.</p>', fields);
+ expect(csv.split('\n')[0]).toBe(
+ 'Title,Meta title,Meta description,Slug,Author,Featured image,Characters,Content,HTML',
+ );
+ expect(csv).toContain('<p>Done.</p>');
+ const long = `<p>${'x'.repeat(40_000)}</p>`;
+ const [{ data }] = pageWorkbook('T', long, fields);
+ expect(data[0][0]).toEqual({ value: 'Title', fontWeight: 'bold' });
+ const content = data[1][7] as string;
+ expect(content).toHaveLength(32_767);
+ expect(content.endsWith('…')).toBe(true);
+ });
});
describe('the Library’s Export', () => {
diff --git a/web/src/lib/content/draft-export.ts b/web/src/lib/content/draft-export.ts
index b73559f95..d36befe51 100644
--- a/web/src/lib/content/draft-export.ts
+++ b/web/src/lib/content/draft-export.ts
@@ -1,18 +1,31 @@
import type { Sheet } from 'write-excel-file/browser';
+import { BYTE_ORDER_MARK } from '@/lib/action-center/export';
import { toCsv } from '@/lib/csv';
import { slugify } from '@/lib/slug';
import { safeLinkHref } from './editor';
+import { pageFields, withoutLeadingH1 } from './ready-to-publish';
/**
- * Export in the Content Editor: the page as Word, HTML or Markdown, from the
- * HTML Copy HTML gives (publishableHtml). HTML is that page as a document of
- * its own. Word and Markdown read it as blocks first: headings, paragraphs,
- * quotes, lists, tables, and anything else an HTML block holds. Markdown keeps
- * that last as HTML, Word keeps its text. The schema JSON-LD is the page's
- * markup, not its text, so only the HTML file carries it.
+ * Export in the Content Editor: the page as Word, Excel, CSV, HTML or
+ * Markdown, from the HTML Copy HTML gives (publishableHtml). HTML is that
+ * page as a document of its own. Word and Markdown read it as blocks first:
+ * headings, paragraphs, quotes, lists, tables, and anything else an HTML
+ * block holds. Markdown keeps that last as HTML, Word keeps its text. Excel
+ * and CSV hold the page as one row, for a CMS's import (pageSheetRow). The
+ * schema JSON-LD is the page's markup, not its text, so only the HTML file
+ * carries it.
*/
-export type DraftExportFormat = 'docx' | 'html' | 'md';
+export type DraftExportFormat = 'docx' | 'xlsx' | 'csv' | 'html' | 'md';
+
+/** The formats, in the order Export lists them. */
+export const DRAFT_EXPORT_FORMATS = [
+ 'docx',
+ 'xlsx',
+ 'csv',
+ 'html',
+ 'md',
+] as const satisfies readonly DraftExportFormat[];
/**
* The page fields an export carries next to the content (Quality spec §7b,
@@ -411,16 +424,30 @@ export async function draftDocx(title: string, html: string, fields?: ExportFiel
}
/**
- * The file for a format: Word built on the click, HTML and Markdown as UTF-8
- * text; with the page fields, each carries them its own way.
+ * The file for a format: Word and Excel built on the click, CSV, HTML and
+ * Markdown as UTF-8 text; with the page fields, each carries them its own way.
+ * `sourceUrl` is the live page an optimize draft is for: without Export's
+ * fields, Excel's and CSV's slug is its, as Export's is.
*/
export async function draftExportBlob(
format: DraftExportFormat,
title: string,
html: string,
fields?: ExportFields,
+ sourceUrl: string | null = null,
): Promise<Blob> {
if (format === 'docx') return draftDocx(title, html, fields);
+ if (format === 'csv') {
+ // The mark tells Excel the file is UTF-8, as the Library's CSV does.
+ return new Blob([BYTE_ORDER_MARK, pageCsv(title, html, fields, sourceUrl)], {
+ type: 'text/csv;charset=utf-8;',
+ });
+ }
+ if (format === 'xlsx') {
+ // Loaded on the click: the library is only needed to write the file.
+ const { default: writeXlsxFile } = await import('write-excel-file/browser');
+ return writeXlsxFile(pageWorkbook(title, html, fields, sourceUrl)).toBlob();
+ }
return format === 'html'
? new Blob([draftHtmlDocument(title, html, fields)], { type: 'text/html;charset=utf-8' })
: new Blob([draftMarkdown(title, html, fields)], { type: 'text/markdown;charset=utf-8' });
@@ -468,6 +495,14 @@ export const LIBRARY_EXPORT_HEADERS = [
/** A spreadsheet cell holds at most this many characters (Excel's limit). */
const CELL_LIMIT = 32_767;
+/** A sheet's cell: a text past Excel's limit cut, and says so; one with lines wrapped. */
+function sheetCell(value: string | number) {
+ if (typeof value !== 'string') return value;
+ const cell = value.length > CELL_LIMIT ? `${value.slice(0, CELL_LIMIT - 1)}…` : value;
+ // A page is a block a line: wrapped, so Excel doesn't run them together.
+ return cell.includes('\n') ? { value: cell, wrap: true } : cell;
+}
+
/** "2026-10-22": a date that sorts as text. */
const day = (iso: string) => iso.slice(0, 10);
@@ -551,13 +586,7 @@ export function libraryWorkbook(items: LibraryExportItem[]): Sheet<Blob>[] {
data: [
LIBRARY_EXPORT_HEADERS.map(bold),
...libraryRows(items).map((row) =>
- LIBRARY_EXPORT_HEADERS.map((header) => {
- const value = row[header];
- if (typeof value !== 'string') return value;
- const cell = value.length > CELL_LIMIT ? `${value.slice(0, CELL_LIMIT - 1)}…` : value;
- // A page is a block a line: wrapped, so Excel doesn't run them together.
- return cell.includes('\n') ? { value: cell, wrap: true } : cell;
- }),
+ LIBRARY_EXPORT_HEADERS.map((header) => sheetCell(row[header])),
),
],
},
@@ -599,3 +628,107 @@ export async function libraryDocx(items: LibraryExportItem[]): Promise<Blob> {
export function libraryExportFileName(tab: string, format: LibraryExportFormat, now: Date): string {
return `ansvisor_content_library_${tab.replace(/_/g, '-')}_${now.toISOString().slice(0, 10)}.${format}`;
}
+
+// ─── One page as a spreadsheet row ──────────────────────────────────────────
+
+/** The page's CSV and sheet header: a CMS's CSV import maps each to a field. */
+export const PAGE_SHEET_HEADERS = [
+ 'Title',
+ 'Meta title',
+ 'Meta description',
+ 'Slug',
+ 'Author',
+ 'Featured image',
+ 'Characters',
+ 'Content',
+ 'HTML',
+];
+
+/** Export's page fields as front matter, read from the page where Export gives none. */
+function frontOf(
+ title: string,
+ html: string,
+ fields: ExportFields | undefined,
+ sourceUrl: string | null,
+): Record<string, string> {
+ if (fields) return fields.front;
+ // As Export reads them, with no author: an optimize draft's slug is its
+ // live page's, so a CMS import updates that page, not a new one.
+ const read = pageFields({ title, html, sourceUrl, author: null, teamByline: '' });
+ return {
+ title: read.metaTitle,
+ description: read.metaDescription,
+ slug: read.slug,
+ image: read.featuredImage ?? '',
+ };
+}
+
+/**
+ * The page as one row: its title, its page fields (Export's, else read from
+ * the page as Export reads them: frontOf), its text a block a line, and its
+ * HTML without the H1 the Title column holds, as a CMS's title field does.
+ * A list item's text starts with "•", not "-": a cell starting with "-"
+ * would be guarded as a formula (toCsv), its text starting "'-".
+ */
+export function pageSheetRow(
+ title: string,
+ html: string,
+ fields?: ExportFields,
+ sourceUrl: string | null = null,
+): Record<string, string | number> {
+ const body = withoutLeadingH1(html);
+ const content = draftText('', body).replace(/^(\s*)- /gm, '$1• ');
+ const front = frontOf(title, html, fields, sourceUrl);
+ const values: (string | number)[] = [
+ title,
+ front.title ?? '',
+ front.description ?? '',
+ front.slug ?? '',
+ front.author ?? '',
+ front.image ?? '',
+ content.replace(/\n/g, '').length,
+ content,
+ body,
+ ];
+ return Object.fromEntries(PAGE_SHEET_HEADERS.map((header, i) => [header, values[i]]));
+}
+
+/** Export CSV: the page as one row. */
+export function pageCsv(
+ title: string,
+ html: string,
+ fields?: ExportFields,
+ sourceUrl: string | null = null,
+): string {
+ return toCsv([pageSheetRow(title, html, fields, sourceUrl)], PAGE_SHEET_HEADERS);
+}
+
+/** Export Excel: the page as one row; a text past a cell's limit is cut, and says so. */
+export function pageWorkbook(
+ title: string,
+ html: string,
+ fields?: ExportFields,
+ sourceUrl: string | null = null,
+): Sheet<Blob>[] {
+ const row = pageSheetRow(title, html, fields, sourceUrl);
+ return [
+ {
+ sheet: 'Page',
+ columns: [
+ { width: 40 },
+ { width: 40 },
+ { width: 60 },
+ { width: 30 },
+ { width: 20 },
+ { width: 40 },
+ { width: 11 },
+ { width: 80 },
+ { width: 80 },
+ ],
+ data: [
+ PAGE_SHEET_HEADERS.map((value) => ({ value, fontWeight: 'bold' as const })),
+ PAGE_SHEET_HEADERS.map((header) => sheetCell(row[header])),
+ ],
+ },
+ ];
+}