Action

Show Backlinks

Posted by garbonsai, Last update 2 months ago

UPDATES

2 months ago

  • Renamed

Finds drafts that link to the current draft using wiki-style links and displays them in a temporary workspace. Accounts for [[Title]], [[Title/Section]] and [[u:UUID]] links.

Steps

  • script

    // get the display title of the draft. escape any forward slashes.
    let title = draft.displayTitle.replace( /\//g, '\/' );
    
    // build the query string, accounting for backlinks to markers
    let query = title.length !== 0 ?
    	`"[[${title}]]" or "[[${title}/" or "[[u:${draft.uuid}]]"` :
    	`[[u:${draft.uuid}]]`;
    
    // build a temporary workspace
    let ws = Workspace.create();
    ws.loadFolder = 'all';
    ws.queryString = query;
    
    // if it isn't empty, load the workspace
    if ( ws.query( 'all' ).length !== 0 ) {
    	ws.name = 'Backlinks';
    	ws.setAllSort( 'name', false );
    	app.applyWorkspace( ws );
    	app.showDraftList();
    
    // display an error if no backlinks were found
    } else {
    	app.displayErrorMessage( 'No backlinks found.' );
    	context.cancel( 'No backlinks found.' );
    }

Options

  • After Success Nothing
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.