mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
Implement atom feeds
This commit is contained in:
@@ -143,6 +143,9 @@ case class Context(settings: SystemSettingsService.SystemSettings, loginAccount:
|
|||||||
|
|
||||||
lazy val currentPath = request.getRequestURI.substring(request.getContextPath.length)
|
lazy val currentPath = request.getRequestURI.substring(request.getContextPath.length)
|
||||||
|
|
||||||
|
lazy val baseURL = request.getRequestURL.substring(0, request.getRequestURL.length - request.getRequestURI.length) + path
|
||||||
|
lazy val host = request.getServerName
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object from cache.
|
* Get object from cache.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
redirect("/")
|
redirect("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get("/activities.atom"){
|
||||||
|
contentType = "application/atom+xml; type=feed"
|
||||||
|
xml.feed(getRecentActivities())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set account information into HttpSession and redirect.
|
* Set account information into HttpSession and redirect.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
*/
|
*/
|
||||||
def datetime(date: Date): String = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)
|
def datetime(date: Date): String = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format java.util.Date to "yyyy-MM-dd'T'hh:mm:ss'Z'".
|
||||||
|
*/
|
||||||
|
def datetimeRFC3339(date: Date): String = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'").format(date).replaceAll("(\\d\\d)(\\d\\d)$","$1:$2")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format java.util.Date to "yyyy-MM-dd".
|
* Format java.util.Date to "yyyy-MM-dd".
|
||||||
*/
|
*/
|
||||||
|
|||||||
30
src/main/twirl/feed.scala.xml
Normal file
30
src/main/twirl/feed.scala.xml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
@(activities: List[model.Activity])(implicit context: app.Context)<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
@import context._
|
||||||
|
@import view.helpers._
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
||||||
|
@header(activities)
|
||||||
|
@activities.map { activity => @item(activity) }
|
||||||
|
</feed>
|
||||||
|
|
||||||
|
@header(activities: List[model.Activity]) = {<id>tag:@context.host,2013:gitbucket</id>
|
||||||
|
<title>Gitbucket's activities</title>
|
||||||
|
<link type="application/atom+xml" rel="self" href="@context.baseURL/activities.atom"/>
|
||||||
|
<author>
|
||||||
|
<name>Gitbucket</name>
|
||||||
|
<uri>@context.baseURL</uri>
|
||||||
|
</author>
|
||||||
|
<updated>@datetimeRFC3339(activities.map(_.activityDate).max)</updated>}
|
||||||
|
|
||||||
|
@item(activity: model.Activity) = {
|
||||||
|
<entry>
|
||||||
|
<id>tag:@context.host,@date(activity.activityDate):activity:@activity.activityId</id>
|
||||||
|
<published>@datetimeRFC3339(activity.activityDate)</published>
|
||||||
|
<updated>@datetimeRFC3339(activity.activityDate)</updated>
|
||||||
|
<link type="text/html" rel="alternate" href="@context.baseURL/@activity.userName/@activity.repositoryName" />
|
||||||
|
<title type="html">@activity.activityType</title>
|
||||||
|
<author>
|
||||||
|
<name>@activity.activityUserName</name>
|
||||||
|
<uri>@url(activity.activityUserName)</uri>
|
||||||
|
</author>
|
||||||
|
<content type="html">@activityMessage(activity.message)</content>
|
||||||
|
</entry>}
|
||||||
@@ -5,6 +5,9 @@
|
|||||||
@if(activities.isEmpty){
|
@if(activities.isEmpty){
|
||||||
No activity
|
No activity
|
||||||
} else {
|
} else {
|
||||||
|
<div style="text-align:right;">
|
||||||
|
<a href="@path/activities.atom"><img src="@assets/common/images/feed.png" alt="activities"></a>
|
||||||
|
</div>
|
||||||
@activities.map { activity =>
|
@activities.map { activity =>
|
||||||
<div class="block">
|
<div class="block">
|
||||||
@(activity.activityType match {
|
@(activity.activityType match {
|
||||||
|
|||||||
BIN
src/main/webapp/assets/common/images/feed.png
Normal file
BIN
src/main/webapp/assets/common/images/feed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 691 B |
Reference in New Issue
Block a user