Search in sources :

Example 1 with MarkdownProcessor

use of org.markdown4j.server.MarkdownProcessor in project blogwt by billy1380.

the class FeedServlet method getFeed.

protected SyndFeed getFeed(HttpServletRequest request) throws IOException, FeedException {
    SyndFeed feed = new SyndFeedImpl();
    String url = ServletHelper.constructBaseUrl(request);
    feed.setTitle(PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.TITLE).value);
    feed.setLink(url + "/feed");
    feed.setDescription(PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.EXTENDED_TITLE).value);
    List<Post> posts;
    Pager pager = PagerHelper.createDefaultPager();
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    SyndEntry entry;
    SyndContent description;
    MarkdownProcessor processor = new MarkdownProcessor();
    do {
        posts = PostServiceProvider.provide().getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
        if (posts != null) {
            PagerHelper.moveForward(pager);
            for (Post post : posts) {
                entry = new SyndEntryImpl();
                entry.setTitle(post.title);
                entry.setLink(url + "/#" + PageType.PostDetailPageType.asTargetHistoryToken(post.slug));
                entry.setPublishedDate(post.published);
                description = new SyndContentImpl();
                description.setType("text/HTML");
                description.setValue(processor.process(post.summary));
                entry.setDescription(description);
                entries.add(entry);
            }
        }
    } while (posts != null && posts.size() >= pager.count.intValue());
    feed.setEntries(entries);
    return feed;
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) MarkdownProcessor(org.markdown4j.server.MarkdownProcessor) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndContent(com.rometools.rome.feed.synd.SyndContent) Pager(com.willshex.blogwt.shared.api.Pager) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Example 2 with MarkdownProcessor

use of org.markdown4j.server.MarkdownProcessor in project blogwt by billy1380.

the class StaticPosts method showPosts.

protected void showPosts(List<Post> posts, StringBuffer markup) {
    MarkdownProcessor processor = new MarkdownProcessor();
    processor.registerPlugins(new IncludePlugin());
    String link, body;
    for (Post post : posts) {
        body = "Empty... :imp:";
        if (post.summary != null && post.summary.length() > 0) {
            body = post.summary;
        }
        link = "/#" + PageType.PostDetailPageType.asTargetHistoryToken(PostHelper.getSlug(post));
        markup.append("<div><a href=\"");
        markup.append(link);
        markup.append("\">");
        markup.append(process("##" + post.title));
        markup.append("</a><div><span>");
        markup.append(DateTimeHelper.ago(post.published));
        markup.append("</span> by <img src=\"");
        markup.append(post.author.avatar);
        markup.append("?s=");
        markup.append(UserHelper.AVATAR_HEADER_SIZE);
        markup.append("&default=retro\" /> ");
        markup.append(UserHelper.handle(post.author));
        markup.append("</div><div>");
        markup.append(process(body));
        markup.append("</div><a href=\"");
        markup.append(link);
        markup.append("\">Read More</a></div>");
    }
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) IncludePlugin(org.markdown4j.server.IncludePlugin) MarkdownProcessor(org.markdown4j.server.MarkdownProcessor)

Aggregations

Post (com.willshex.blogwt.shared.api.datatype.Post)2 MarkdownProcessor (org.markdown4j.server.MarkdownProcessor)2 SyndContent (com.rometools.rome.feed.synd.SyndContent)1 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)1 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)1 Pager (com.willshex.blogwt.shared.api.Pager)1 ArrayList (java.util.ArrayList)1 IncludePlugin (org.markdown4j.server.IncludePlugin)1