MCPcopy Index your code
hub / github.com/simstudioai/sim / itemToPlainText

Function itemToPlainText

apps/sim/connectors/webflow/webflow.ts:42–72  ·  view source on GitHub ↗

* Formats a CMS item's field data into structured plain text.

(item: WebflowItem, collectionName: string)

Source from the content-addressed store, hash-verified

40 * Formats a CMS item's field data into structured plain text.
41 */
42function itemToPlainText(item: WebflowItem, collectionName: string): string {
43 const lines: string[] = []
44 const fieldData = item.fieldData || {}
45
46 const title = (fieldData.name as string) || (fieldData.title as string) || 'Untitled'
47 lines.push(`# ${title}`)
48 lines.push(`Collection: ${collectionName}`)
49
50 for (const [key, value] of Object.entries(fieldData)) {
51 if (value == null) continue
52 if (key === 'name' || key === 'title') continue
53
54 if (Array.isArray(value)) {
55 const items = value.map((v) => {
56 if (typeof v === 'object' && v !== null) {
57 return JSON.stringify(v)
58 }
59 return String(v)
60 })
61 lines.push(`${key}: ${items.join(', ')}`)
62 } else if (typeof value === 'object') {
63 lines.push(`${key}: ${JSON.stringify(value)}`)
64 } else if (typeof value === 'string' && /<[a-z][^>]*>/i.test(value)) {
65 lines.push(`${key}: ${htmlToPlainText(value)}`)
66 } else {
67 lines.push(`${key}: ${String(value)}`)
68 }
69 }
70
71 return lines.join('\n')
72}
73
74/**
75 * Extracts a human-readable title from a Webflow CMS item.

Callers 1

itemToDocumentFunction · 0.85

Calls 4

htmlToPlainTextFunction · 0.90
joinMethod · 0.80
testMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected