79 lines
2.0 KiB
TypeScript
79 lines
2.0 KiB
TypeScript
"use client";
|
|
|
|
import type { Block, SectionBlockProps, TextBlockProps } from "@/features/editor/state/editorStore";
|
|
|
|
export function createBlogTemplateBlocks(opts: {
|
|
sectionId: string;
|
|
createId: () => string;
|
|
}): { blocks: Block[]; lastSelectedId: string } {
|
|
const { sectionId, createId } = opts;
|
|
|
|
const columns: SectionBlockProps["columns"] = [
|
|
{ id: `${sectionId}_col_1`, span: 4 },
|
|
{ id: `${sectionId}_col_2`, span: 4 },
|
|
{ id: `${sectionId}_col_3`, span: 4 },
|
|
];
|
|
|
|
const sectionProps: SectionBlockProps = {
|
|
background: "default",
|
|
paddingY: "lg",
|
|
columns,
|
|
} as any;
|
|
|
|
const sectionBlock: Block = {
|
|
id: sectionId,
|
|
type: "section",
|
|
props: sectionProps,
|
|
sectionId: null,
|
|
columnId: null,
|
|
};
|
|
|
|
const postDefinitions = [
|
|
{ title: "블로그 포스트 1", summary: "첫 번째 포스트 요약을 여기에 입력하세요." },
|
|
{ title: "블로그 포스트 2", summary: "두 번째 포스트 요약을 여기에 입력하세요." },
|
|
{ title: "블로그 포스트 3", summary: "세 번째 포스트 요약을 여기에 입력하세요." },
|
|
];
|
|
|
|
const blogBlocks: Block[] = columns.flatMap((col, index) => {
|
|
const post = postDefinitions[index] ?? postDefinitions[0];
|
|
|
|
const titleId = createId();
|
|
const summaryId = createId();
|
|
|
|
const titleProps: TextBlockProps = {
|
|
text: post.title,
|
|
align: "left",
|
|
size: "lg",
|
|
} as any;
|
|
|
|
const summaryProps: TextBlockProps = {
|
|
text: post.summary,
|
|
align: "left",
|
|
size: "sm",
|
|
} as any;
|
|
|
|
const titleBlock: Block = {
|
|
id: titleId,
|
|
type: "text",
|
|
props: titleProps,
|
|
sectionId,
|
|
columnId: col.id,
|
|
};
|
|
|
|
const summaryBlock: Block = {
|
|
id: summaryId,
|
|
type: "text",
|
|
props: summaryProps,
|
|
sectionId,
|
|
columnId: col.id,
|
|
};
|
|
|
|
return [titleBlock, summaryBlock];
|
|
});
|
|
|
|
const blocks: Block[] = [sectionBlock, ...blogBlocks];
|
|
const lastSelectedId = blogBlocks[blogBlocks.length - 1]?.id ?? sectionId;
|
|
|
|
return { blocks, lastSelectedId };
|
|
}
|