mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	trim content for grid view
This commit is contained in:
		
							parent
							
								
									4202af96c8
								
							
						
					
					
						commit
						37e111d8a9
					
				| @ -4,7 +4,11 @@ import renderService from "./render.js"; | ||||
| import protectedSessionService from "./protected_session.js"; | ||||
| import protectedSessionHolder from "./protected_session_holder.js"; | ||||
| 
 | ||||
| async function getRenderedContent(note) { | ||||
| async function getRenderedContent(note, options = {}) { | ||||
|     options = Object.assign({ | ||||
|         trim: false | ||||
|     }, options); | ||||
| 
 | ||||
|     const type = getRenderingType(note); | ||||
| 
 | ||||
|     let $rendered; | ||||
| @ -12,12 +16,12 @@ async function getRenderedContent(note) { | ||||
|     if (type === 'text') { | ||||
|         const fullNote = await server.get('notes/' + note.noteId); | ||||
| 
 | ||||
|         $rendered = $('<div class="ck-content">').html(fullNote.content); | ||||
|         $rendered = $('<div class="ck-content">').html(trim(fullNote.content, options.trim)); | ||||
|     } | ||||
|     else if (type === 'code') { | ||||
|         const fullNote = await server.get('notes/' + note.noteId); | ||||
| 
 | ||||
|         $rendered = $("<pre>").text(fullNote.content); | ||||
|         $rendered = $("<pre>").text(trim(fullNote.content, options.trim)); | ||||
|     } | ||||
|     else if (type === 'image') { | ||||
|         $rendered = $("<img>") | ||||
| @ -89,6 +93,15 @@ async function getRenderedContent(note) { | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| function trim(text, doTrim) { | ||||
|     if (!doTrim) { | ||||
|         return text; | ||||
|     } | ||||
|     else { | ||||
|         return text.substr(0, Math.min(text.length, 1000)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| function getRenderingType(note) { | ||||
|     let type = note.type; | ||||
| 
 | ||||
|  | ||||
| @ -300,7 +300,9 @@ class NoteListRenderer { | ||||
|         const $content = $('<div class="note-book-content">'); | ||||
| 
 | ||||
|         try { | ||||
|             const {renderedContent, type} = await noteContentRenderer.getRenderedContent(note); | ||||
|             const {renderedContent, type} = await noteContentRenderer.getRenderedContent(note, { | ||||
|                 trim: this.viewType === 'grid' // for grid only short content is needed
 | ||||
|             }); | ||||
| 
 | ||||
|             $content.append(renderedContent); | ||||
|             $content.addClass("type-" + type); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam