Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jgclark.NoteHelpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This plugin (now a Core Plugin bundled with NotePlan 3.16.1 onwards) provides co
- **Show This Quarter** (alias **/stq**)
- **Show This Year** (alias **/sty**)
- **update all indexes** (alias **uai**): updates all the existing folder index notes
- **Write changed/modified date to frontmatter** (alias **modified**): writes the modified date to frontmatter (on each save). Writes to 'modified' key. Also (optionally) writes the author's initials to the 'author' key (see plugin settings).

**Tip**: some of these are even more helpful if you assign a keyboard shortcut to them, using macOS's Keyboard > Shortcuts > App Shortcuts system. For example I have mapped ⇧⌘H to `/jump to heading`.

Expand Down
48 changes: 46 additions & 2 deletions jgclark.NoteHelpers/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"plugin.author": "Jonathan Clark & Eduard Metzger",
"plugin.url": "https://github.com/NotePlan/plugins/tree/main/jgclark.NoteHelpers/",
"plugin.changelog": "https://github.com/NotePlan/plugins/blob/main/jgclark.NoteHelpers/CHANGELOG.md",
"plugin.version": "1.0.0",
"plugin.lastUpdateInfo": "1.0.0: move '/new note from ...' commands here from Filer plugin, and revived '/new note' command.\n0.20.3: New 'printEditorDetailed' command to log all paragraph details as well.\n0.20.2: 'printNote' extended to cover backlinks.\n0.20.1: new command 'printNote' for debugging purposes.\n0.20.0: new commands \"unlinked note finder\" and \"delete note\". Bug fix to \"rename note filename\" command.\n0.19.2: fix edge cases with \"add trigger to note\".\n0.19.1: \"add trigger to note\" command can now be run from template. Added migration message about 'open note' commands.\n0.19.0: fix to '/rename inconsistent filename' command. Moved 'open note' functions to WindowTools plugin. Updated the display of the 'index folders' command. Removed 'Show month/quarter/year' commands as they are now in the main NP menus.",
"plugin.version": "1.1.0",
"plugin.lastUpdateInfo": "1.1.0: added 'write modified' command to write the modified date to frontmatter (on each save). Can be run by hand or can be included as a trigger using the 'add trigger to note' command.\n1.0.0: move '/new note from ...' commands here from Filer plugin, and revived '/new note' command.\n0.20.3: New 'printEditorDetailed' command to log all paragraph details as well.\n0.20.2: 'printNote' extended to cover backlinks.\n0.20.1: new command 'printNote' for debugging purposes.\n0.20.0: new commands \"unlinked note finder\" and \"delete note\". Bug fix to \"rename note filename\" command.\n0.19.2: fix edge cases with \"add trigger to note\".\n0.19.1: \"add trigger to note\" command can now be run from template. Added migration message about 'open note' commands.\n0.19.0: fix to '/rename inconsistent filename' command. Moved 'open note' functions to WindowTools plugin. Updated the display of the 'index folders' command. Removed 'Show month/quarter/year' commands as they are now in the main NP menus.",
"plugin.dependencies": [],
"plugin.script": "script.js",
"plugin.commands": [
Expand Down Expand Up @@ -253,6 +253,23 @@
"description": "onEditorWillSave",
"jsFunction": "triggerFindUnlinkedNotes",
"hidden": true
},
{
"name": "Write changed/modified date to frontmatter",
"description": "Write the modified date to frontmatter (on each save). Writes to 'modified' key.",
"jsFunction": "writeModified",
"alias": [
"modified"
],
"arguments": []
},
{
"name": "writeModified",
"description": "Write the modified date to frontmatter (on each save). Writes to 'modified' key. Can be run by hand or can be included as a trigger using the 'add trigger to note' command.",
"jsFunction": "writeModified",
"alias": [],
"arguments": [],
"hidden": true
}
],
"offerToDownloadPlugin": {
Expand Down Expand Up @@ -372,6 +389,33 @@
{
"type": "separator"
},
{
"type": "heading",
"title": "'Write changed/modified date to frontmatter' command settings"
},
{
"key": "dateFormat",
"title": "Date format",
"description": "The format of the date to write to frontmatter. Use 'ISO' for ISO 8601 format (YYYY-MM-DDTHH:MM:SS.SSSZ), or 'Local' to use your local time settings format.",
"type": "string",
"default": "ISO",
"required": false,
"choices": [
"ISO",
"Local"
]
},
{
"key": "authorID",
"title": "Author ID",
"description": "Your intiials or ID to use in command 'Write changed/modified date to frontmatter'. Leave blank to not include an author ID next to the date.",
"type": "string",
"default": "",
"required": false
},
{
"type": "separator"
},
{
"type": "heading",
"title": "Debugging"
Expand Down
12 changes: 3 additions & 9 deletions jgclark.NoteHelpers/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@ export { titleToFilename } from './lib/commands/titleToFilename'
export { filenameToTitle } from './lib/commands/filenameToTitle'
export { renameInconsistentNames } from './lib/commands/renameInconsistentNames'
export { newNote, newNoteFromClipboard, newNoteFromSelection } from './newNote'
export {
addTriggerToNote,
convertLocalLinksToPluginLinks,
addFrontmatterToNote,
moveNote,
logEditorNoteDetailed,
renameNoteFile,
trashNote
} from './noteHelpers'
export { addTriggerToNote, convertLocalLinksToPluginLinks, addFrontmatterToNote, moveNote, logEditorNoteDetailed, renameNoteFile, trashNote } from './noteHelpers'
export {
jumpToDone,
jumpToHeading,
Expand All @@ -46,6 +38,8 @@ export {
export { findUnlinkedNotesInCurrentNote, findUnlinkedNotesInAllNotes, triggerFindUnlinkedNotes } from './unlinkedNoteFinder'
export { printNote } from '@helpers/NPnote'

export { writeModified } from './writeModified'

export function resetCaches() {
NotePlan.resetCaches()
}
Expand Down
39 changes: 39 additions & 0 deletions jgclark.NoteHelpers/src/writeModified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @flow

import pluginJson from '../plugin.json'
import { setFrontMatterVars } from '@helpers/NPFrontMatter'
import { log, logError, logDebug, timer, clo, clof, JSP } from '@helpers/dev'

/****************************************************************************************************************************
* CONSTANTS
****************************************************************************************************************************/

/****************************************************************************************************************************
* LOCAL FUNCTIONS
****************************************************************************************************************************/

/****************************************************************************************************************************
* EXPORTED FUNCTIONS
****************************************************************************************************************************/

/****************************************************************************************************************************
* COMMAND ENTRYPOINTS
****************************************************************************************************************************/

/**
* Writes the modified date to frontmatter (on each save). Writes to 'modified' key
* Requires the trigger onEditorWillSave
* @author @jgclark
*/
export async function writeModified(): Promise<void> {
try {
logDebug('writeModified', 'Starting')
const { authorID, dateFormat } = await DataStore.settings
const theTime = !dateFormat || dateFormat === 'ISO' ? new Date().toISOString() : new Date().toLocaleString()
setFrontMatterVars(Editor, {
modified: authorID ? `${theTime} (${authorID})` : theTime,
})
} catch (e) {
logError(pluginJson, JSP(e))
}
}
Loading