Smartsite version: 5.2, 5.3.
Problem
Smartsite's built-in macros for generating menus also generate too many AIM relations.
Cause
Smartsite offers no built-in macro that creates a menu the way most clients like to see it. XLinks is too sparse, Sitemap is too broad. We want something in-between. Usually we use XLinks or recursing XLinks to get what we want. Unfortunately every XLinked hyperlink is added to the AIM relations, causing a slow-down whilst saving articles.
Solution
A possible solution would be some granularity: when do we want to add the AIM relation, and when not? Well, we want the AIM relation only when the hyperlink needs to be visible. The easiest way to do that, is to avoid rendering unneeded hyperlinks and unneeded XLinks. We need to limit the XLink recursation: only recurse on a folder when it is part of the parent hierarchy. Thus, we avoid recursing on uncles and siblings.
Technical implementation
What we need to know is the parent hierarchy. Luckily, Smartsite offers the Parents macro. Then, we need to answer the question whether an item in the hierarchy needs recursing: no when it reflects an uncle or sibling of the current article, and yes when it reflects the article itself or any of its ancestors, all the way to an arbitrary top.
We can have Smartsite answer that question by executing a simple bit of VBScript:
returnValue = (InStr(strParents, strCurrent) > 0)
We catch the returnValue in a macro buffer and check that in the recursing XLink.
Technical considerations
The VBScript InStr function will find the item number 3 inside the item number 131. That would lead to a recursion of article 131, while we were hoping to avoid that. Therefore, we must make VBScript understand that we want 3, and nothing else. We achieve that by adding delimiters. Pipes come to mind, as they are not used in numbers. Therefore, when we build the parents list, we tell the Parens macro to use a pipe as its separator. And we also adorn the current item number with pipes. Thus, we ask whether |3| exists in |131|, which is false, subsequently avoiding recursion.
Full sample code
<se rem="1st parameter: the start item number; 2nd parameter: a pipe separated list of parent numbers, with the active item number as the last one" /><se type="script" language="vbscript" save="doRecurse" rem="recurse only when the evaluated item lies within the parents path">
Dim strParents, strCurrent</se>
strCurrent = "|{translationParam(1)}|"
strParents = "|{translationParam(2)}|"
returnValue = (InStr(strParents, strCurrent) > 0)
And of course we apply this to our XLink Recursion discussed earlier.
Happy coding!
cheerful
grumpy
creative
accomplished
nerdy
annoyed