mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-29 11:44:21 +08:00 
			
		
		
		
	add #toc label to control Table of Contents visibility per note, #2985
This commit is contained in:
		
							parent
							
								
									8902cb3117
								
							
						
					
					
						commit
						f890e9917f
					
				| @ -227,7 +227,9 @@ const ATTR_HELP = { | ||||
|                             <li><code>Log for \${now.format('YYYY-MM-DD HH:mm:ss')}</code></li> | ||||
|                         </ul> | ||||
|                          | ||||
|                         See <a href="https://github.com/zadam/trilium/wiki/Default-note-title">wiki with details</a>, API docs for <a href="https://zadam.github.io/trilium/backend_api/Note.html">parentNote</a> and <a href="https://day.js.org/docs/en/display/format">now</a> for details.`
 | ||||
|                         See <a href="https://github.com/zadam/trilium/wiki/Default-note-title">wiki with details</a>, API docs for <a href="https://zadam.github.io/trilium/backend_api/Note.html">parentNote</a> and <a href="https://day.js.org/docs/en/display/format">now</a> for details.`,
 | ||||
|         "template": "This note will appear in the selection of available template when creating new note", | ||||
|         "toc": "<code>#toc</code> or <code>#toc=show</code> will force the Table of Contents to be shown, <code>#toc=hide</code> will force hiding it. If the label doesn't exist, the global setting is observed" | ||||
|     }, | ||||
|     "relation": { | ||||
|         "runOnNoteCreation": "executes when note is created on backend", | ||||
|  | ||||
| @ -74,9 +74,7 @@ export default class TocWidget extends CollapsibleWidget { | ||||
|     } | ||||
| 
 | ||||
|     isEnabled() { | ||||
|         return super.isEnabled() | ||||
|             && this.note.type === 'text' | ||||
|             && !this.note.hasLabel('noToc'); | ||||
|         return super.isEnabled() && this.note.type === 'text'; | ||||
|     } | ||||
| 
 | ||||
|     async doRenderBody() { | ||||
| @ -85,6 +83,14 @@ export default class TocWidget extends CollapsibleWidget { | ||||
|     } | ||||
| 
 | ||||
|     async refreshWithNote(note) { | ||||
|         const tocLabel = note.getLabel('toc'); | ||||
| 
 | ||||
|         if (tocLabel?.value === 'hide') { | ||||
|             this.toggleInt(false); | ||||
|             this.triggerCommand("reevaluateIsEnabled"); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         let $toc = "", headingCount = 0; | ||||
|         // Check for type text unconditionally in case alwaysShowWidget is set
 | ||||
|         if (this.note.type === 'text') { | ||||
| @ -93,7 +99,11 @@ export default class TocWidget extends CollapsibleWidget { | ||||
|         } | ||||
| 
 | ||||
|         this.$toc.html($toc); | ||||
|         this.toggleInt(headingCount >= options.getInt('minTocHeadings')); | ||||
|         this.toggleInt( | ||||
|             ["", "show"].includes(tocLabel?.value) | ||||
|             || headingCount >= options.getInt('minTocHeadings') | ||||
|         ); | ||||
| 
 | ||||
|         this.triggerCommand("reevaluateIsEnabled"); | ||||
|     } | ||||
| 
 | ||||
| @ -241,7 +251,7 @@ export default class TocWidget extends CollapsibleWidget { | ||||
|         if (loadResults.isNoteContentReloaded(this.noteId)) { | ||||
|             await this.refresh(); | ||||
|         } else if (loadResults.getAttributes().find(attr => attr.type === 'label' | ||||
|             && (attr.name.toLowerCase().includes('readonly') || attr.name === 'noToc') | ||||
|             && (attr.name.toLowerCase().includes('readonly') || attr.name === 'toc') | ||||
|             && attributeService.isAffecting(attr, this.note))) { | ||||
| 
 | ||||
|             await this.refresh(); | ||||
|  | ||||
| @ -52,6 +52,7 @@ module.exports = [ | ||||
|     { type: 'label', name: 'hideRelations' }, | ||||
|     { type: 'label', name: 'titleTemplate', isDangerous: true }, | ||||
|     { type: 'label', name: 'template' }, | ||||
|     { type: 'label', name: 'toc' }, | ||||
| 
 | ||||
|     // relation names
 | ||||
|     { type: 'relation', name: 'internalLink' }, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam