Skip to content

Commit 9bd6af1

Browse files
authored
Merge pull request #38 from dev-five-git/add-description
Add Page description
2 parents 8636d2a + e6a6927 commit 9bd6af1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/commands/exportPagesAndComponents.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,41 @@ export function generateImportStatements(
118118
return statements.length > 0 ? `${statements.join('\n')}\n\n` : ''
119119
}
120120

121+
type AnnotatedNode = SceneNode & {
122+
annotations: ReadonlyArray<{ label?: string; labelMarkdown?: string }>
123+
}
124+
125+
/**
126+
* Collect notes from a section: standalone TEXT children (annotations by convention)
127+
* and Figma dev-mode annotations on descendant nodes.
128+
* Returns the combined text, or empty string if none found.
129+
*/
130+
export function collectSectionNotes(section: SectionNode): string {
131+
const lines: string[] = []
132+
133+
// 1. Direct TEXT children are treated as page annotations
134+
for (const child of section.children) {
135+
if (child.type === 'TEXT') {
136+
const text = (child as TextNode).characters.trim()
137+
if (text) lines.push(text)
138+
}
139+
}
140+
141+
// 2. Figma dev-mode annotations on any descendant node
142+
const annotatedNodes = section.findAll(
143+
(node) =>
144+
'annotations' in node && (node as AnnotatedNode).annotations.length > 0,
145+
)
146+
for (const node of annotatedNodes) {
147+
for (const annotation of (node as AnnotatedNode).annotations) {
148+
const text = (annotation.label ?? annotation.labelMarkdown ?? '').trim()
149+
if (text) lines.push(`[${node.name}] ${text}`)
150+
}
151+
}
152+
153+
return lines.join('\n')
154+
}
155+
121156
interface ScreenshotTarget {
122157
node: SceneNode
123158
folder: JSZip
@@ -324,6 +359,12 @@ export async function exportPagesAndComponents() {
324359
pagesFolder?.file(`${pageName}.tsx`, fullCode, ZIP_TEXT_FILE_OPTIONS)
325360
perfEnd(`responsivePage(${pageName})`, t)
326361

362+
// Collect section notes (standalone TEXT children + annotations)
363+
const notes = collectSectionNotes(sectionNode)
364+
if (notes && pagesFolder) {
365+
pagesFolder.file(`${pageName}.txt`, notes, ZIP_TEXT_FILE_OPTIONS)
366+
}
367+
327368
// Defer screenshot capture
328369
if (pagesFolder) {
329370
screenshotTargets.push({

0 commit comments

Comments
 (0)