fix: preview affichait du JSON brut au lieu du texte des pages FlowDeck
Ajout de _extractPreview(): parse le JSON Notion blocks, extrait le
texte des champs .content ou .text de chaque block. Fallback sur le
raw content si le format n'est pas blocks/markdown.
Avant: {"blocks":[{"type":"text","content":"Hello"}]}
Après: Hello
This commit is contained in:
@@ -504,11 +504,32 @@ document.addEventListener('alpine:init', function() {
|
||||
fetch('/api/local-workspace/page-content/' + node.id)
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(d) {
|
||||
self.previewContent = (d.content || '').substring(0, 500);
|
||||
self.previewContent = self._extractPreview(d.content || '', d.format);
|
||||
})
|
||||
.catch(function() { self.previewContent = '(preview not available)'; });
|
||||
}
|
||||
},
|
||||
_extractPreview(content, format) {
|
||||
if (!content) return '(empty)';
|
||||
// Try to extract text from Notion block JSON
|
||||
if (format === 'blocks' || format === 'markdown') {
|
||||
try {
|
||||
var blocks = typeof content === 'string' ? JSON.parse(content) : content;
|
||||
if (blocks && blocks.blocks && Array.isArray(blocks.blocks)) {
|
||||
var lines = [];
|
||||
for (var i=0; i<blocks.blocks.length && lines.length<20; i++) {
|
||||
var b = blocks.blocks[i];
|
||||
if (b.content) lines.push(b.content);
|
||||
else if (b.text) lines.push(b.text);
|
||||
else if (typeof b === 'string') lines.push(b);
|
||||
}
|
||||
return lines.join('\n').substring(0, 500) || '(empty)';
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
// Fallback: raw text
|
||||
return String(content).substring(0, 500);
|
||||
},
|
||||
hidePreview() {
|
||||
this.previewVisible = false;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user