-
Notifications
You must be signed in to change notification settings - Fork 91
Add script "Insert Table of Contents II (Map of Contents)" #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
netlimpopo
wants to merge
5
commits into
qownnotes:master
Choose a base branch
from
netlimpopo:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "Insert Table of Contents II (M.O.C. Map of Contents)", | ||
| "identifier": "insert-moc", | ||
| "script": "insert-moc.qml", | ||
| "authors": ["@netlimpopo"], | ||
| "platforms": ["linux", "macos", "windows"], | ||
| "version": "0.0.1", | ||
| "minAppVersion": "25.12.7", | ||
| "description": "This script generates a list of clickable links which map to every single <code>.md</code> note within the active note folder (= "Map of contents (M.O.C.)"). It displays the links in a table format along with the <em>relative filepaths of the files</em>. Furthermore it sorts the links in alphabetical order. \n The difference to the "Table of Contents" script lies in the fact, that the T.O.C script creates links to headings of the same document whereas this M.O.C. script creates references to every single notename in the active note folder.\n <strong>Usage</strong> \n. <ol> <li>Select the highest folder hierachy <strong>(!)</strong>.</li> <li>Create a new note with an arbitrary name in the highest note hierachy (note level).</li><li>Click the M.O.C button in the script menu. Then the script will overwrite all of the current note content and will insert the linkslist.</li> </ol> \n\n <strong>Warning</strong> \n Note that <strong>all of the content</strong> of the selcted note <strong>will be replaced</strong> by the table of contents link list. Therefore it is essential to create a new note and exclusively use this note for the M.O.C list.\n <strong>automatic updates</strong>\n In case you rename a note, the markdown links in the M.O.C will be automatically updated too, as QOwnNotes watches all markdownlinks and checks links for necessary updates. \n However, if <strong>one creates a new note anywhere, the script must be excecuted again</strong>, as it will otherwise not watch for file additions nor will it add a new link to the list.\n Also if you want to move the M.O.C file to a different location, all the links will be updated accordingly thanks to the QOwnNotes logic. \n An M.O.C. can act as a navitational site (especially when all files are exported as static .html pages) and provide an overview of all available notes. The idea is strongly influenced by the Obsidian plugin 'Waypoint' see <a href="https://github.com/IdreesInc/Waypoint">Waypoint Obsidian</a>. " | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import QtQml 2.2 | ||
| import QOwnNotesTypes 1.0 | ||
|
|
||
| Script { | ||
| function init() { | ||
| // Register custom action for MOC index generation | ||
| script.registerCustomAction("MOC", "Generate MOC", "MOC"); | ||
| } | ||
|
|
||
| function customActionInvoked(action) { | ||
| if (action !== "indexpage") { | ||
| return; | ||
| } | ||
|
|
||
| var currentNote = script.currentNote; | ||
| var noteIds = script.fetchNoteIdsByNoteTextPart(""); // get all note IDs | ||
|
|
||
| // Build each link line and collect into array | ||
| var listedLinks = []; | ||
| for (var i = 0; i < noteIds.length; i++) { | ||
| var noteId = noteIds[i]; | ||
| var noteObj = script.fetchNoteById(noteId); | ||
| var name = noteObj.name; | ||
| var fullPath = noteObj.fullNoteFilePath; | ||
| var parts = fullPath.split('.'); | ||
| var ext = parts[parts.length - 1]; | ||
| var relDir = noteObj.relativeNoteFileDirPath; | ||
|
|
||
| // Construct filePath and encoded path | ||
| var filePath = relDir && relDir.length > 0 | ||
| ? relDir + "/" + name + "." + ext | ||
| : name + "." + ext; | ||
| var rawLink = (relDir && relDir.length > 0 | ||
| ? relDir + "/" + name | ||
| : name); | ||
| var encoded = encodeURIComponent(rawLink) | ||
| .replace(/%2F/g, "/") | ||
| .replace(/%2E/g, ".") + "." + ext; | ||
|
|
||
| // Format line | ||
| var line = "|" + filePath + " | ---> [" + name + "." + ext + "](" + encoded + ")| "; | ||
| listedLinks.push(line); | ||
| } | ||
|
|
||
| // Sort lines alphabetically | ||
| listedLinks.sort(); | ||
|
|
||
| // Assemble new note text | ||
| var noteTextstring = "# Map of Content \n\n|path |filelink | \n|---|---| \n" + listedLinks.join("\n") + "\n"; | ||
|
|
||
| // Replace entire note content | ||
| script.noteTextEditSelectAll(); | ||
| script.noteTextEditWrite(noteTextstring); | ||
| script.log("MOC index generated and sorted successfully."); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best remove the
Insert, just the name is enough