2025-07-22 13:26:27 +05:00
/ *
This file is part of the Notesnook project ( https : //notesnook.com/)
Copyright ( C ) 2023 Streetwriters ( Private ) Limited
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
2025-07-22 09:32:23 +05:00
import { writeFileSync } from "fs" ;
2025-07-22 13:26:27 +05:00
import {
getGroupedKeybindings ,
formatKey ,
macify ,
CATEGORIES
} from "@notesnook/common" ;
2025-07-22 09:32:23 +05:00
console . log ( "Generating keyboard shortcuts documentation..." ) ;
const keyboardShortcutFilePath = "./contents/keyboard-shortcuts.md" ;
const frontmatter = ` ---
2026-08-14 08:57:51 +05:00
title : Keyboard shortcuts
pageTitle : Every keyboard shortcut in Notesnook
description : The complete list of Notesnook keyboard shortcuts for web , Windows , Linux and macOS — navigation , the editor , formatting and note actions .
keywords :
- notesnook keyboard shortcuts
- notesnook hotkeys
- notes app shortcuts
2025-07-22 09:32:23 +05:00
-- -
` ;
2025-07-22 16:28:07 +05:00
const content = ` # Keyboard shortcuts
2026-08-14 08:57:51 +05:00
These are every keyboard shortcut the Notesnook desktop and web apps respond to , grouped by what they do . Press \ ` Ctrl \` \` / \` ( \` ⌘ \` \` / \` on macOS) inside the app to bring the same list up there.
: : : info This page is generated from the app
The tables below are generated straight from the app ' s own keybinding registry , so they cannot drift out of step with the shortcuts that actually fire .
: : : ` ;
const relatedPages = ` ## Related pages
- [ Editor toolbar ] ( / r i c h - t e x t - e d i t o r / r i c h - t e x t - e d i t o r - t o o l b a r ) — t h e s a m e a c t i o n s a s b u t t o n s , a n d h o w t o r e a r r a n g e t h e m
- [ Markdown shortcuts ] ( / r i c h - t e x t - e d i t o r / m a r k d o w n - n o t e s - e d i t i n g ) — f o r m a t t i n g t h a t t r i g g e r s a s y o u t y p e
- [ Find & replace ] ( / r i c h - t e x t - e d i t o r / s e a r c h - a n d - r e p l a c e ) — s e a r c h i n g i n s i d e t h e n o t e y o u a r e e d i t i n g
- [ Search & navigation ] ( / s e a r c h - a n d - n a v i g a t i o n ) — t h e c o m m a n d p a l e t t e a n d q u i c k o p e n
- [ Tabs & panes ] ( / r i c h - t e x t - e d i t o r / e d i t o r - t a b s - a n d - p a n e s ) — m o v i n g b e t w e e n o p e n n o t e s ` ;
2025-07-22 09:32:23 +05:00
const markdownTable = getGroupedTableKeybindingsMarkdown ( ) ;
writeFileSync (
keyboardShortcutFilePath ,
2026-08-14 08:57:51 +05:00
frontmatter + "\n" + content + "\n\n" + markdownTable + "\n\n" + relatedPages + "\n" ,
2025-07-22 09:32:23 +05:00
"utf-8"
) ;
console . log ( "Keyboard shortcuts documentation updated successfully!" ) ;
/ * *
* @ returns markdown formatted table of keyboard shortcuts grouped by category .
* /
function getGroupedTableKeybindingsMarkdown ( ) {
const desktopKeybindings = getGroupedKeybindings ( true , false ) ;
const webKeybindings = getGroupedKeybindings ( false , false ) ;
const header = ` | Description | Web | Windows/Linux | Mac |
| -- - | -- - | -- - | -- - | ` ;
2025-07-22 13:26:27 +05:00
return CATEGORIES . map ( ( category ) => {
const webShortcuts =
webKeybindings . find ( ( g ) => g . category === category ) ? . shortcuts || [ ] ;
const desktopShortcuts =
desktopKeybindings . find ( ( g ) => g . category === category ) ? . shortcuts || [ ] ;
const mergedShortcuts = { } ;
webShortcuts . forEach ( ( { description , keys } ) => {
if ( ! mergedShortcuts [ description ] ) {
mergedShortcuts [ description ] = { } ;
}
mergedShortcuts [ description ] . web = keys ;
} ) ;
desktopShortcuts . forEach ( ( { description , keys } ) => {
if ( ! mergedShortcuts [ description ] ) {
mergedShortcuts [ description ] = { } ;
}
mergedShortcuts [ description ] . desktop = keys ;
} ) ;
const rows = Object . entries ( mergedShortcuts )
. map ( ( [ description , { web , desktop } ] ) => {
const webKeys = web ? . map ( ( k ) => formatKey ( k ) ) . join ( " / " ) || "-" ;
const windowsLinuxKeys =
desktop ? . map ( ( k ) => formatKey ( k ) ) . join ( " / " ) || "-" ;
const macKeys =
desktop
? . map ( macify )
. map ( ( k ) => formatKey ( k , true ) )
. join ( " / " ) || "-" ;
return ` | ${ description } | ${ webKeys } | ${ windowsLinuxKeys } | ${ macKeys } | ` ;
} )
. join ( "\n" ) ;
2026-08-14 08:57:51 +05:00
return ` ## ${ category } \n \n ${ header } \n ${ rows } ` ;
2025-07-22 13:26:27 +05:00
} ) . join ( "\n\n" ) ;
2025-07-22 09:32:23 +05:00
}