Skip to content

Instantly share code, notes, and snippets.

@ChewingPencils
Created January 30, 2013 22:04
Show Gist options
  • Save ChewingPencils/4677581 to your computer and use it in GitHub Desktop.
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.
/*
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