package org.mnode.whistlepost.model;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;

@Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
public class Article extends Page {

    public String getSummary() {
        if (getPars().length > 0) {
            // remove all markup from summary..
            return getPars()[0].replaceAll("<\\w.*>", "");
        } else {
            return "";
        }
    }

    public String[] getPars() {
        return resource.getValueMap().get("pars", new String[] {});
    }

    public String getPublishedDate() {
        return resource.getValueMap().get("date", String.class);
    }

    public String getMedia() {
        return resource.getValueMap().get("media", String.class);
    }
}

@@ -159,32 +159,222 @@
 ing.
-models.annotations.Model
+api.resource.ResourceResolver;%0Aimport org.apache.sling.models.annotations.Model;%0Aimport org.apache.sling.models.annotations.injectorspecific.SlingObject;%0A%0Aimport java.util.Arrays;%0Aimport java.util.stream.Collectors
 ;%0A%0A@
@@ -478,16 +478,83 @@
 Page %7B%0A%0A
+    @SlingObject%0A    protected ResourceResolver resourceResolver;%0A%0A
     publ
@@ -1023,24 +1023,24 @@
 etMedia() %7B%0A
-
         retu
@@ -1098,11 +1098,917 @@
 );%0A    %7D
+%0A%0A    public Article getSidebar() %7B%0A        Resource sidebarResource = null;%0A%0A        String sidebar = resource.getValueMap().get(%22sidebar%22, String.class);%0A        if (sidebar != null) %7B%0A            if (sidebar.startsWith(%22/%22)) %7B%0A                sidebarResource = resourceResolver.getResource(sidebar);%0A            %7D else %7B%0A                sidebarResource = resourceResolver.getResource(resource.getParent(), sidebar);%0A            %7D%0A        %7D%0A%0A        if (sidebarResource != null) %7B%0A            return sidebarResource.adaptTo(Article.class);%0A        %7D else %7B%0A            return null;%0A        %7D%0A    %7D%0A%0A    public Iterable%3CArticle%3E getRelated() %7B%0A        String%5B%5D related = resource.getValueMap().get(%22related%22, new String%5B%5D %7B%7D);%0A%0A        return Arrays.stream(related).map(p -%3E resourceResolver.getResource(resource.getParent(), p).adaptTo(Article.class))%0A                .collect(Collectors.toList());%0A    %7D
 %0A%7D%0A

Support sidebar and related articles