Filter duplicate stories

It is possible to filter duplicate stories in a page. As for example, two widgets which fetches latest articles from a publication can fetch duplicate article. So, if those two widgets are placed in a section they can display same article twice. A client side javascript solution has been implemented so that widgets those fetch latest articles will not show same article more than one. blog navigation, filmstrip, list, stories, trailers and video widget will support filtering of duplicate stories. But source must be latest articles and filtering must be enabled from the widget.

In the <article:list/> we set the max attribute to twice the number of size specified in the widget. If this tag returns articles more than specified in the widget then we add a CSS class with each article and resulted articles will be hidden. The CSS class is adding by the decorator CssClassAdderDecorator. We also add a CSS class in widget's main div. Pattern of this CSS class is wf-filtered-list-size-xyz where xyz is the number of articles to fetch.

We have a script that runs on page load. The scripts starts filtering from the bottom of the result list. The script performs the following operation -

  • will look for html element having class with the pattern wf-filtered-list-size-

  • will extract number of articles to display from class name

  • will look for article's having class pattern wf-article-

  • will check whether this article has been displayed or not. If not displayed then it will display otherwise it will hide this article

To apply filtering to a new content type CssClassAdderDecorator must be added in the content type definition. This decorator add css class wf-article-xyz to the article.fields map. Here xyz is the article id. In the template article's parent should have the class wf-filtered-list-size-<listSize> and article must use the class ${article.fields.wfClass}

In the widget we specify how many latest articles to fetch. Therefore, we expect that if this number of article returns by the tag then in the publication all of them will be displayed. In the script after filtering is done it will check the number of displayed article for each widget. If it is less than the required number then it will display some hidden articles from this widget to make the number equal.