Orphaned Pages Script Error

svs's Avatar

svs

27 Aug, 2018 06:27 PM

I've created a new Voodoopad document and pasted in the code from here:

https://www.voodoopad.com/documentation/page-events/

into my VPPageEventScript page

When I open the "Orphaned Pages" page the console in VP opens with the following text:

TypeError: keys.length is not a function. (In 'keys.length()', 'keys.length' is 5)
line: 9
column: 32

And orphaned pages are not displayed.

Anyone know what the problem might be? This is a new VP doc and does have orphaned pages. I'm assuming something's wrong with the VPPageEventScript script for orphaned pages.

  1. 1 Posted by Sarah on 28 Aug, 2018 05:00 PM

    Sarah's Avatar

    Hi svs,

    This code should work instead:

    function makeOrphanedPage(document) {
    
        var linkedPages = {}; // using a hash table here because it's convenient.
        var orphanedPages = [];
        var summaryPageName = "Orphaned Pages";
    
        /* Collect all linked pages. */
        var keys = document.keys();
        for (i = 0; i < keys.length; i++) {
            var page = document.pageForKey(keys[i]);
    
            if (!page.isText() || (page.key() == "orphaned pages")) {
                continue;
            }
    
            var pageContent = page.dataAsAttributedString();
            var linkedPageNames = document.linkedPageNamesInAttributedString(pageContent);
    
            for (j = 0; j < linkedPageNames.length; j++) {
    
                linkedKey = linkedPageNames[j].vpkey();
    
    
                // ignore self links.
                if (!linkedKey.isEqualToString(page.key())) {
                    linkedPages[linkedKey] = "";
                }
            }
        }
    
        /* Now compare the linked pages with all pages to find the orphaned ones. */
        for (i = 0; i < keys.length; i++) {
            var key = keys[i];
            if (linkedPages[key] == null) {
                orphanedPages.push(key);
            }
        }
        
        /* Create a summary page and open it. */
        var summaryPage = document.createNewPageWithName(summaryPageName);
        summaryPage.setDataAsString(summaryPageName + "\n\n" + orphanedPages.join("\n"));
    }
    
    function pageWasOpened(document, page) {
        if (page.key() == "orphaned pages") {
            makeOrphanedPage(document);
        }
    }
    

    the keys.length() has been replaced with keys.length. I apologize for the trouble. We will update the documentation as soon as we can. Let me know if you run into anymore issues.

  2. 2 Posted by svs on 28 Aug, 2018 08:21 PM

    svs's Avatar

    Thank you so much, that worked perfectly!

  3. svs closed this discussion on 29 Aug, 2018 05:57 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac