feat: add notes preview helper with tests
Made-with: Cursor
This commit is contained in:
26
backend/utils/notes-preview.js
Normal file
26
backend/utils/notes-preview.js
Normal file
@@ -0,0 +1,26 @@
|
||||
function computeNotesPreview(notes) {
|
||||
if (!notes || notes.trim() === '') {
|
||||
return { has_notes: false, notes_preview: null };
|
||||
}
|
||||
|
||||
const firstParagraph = notes.split(/\n\n/)[0];
|
||||
|
||||
const stripped = firstParagraph
|
||||
.replace(/^#{1,6}\s+/gm, '') // headers
|
||||
.replace(/\*\*(.+?)\*\*/g, '$1') // bold
|
||||
.replace(/\*(.+?)\*/g, '$1') // italic with *
|
||||
.replace(/_(.+?)_/g, '$1') // italic with _
|
||||
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // links
|
||||
.replace(/^[-*+]\s+/gm, '') // list markers
|
||||
.replace(/\n/g, ' ') // collapse remaining newlines
|
||||
.replace(/\s+/g, ' ') // collapse whitespace
|
||||
.trim();
|
||||
|
||||
const truncated = stripped.length > 150
|
||||
? stripped.slice(0, 150) + '...'
|
||||
: stripped;
|
||||
|
||||
return { has_notes: true, notes_preview: truncated };
|
||||
}
|
||||
|
||||
module.exports = { computeNotesPreview };
|
||||
Reference in New Issue
Block a user