mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-19 21:19:31 +01:00
docs: move keyboard shortcuts script to docs/help
Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
71
docs/help/scripts/document-keyboard-shortcuts.mjs
Normal file
71
docs/help/scripts/document-keyboard-shortcuts.mjs
Normal file
@@ -0,0 +1,71 @@
|
||||
import { writeFileSync } from "fs";
|
||||
import { getGroupedKeybindings, formatKey, macify } from "@notesnook/common";
|
||||
|
||||
console.log("Generating keyboard shortcuts documentation...");
|
||||
|
||||
const keyboardShortcutFilePath = "./contents/keyboard-shortcuts.md";
|
||||
|
||||
const frontmatter = `---
|
||||
title: Keyboard Shortcuts
|
||||
description: Keyboard shortcuts for Notesnook
|
||||
---
|
||||
`;
|
||||
|
||||
const content =
|
||||
"The following keyboard shortcuts will help you navigate Notesnook faster.";
|
||||
|
||||
const markdownTable = getGroupedTableKeybindingsMarkdown();
|
||||
|
||||
writeFileSync(
|
||||
keyboardShortcutFilePath,
|
||||
frontmatter + "\n" + content + "\n\n" + markdownTable,
|
||||
"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 |
|
||||
| --- | --- | --- | --- |`;
|
||||
|
||||
return Object.keys({ ...webKeybindings, ...desktopKeybindings })
|
||||
.map((category) => {
|
||||
const webShortcuts = webKeybindings[category] || [];
|
||||
const desktopShortcuts = desktopKeybindings[category] || [];
|
||||
|
||||
const mergedShortcuts = {};
|
||||
|
||||
webShortcuts.forEach(({ description, keys }) => {
|
||||
if (!mergedShortcuts[description]) {
|
||||
mergedShortcuts[description] = {};
|
||||
}
|
||||
mergedShortcuts[description].web = keys.map(formatKey);
|
||||
});
|
||||
desktopShortcuts.forEach(({ description, keys }) => {
|
||||
if (!mergedShortcuts[description]) {
|
||||
mergedShortcuts[description] = {};
|
||||
}
|
||||
mergedShortcuts[description].desktop = keys.map(formatKey);
|
||||
});
|
||||
|
||||
const rows = Object.entries(mergedShortcuts)
|
||||
.map(([description, { web, desktop }]) => {
|
||||
const webKeys = web?.join(" / ") || "-";
|
||||
const windowsLinuxKeys = desktop?.join(" / ") || "-";
|
||||
const macKeys =
|
||||
desktop?.map(macify).map(formatKey).join(" / ") || "-";
|
||||
|
||||
return `| ${description} | ${webKeys} | ${windowsLinuxKeys} | ${macKeys} |`;
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
return `### ${category}\n\n${header}\n${rows}`;
|
||||
})
|
||||
.join("\n\n");
|
||||
}
|
||||
Reference in New Issue
Block a user