Searching for incoming links

In this question about incoming links I was able to find a macro to enumerate incoming links on a specified page.

I now have a heirarchy of pages that refer to each other and it is important that I know which pages don't have any incoming links at all since this implies that they have not been set up properly in the cross-reference web being created.

Does anyone know how I can search for pages that don't have incoming links?

Possibly a more generalised search based on existing incoming links would also be useful (say, all pages with incoming links from a specified page, or space).

Thanks for your help.

1 answer

1 accepted

This widget could not be displayed.

Hi Russell,

The following user macro lists all pages without any incoming links of a given space:

## @param Space:title=Space|type=string|required=true
#set($space =  $spaceManager.getSpace($paramSpace))
#set($pages = $pageManager.getPages($space, true))
#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($linkManager = $containerContext.getComponent('linkManager'))

<h1>Pages without incoming links in space "$space.getName()"</h1>
<ul>
  #foreach ( $page in $pages )
    #set($links = $linkManager.getIncomingLinksToContent($page.getContentEntityObject()))
    #if($links.size() == 0)
      <li>
        <a href="$req.contextPath/pages/viewpage.action?pageId=$page.getId()">$page.getTitle()</a>
      </li>
    #end
  #end
</ul>

Cheers,
Thomas

That's perfect! Thanks Thomas. Using your "template" I was even able to enhance it a little for my purposes. Thanks!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Tuesday in Confluence

Add-on evaluation with confluence templates

Atlassian market place contains number of Apps/Addons which improves the capability of out of the box Atlassian products. It is good to follow a plugin evaluation process before install add-ons. So t...

75 views 9 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you