Skip to content

Commit b7f1e09

Browse files
committed
feat: support 15+ additional block types in blocks command
1 parent c444bfc commit b7f1e09

2 files changed

Lines changed: 166 additions & 1 deletion

File tree

commands/blocks.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,171 @@ module.exports = {
100100
continue;
101101
}
102102

103+
// Handle image blocks
104+
if (type === 'image') {
105+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
106+
const url = content?.file?.url || content?.external?.url || '';
107+
const caption = content?.caption ? richTextToPlain(content.caption) : '';
108+
console.log(`${idTag}🖼️ ${caption || '(image)'}`);
109+
if (url) console.log(`${idTag} ${url.slice(0, 80)}${url.length > 80 ? '...' : ''}`);
110+
continue;
111+
}
112+
113+
// Handle video blocks
114+
if (type === 'video') {
115+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
116+
const url = content?.file?.url || content?.external?.url || '';
117+
const caption = content?.caption ? richTextToPlain(content.caption) : '';
118+
console.log(`${idTag}🎬 ${caption || '(video)'}`);
119+
if (url) console.log(`${idTag} ${url.slice(0, 80)}${url.length > 80 ? '...' : ''}`);
120+
continue;
121+
}
122+
123+
// Handle audio blocks
124+
if (type === 'audio') {
125+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
126+
const url = content?.file?.url || content?.external?.url || '';
127+
const caption = content?.caption ? richTextToPlain(content.caption) : '';
128+
console.log(`${idTag}🔊 ${caption || '(audio)'}`);
129+
if (url) console.log(`${idTag} ${url.slice(0, 80)}${url.length > 80 ? '...' : ''}`);
130+
continue;
131+
}
132+
133+
// Handle file blocks
134+
if (type === 'file') {
135+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
136+
const url = content?.file?.url || content?.external?.url || '';
137+
const name = content?.name || content?.caption?.[0]?.plain_text || '(file)';
138+
console.log(`${idTag}📎 ${name}`);
139+
if (url) console.log(`${idTag} ${url.slice(0, 80)}${url.length > 80 ? '...' : ''}`);
140+
continue;
141+
}
142+
143+
// Handle PDF blocks
144+
if (type === 'pdf') {
145+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
146+
const url = content?.file?.url || content?.external?.url || '';
147+
const caption = content?.caption ? richTextToPlain(content.caption) : '';
148+
console.log(`${idTag}📑 ${caption || '(PDF)'}`);
149+
if (url) console.log(`${idTag} ${url.slice(0, 80)}${url.length > 80 ? '...' : ''}`);
150+
continue;
151+
}
152+
153+
// Handle bookmark blocks
154+
if (type === 'bookmark') {
155+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
156+
const url = content?.url || '';
157+
const caption = content?.caption ? richTextToPlain(content.caption) : '';
158+
console.log(`${idTag}🔖 ${caption || url || '(bookmark)'}`);
159+
if (caption && url) console.log(`${idTag} ${url}`);
160+
continue;
161+
}
162+
163+
// Handle embed blocks
164+
if (type === 'embed') {
165+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
166+
const url = content?.url || '';
167+
const caption = content?.caption ? richTextToPlain(content.caption) : '';
168+
console.log(`${idTag}🔗 ${caption || '(embed)'}`);
169+
if (url) console.log(`${idTag} ${url}`);
170+
continue;
171+
}
172+
173+
// Handle link_preview blocks
174+
if (type === 'link_preview') {
175+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
176+
const url = content?.url || '';
177+
console.log(`${idTag}🔗 ${url}`);
178+
continue;
179+
}
180+
181+
// Handle callout blocks
182+
if (type === 'callout') {
183+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
184+
const icon = content?.icon?.emoji || content?.icon?.external?.url ? '📌' : '💡';
185+
const text = content?.rich_text ? richTextToPlain(content.rich_text) : '';
186+
console.log(`${idTag}${content?.icon?.emoji || icon} ${text}`);
187+
continue;
188+
}
189+
190+
// Handle quote blocks
191+
if (type === 'quote') {
192+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
193+
const text = content?.rich_text ? richTextToPlain(content.rich_text) : '';
194+
console.log(`${idTag}> ${text}`);
195+
continue;
196+
}
197+
198+
// Handle toggle blocks (show header, note has children)
199+
if (type === 'toggle') {
200+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
201+
const text = content?.rich_text ? richTextToPlain(content.rich_text) : '';
202+
console.log(`${idTag}${text}`);
203+
continue;
204+
}
205+
206+
// Handle equation blocks
207+
if (type === 'equation') {
208+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
209+
const expr = content?.expression || '';
210+
console.log(`${idTag}${expr}`);
211+
continue;
212+
}
213+
214+
// Handle synced_block
215+
if (type === 'synced_block') {
216+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
217+
const syncedFrom = content?.synced_from?.block_id;
218+
if (syncedFrom) {
219+
console.log(`${idTag}🔄 (synced from ${syncedFrom.slice(0, 8)}...)`);
220+
} else {
221+
console.log(`${idTag}🔄 (synced block source)`);
222+
}
223+
continue;
224+
}
225+
226+
// Handle column_list (container)
227+
if (type === 'column_list') {
228+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
229+
console.log(`${idTag}┃ (columns)`);
230+
continue;
231+
}
232+
233+
// Handle column
234+
if (type === 'column') {
235+
// Columns are children of column_list, usually skip
236+
continue;
237+
}
238+
239+
// Handle link_to_page
240+
if (type === 'link_to_page') {
241+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
242+
const pageId = content?.page_id || content?.database_id || '';
243+
console.log(`${idTag}↗️ (link to ${pageId.slice(0, 8)}...)`);
244+
continue;
245+
}
246+
247+
// Handle table_of_contents
248+
if (type === 'table_of_contents') {
249+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
250+
console.log(`${idTag}📑 (table of contents)`);
251+
continue;
252+
}
253+
254+
// Handle breadcrumb
255+
if (type === 'breadcrumb') {
256+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
257+
console.log(`${idTag}🍞 (breadcrumb)`);
258+
continue;
259+
}
260+
261+
// Handle unsupported block type (show type name)
262+
if (type === 'unsupported') {
263+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
264+
console.log(`${idTag}⚠️ (unsupported block type)`);
265+
continue;
266+
}
267+
103268
if (content?.rich_text) {
104269
text = richTextToPlain(content.rich_text);
105270
} else if (content?.text) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jordancoin/notioncli",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "A powerful CLI for the Notion API — query databases, manage pages, and automate your workspace from the terminal.",
55
"main": "bin/notion.js",
66
"bin": {

0 commit comments

Comments
 (0)