Skip to content

Commit

Permalink
Restoring 'blog' content on project pages
Browse files Browse the repository at this point in the history
This restores the latest blog items being displayed on each project page. Blogs are taken based on the tags applies to the "ignite realtime blogs" category of Discourse.

As Discourse's RSS feed does not go back very far, and doesn't seem to offer an RSS feed for the combination of 'category' and 'tag', the amount of history that is displayed is limited.
  • Loading branch information
guusdk committed Jun 28, 2024
1 parent b8dac79 commit 3a35b5d
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 68 deletions.
35 changes: 27 additions & 8 deletions src/main/java/org/jivesoftware/site/FeedManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

/**
* FeedManager
Expand Down Expand Up @@ -46,7 +45,7 @@ public List<SyndEntry> getBlogFeedEntries(String baseUrl, String feedUrl) {
try {
SyndFeed feed = feedFetcher.retrieveFeed(new URL(baseUrl + "/" + feedUrl ));
if (null != feed) {
return (List<SyndEntry>)feed.getEntries();
return (List<SyndEntry>)feed.getEntries().stream().filter(Objects::nonNull).collect(Collectors.toList());
}
} catch (Exception e) {
Log.warn("Problem getting Community Blog RSS feed '{}'.", baseUrl + "/" + feedUrl, e);
Expand All @@ -55,15 +54,35 @@ public List<SyndEntry> getBlogFeedEntries(String baseUrl, String feedUrl) {
}

public List<SummaryFeedItem> getItems( String baseUrl, String feedUrl, int max )
{
return getTaggedItems(baseUrl, feedUrl, null, max);
}

public List<SummaryFeedItem> getTaggedItems( String baseUrl, String feedUrl, String tag, int max )
{
final List<SummaryFeedItem> result = new ArrayList<>( max );

final List<SyndEntry> entries = getBlogFeedEntries( baseUrl, feedUrl );
for ( int i=0; i < entries.size() && i < max; i++ )
{
result.add( new FeedItem( getJSON( entries.get( i ).getLink() ) ) );
for (final SyndEntry entry : entries) {
if (entry == null) {
continue;
}
final JSONObject json = getJSON(entry.getLink());
if (json == null) {
continue;
}
final FeedItem item = new FeedItem(json);
if (tag != null) {
if (Arrays.stream(item.getTags()).anyMatch(t -> t.equalsIgnoreCase(tag))) {
result.add(item);
}
} else {
result.add(item);
}
if (result.size() >= max) {
break;
}
}

return result;
}

Expand Down
31 changes: 3 additions & 28 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<%@ page import="org.jivesoftware.site.Versions" %>
<%@ page import="org.jivesoftware.webservices.RestClient" %>
<%@ page import="org.jivesoftware.site.FeedManager" %>

<%@ page import="org.jivesoftware.site.Versions"%>
<%@ page import="org.jivesoftware.webservices.RestClient"%>
<%@ page import="org.jivesoftware.site.FeedManager"%>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib uri="http://igniterealtime.org/website/tags" prefix="ir" %>
<%
String baseUrl = config.getServletContext().getInitParameter("discourse_baseurl");
Expand All @@ -17,7 +15,6 @@
request.setAttribute( "feedManager", FeedManager.getInstance() );
request.setAttribute( "restClient", new RestClient() );
%>

<html>
<head>
<title>a real time collaboration community site</title>
Expand Down Expand Up @@ -119,35 +116,13 @@
<!-- END blog header -->

<%-- Show blog feed --%>

<cache:cache time="600" key="${baseUrl.concat('/c/blogs/ignite-realtime-blogs.rss')}">
<c:forEach items="${feedManager.getItems( baseUrl, '/c/blogs/ignite-realtime-blogs.rss', 5 )}" var="item" varStatus="status">
<ir:blogpost item="${item}" isOdd="${status.count % 2 != 0}"/>
</c:forEach>
</cache:cache>

<%--<% try { %>--%>
<%--<%--%>
<%--RestClient client = new RestClient();--%>
<%--String blogSearchUrl = restBaseUrl + "/search/places?filter=search(Ignite,Realtime,Blog)&filter=type(blog)";--%>
<%--JSONObject result = client.get(blogSearchUrl);--%>
<%--JSONArray results = result.getJSONArray("list");--%>
<%--JSONObject blog = (JSONObject)results.get(0);--%>
<%--String contentsUrl = blog.getJSONObject("resources").getJSONObject("contents").getString("ref");--%>

<%--String blogRestUrl = contentsUrl + "?count=5";--%>
<%--result = client.get(blogRestUrl);--%>
<%--JSONArray posts = result.getJSONArray("list");--%>
<%--request.setAttribute("posts", posts);--%>
<%--%>--%>
<%--<jsp:include page="/includes/blogposts.jsp" />--%>
<%--<% } catch (Exception e) { %>--%>
<%--<cache:usecached />--%>
<%--<% } %>--%>
<%--</cache:cache>--%>
</div>

<style type="text/css"></style>
<!-- END 'latest blog entries' column -->
</div>
<!-- END home page body content area -->
Expand Down
38 changes: 34 additions & 4 deletions src/main/webapp/projects/asterisk/index.jsp
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<%@ page import="org.jivesoftware.site.Versions"%>

<%@ page import="org.jivesoftware.webservices.RestClient"%>
<%@ page import="org.jivesoftware.site.FeedManager"%>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib uri="http://igniterealtime.org/website/tags" prefix="ir" %>
<%
String baseUrl = config.getServletContext().getInitParameter("discourse_baseurl");
if ( baseUrl == null || baseUrl.isEmpty() )
{
baseUrl = "https://discourse.igniterealtime.org/";
}
request.setAttribute( "baseUrl", baseUrl );
request.setAttribute( "feedManager", FeedManager.getInstance() );
request.setAttribute( "restClient", new RestClient() );
%>
<html>
<head>
<title>Asterisk-IM</title>
Expand Down Expand Up @@ -88,8 +100,26 @@ fully supported in the <a href="../spark/">Spark</a> IM client. Read more about
</div>
</div>
<!-- END small panel -->



<!-- BEGIN 'latest blog entries' column -->
<div id="ignite_home_body_leftcol">
<!-- BEGIN blog header -->
<div id="ignite_blog_header">
<span id="ignite_blog_header_label">
Latest <a href="${baseUrl}/tags/c/blogs/ignite-realtime-blogs/5/asterisk">Blog</a> Entries
</span>
</div>
<!-- END blog header -->

<%-- Show blog feed --%>
<cache:cache time="600" key="${baseUrl.concat('/tags/c/blogs/ignite-realtime-blogs/5/asterisk')}">
<c:forEach items="${feedManager.getTaggedItems( baseUrl, '/c/blogs/ignite-realtime-blogs.rss', 'asterisk', 5 )}" var="item" varStatus="status">
<ir:blogpost item="${item}" isOdd="${status.count % 2 != 0}"/>
</c:forEach>
</cache:cache>
</div>
<!-- END 'latest blog entries' column -->

</div>
<!-- END left column (main content) -->

Expand Down
38 changes: 34 additions & 4 deletions src/main/webapp/projects/botz/index.jsp
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<%@ page import="org.jivesoftware.site.Versions"%>

<%@ page import="org.jivesoftware.webservices.RestClient"%>
<%@ page import="org.jivesoftware.site.FeedManager"%>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib uri="http://igniterealtime.org/website/tags" prefix="ir" %>
<%
String baseUrl = config.getServletContext().getInitParameter("discourse_baseurl");
if ( baseUrl == null || baseUrl.isEmpty() )
{
baseUrl = "https://discourse.igniterealtime.org/";
}
request.setAttribute( "baseUrl", baseUrl );
request.setAttribute( "feedManager", FeedManager.getInstance() );
request.setAttribute( "restClient", new RestClient() );
%>
<html>
<head>
<title>Botz</title>
Expand Down Expand Up @@ -74,8 +86,26 @@
</div>
</div>
<!-- END small panel -->



<!-- BEGIN 'latest blog entries' column -->
<div id="ignite_home_body_leftcol">
<!-- BEGIN blog header -->
<div id="ignite_blog_header">
<span id="ignite_blog_header_label">
Latest <a href="${baseUrl}/tags/c/blogs/ignite-realtime-blogs/5/botz">Blog</a> Entries
</span>
</div>
<!-- END blog header -->

<%-- Show blog feed --%>
<cache:cache time="600" key="${baseUrl.concat('/tags/c/blogs/ignite-realtime-blogs/5/botz')}">
<c:forEach items="${feedManager.getTaggedItems( baseUrl, '/c/blogs/ignite-realtime-blogs.rss', 'botz', 5 )}" var="item" varStatus="status">
<ir:blogpost item="${item}" isOdd="${status.count % 2 != 0}"/>
</c:forEach>
</cache:cache>
</div>
<!-- END 'latest blog entries' column -->

</div>
<!-- END left column (main content) -->

Expand Down
38 changes: 33 additions & 5 deletions src/main/webapp/projects/openfire/index.jsp
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<%@ page import="org.jivesoftware.site.Versions"%>

<%@ page import="org.jivesoftware.webservices.RestClient"%>
<%@ page import="org.jivesoftware.site.FeedManager"%>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="i" %>
<%@ taglib uri="http://igniterealtime.org/website/tags" prefix="ir" %>
<%
String baseUrl = config.getServletContext().getInitParameter("discourse_baseurl");
if ( baseUrl == null || baseUrl.isEmpty() )
{
baseUrl = "https://discourse.igniterealtime.org/";
}
request.setAttribute( "baseUrl", baseUrl );
request.setAttribute( "feedManager", FeedManager.getInstance() );
request.setAttribute( "restClient", new RestClient() );
%>
<html>
<head>
<title>Openfire Server</title>
Expand Down Expand Up @@ -91,8 +102,25 @@
</div>
</div>
<!-- END small panel -->



<!-- BEGIN 'latest blog entries' column -->
<div id="ignite_home_body_leftcol">
<!-- BEGIN blog header -->
<div id="ignite_blog_header">
<span id="ignite_blog_header_label">
Latest <a href="${baseUrl}/tags/c/blogs/ignite-realtime-blogs/5/openfire">Blog</a> Entries
</span>
</div>
<!-- END blog header -->

<%-- Show blog feed --%>
<cache:cache time="600" key="${baseUrl.concat('/tags/c/blogs/ignite-realtime-blogs/5/openfire')}">
<c:forEach items="${feedManager.getTaggedItems( baseUrl, '/c/blogs/ignite-realtime-blogs.rss', 'openfire', 5 )}" var="item" varStatus="status">
<ir:blogpost item="${item}" isOdd="${status.count % 2 != 0}"/>
</c:forEach>
</cache:cache>
</div>
<!-- END 'latest blog entries' column -->

</div>
<!-- END left column (main content) -->
Expand Down
38 changes: 34 additions & 4 deletions src/main/webapp/projects/pade/index.jsp
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<%@ page import="org.jivesoftware.site.Versions"%>

<%@ page import="org.jivesoftware.webservices.RestClient"%>
<%@ page import="org.jivesoftware.site.FeedManager"%>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib uri="http://igniterealtime.org/website/tags" prefix="ir" %>
<%
String baseUrl = config.getServletContext().getInitParameter("discourse_baseurl");
if ( baseUrl == null || baseUrl.isEmpty() )
{
baseUrl = "https://discourse.igniterealtime.org/";
}
request.setAttribute( "baseUrl", baseUrl );
request.setAttribute( "feedManager", FeedManager.getInstance() );
request.setAttribute( "restClient", new RestClient() );
%>
<html>
<head>
<title>Pade</title>
Expand Down Expand Up @@ -92,8 +104,26 @@
</div>
</div>
<!-- END small panel -->



<!-- BEGIN 'latest blog entries' column -->
<div id="ignite_home_body_leftcol">
<!-- BEGIN blog header -->
<div id="ignite_blog_header">
<span id="ignite_blog_header_label">
Latest <a href="${baseUrl}/tags/c/blogs/ignite-realtime-blogs/5/pade">Blog</a> Entries
</span>
</div>
<!-- END blog header -->

<%-- Show blog feed --%>
<cache:cache time="600" key="${baseUrl.concat('/tags/c/blogs/ignite-realtime-blogs/5/pade')}">
<c:forEach items="${feedManager.getTaggedItems( baseUrl, '/c/blogs/ignite-realtime-blogs.rss', 'pade', 5 )}" var="item" varStatus="status">
<ir:blogpost item="${item}" isOdd="${status.count % 2 != 0}"/>
</c:forEach>
</cache:cache>
</div>
<!-- END 'latest blog entries' column -->

</div>
<!-- END left column (main content) -->

Expand Down
35 changes: 33 additions & 2 deletions src/main/webapp/projects/smack/index.jsp
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<%@ page import="org.jivesoftware.site.Versions"%>

<%@ page import="org.jivesoftware.webservices.RestClient"%>
<%@ page import="org.jivesoftware.site.FeedManager"%>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib uri="http://igniterealtime.org/website/tags" prefix="ir" %>
<%
String baseUrl = config.getServletContext().getInitParameter("discourse_baseurl");
if ( baseUrl == null || baseUrl.isEmpty() )
{
baseUrl = "https://discourse.igniterealtime.org/";
}
request.setAttribute( "baseUrl", baseUrl );
request.setAttribute( "feedManager", FeedManager.getInstance() );
request.setAttribute( "restClient", new RestClient() );
%>
<html>
<head>
<title>Smack API</title>
Expand Down Expand Up @@ -91,6 +103,25 @@
</div>
<!-- END small panel -->

<!-- BEGIN 'latest blog entries' column -->
<div id="ignite_home_body_leftcol">
<!-- BEGIN blog header -->
<div id="ignite_blog_header">
<span id="ignite_blog_header_label">
Latest <a href="${baseUrl}/tags/c/blogs/ignite-realtime-blogs/5/smack">Blog</a> Entries
</span>
</div>
<!-- END blog header -->

<%-- Show blog feed --%>
<cache:cache time="600" key="${baseUrl.concat('/tags/c/blogs/ignite-realtime-blogs/5/smack')}">
<c:forEach items="${feedManager.getTaggedItems( baseUrl, '/c/blogs/ignite-realtime-blogs.rss', 'smack', 5 )}" var="item" varStatus="status">
<ir:blogpost item="${item}" isOdd="${status.count % 2 != 0}"/>
</c:forEach>
</cache:cache>
</div>
<!-- END 'latest blog entries' column -->

</div>
<!-- END left column (main content) -->

Expand Down
Loading

0 comments on commit 3a35b5d

Please sign in to comment.