Created
January 30, 2013 22:04
-
-
Save ChewingPencils/4677581 to your computer and use it in GitHub Desktop.
VPPageEventScript ... Prints all backlinks to a console window. Easy cut and paste for index pages. (Having to write an sort each page is way to taxing). To install, Create a new page: VPPageEventScript. Paste this in.
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
/* | |
The pageWasOpened function is called when a page is opened in a VoodooPad document for viewing. | |
*/ | |
function pageWasOpened(document, page) { | |
// print("pageWasOpened: " + page.displayName()); | |
//if (page.displayName() == "Category_Reading_Notes") | |
if (page.displayName().indexOf("Category_") !== -1) | |
pageList = listBacklinks(String(page.displayName()), page) | |
} | |
/* | |
The pageWasClosed function is called after a page is closed in a VoodooPad document. | |
Note: if a page is deleted, this method will not be called. | |
*/ | |
function pageWasClosed(document, page) { | |
// print("pageWasClosed: " + page.displayName()); | |
} | |
/* | |
The pageWasCreated function is called after a page is created in a VoodooPad document. | |
*/ | |
function pageWasCreated(document, page) { | |
// print("pageWasCreated: " + page.displayName()); | |
} | |
/* | |
The pageWasDeleted function is called after a page is deleted in a VoodooPad document. | |
*/ | |
function pageWasDeleted(document, pageName) { | |
// print("pageWasDeleted pageName: " + pageName); | |
} | |
/* | |
The textViewWillDisplay function is called right before a text item's NSTextView is about to display. You can take this opportunity to customize it with things like specific margins: | |
*/ | |
function textViewWillDisplay(document, page, textView) { | |
// uncomment to add a custom 30 pt margin in the sides of the text view. | |
[textView setTextContainerInset:NSMakeSize(30, 0)]; | |
} | |
function listBacklinks(catSearch, callingPage){ | |
var keys = document.keys(); | |
var pageList = "\n----\n\nBacklinks for page " + catSearch + " :\n\n"; | |
for (idx = 0; idx < keys.length(); idx++) { | |
var pageKey = keys[idx]; | |
var page = document.pageForKey(pageKey); | |
var pubValue = page.dataAsAttributedString(); | |
// print (pubValue); | |
if(pubValue != null){ | |
pubValue = String(pubValue) | |
if (pubValue.indexOf(catSearch) !== -1 && page.displayName() != catSearch && page.displayName() != "Category_Categories") { | |
pageList = pageList + "- " + page.displayName() + "\n"; | |
} | |
} | |
} | |
print(pageList); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment