Skip to content

Commit

Permalink
Merge branch 'master' into '0.4.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Yermolaiev <[email protected]>
  • Loading branch information
oermolaev committed Sep 22, 2016
2 parents af9252f + 8ea099b commit 1486ef4
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 8 deletions.
14 changes: 13 additions & 1 deletion SiteConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,16 @@ published: true
---
""")},

]
]

// Blog configuration for rss and atom feeds.
blog_feed {
title = 'Business Casual'
author {
name = 'John Doe'
email = '[email protected]'
}
posts_per_feed = 20
}

known_file_types = [".html", ".js", ".css", ".xml", ".markdown", ".jpg", ".svg", ".ttf", ".woff", ".eot"]
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = '0.4.2'
defaultTasks 'preview'

ext {
mainClassName = [project.group, 'Main'].join('.')
mainClassName = 'com.sysgears.grain.Main'
compatibilityVersion = JavaVersion.VERSION_1_5
}

Expand Down
25 changes: 25 additions & 0 deletions content/blog/atom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[${site.blog_feed.title}]]></title>
<link href="${site.url}${page.url}" rel="self"/>
<link href="${site.url}/"/>
<updated>${page.lastUpdated.format("yyyy-MM-dd'T'HH:mm:ssXXX")}</updated>
<id>${site.url}</id>
<author>
<name><![CDATA[${site.blog_feed.author.name}]]></name>
<% if (site.blog_feed.author.email) { %>
<email><![CDATA[${site.blog_feed.author.email}]]></email>
<% } %>
</author>
<generator uri="http://sysgears.com/grain/docs/latest/">Grain</generator>

<% page.posts.each { post -> %>
<entry>
<title type="html"><![CDATA[${post.title}]]></title>
<link href="${site.url}${post.url}"/>
<updated>${post.date.format("yyyy-MM-dd'T'HH:mm:ssXXX")}</updated>
<id><![CDATA[${site.url}${post.url}]]></id>
<content type="html"><![CDATA[${post.render().content}]]></content>
</entry>
<% } %>
</feed>
24 changes: 24 additions & 0 deletions content/blog/rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

<channel>
<title><![CDATA[${site.blog_feed.title}]]></title>
<link>${site.url}${page.url}</link>
<description>RSS Feed for <![CDATA[${site.blog_feed.title}]]></description>
<pubDate>${page.lastUpdated.format('E, d MMM yyyy HH:mm:ss Z')}</pubDate>
<generator uri="http://sysgears.com/grain/docs/latest/">Grain</generator>
<atom:link href="${site.url}${page.url}" rel="self" type="application/rss+xml" />

<% page.posts.each { post -> %>
<item>
<guid>${site.url}${post.url}</guid>
<title><![CDATA[${post.title}]]></title>
<pubDate>${post.date.format('E, d MMM yyyy HH:mm:ss Z')}</pubDate>
<link><![CDATA[${site.url}${post.url}]]></link>
<description><![CDATA[${post.render().content}]]></description>
</item>
<% } %>

</channel>

</rss>
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion content/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: front_page

banner:
slides: [/images/slide-1.jpg, images/slide-2.jpg, images/slide-3.jpg]
slides: [/images/slide-1.jpg, /images/slide-2.jpg, /images/slide-3.jpg]
brand_before: Welcome to
brand_name: Business Casual
brand_after: By **Start Bootstrap**
Expand Down
4 changes: 2 additions & 2 deletions theme/layouts/blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ <h2>${item.title}
<div class="col-lg-12 text-center">
<ul class="pager">
<% if (page.paginator.prev_page) { %>
<li class="previous"><a href="${page.paginator.prev_page}">&larr; Newer</a>
<li class="previous"><a href="${link page.paginator.prev_page}">&larr; Newer</a>
</li>
<% } %>
<% if (page.paginator.next_page) { %>
<li class="next"><a href="${page.paginator.next_page}">Older &rarr;</a>
<li class="next"><a href="${link page.paginator.next_page}">Older &rarr;</a>
</li>
<% } %>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions theme/layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ <h2>
<div class="col-lg-12 text-center">
<ul class="pager">
<% if (page.prev_post) { %>
<li class="previous"><a href="${page.prev_post.url}">&larr; Newer</a>
<li class="previous"><a href="${link page.prev_post.url}">&larr; Newer</a>
</li>
<% } %>
<% if (page.next_post) { %>
<li class="next"><a href="${page.next_post.url}">Older &rarr;</a>
<li class="next"><a href="${link page.next_post.url}">Older &rarr;</a>
</li>
<% } %>
</ul>
Expand Down
28 changes: 27 additions & 1 deletion theme/src/com/sysgears/theme/ResourceMapper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.sysgears.theme

import com.sysgears.grain.taglib.Site
import com.sysgears.theme.pagination.Paginator
import groovy.util.logging.Slf4j

/**
* Change pages urls and extend models.
*/
@Slf4j
class ResourceMapper {

/**
Expand All @@ -22,7 +24,9 @@ class ResourceMapper {
*/
def map = { resources ->

def refinedResources = resources.findResults(filterPublished).collect { Map resource ->
def filterResources = filterKnownTypes(resources).findResults(filterPublished)

def refinedResources = filterResources.collect { Map resource ->
customizeUrls <<
fillDates <<
resource
Expand All @@ -42,6 +46,12 @@ class ResourceMapper {
updatedResources += Paginator.paginate(items, 'posts', perPage, url, page + model)
}
switch (page.url) {
case '/blog/atom.xml':
case '/blog/rss.xml':
def lastUpdated = posts.max { it.updated.time }.updated
def feedPosts = posts.take(site.blog_feed.posts_per_feed as Integer)
updatedResources << (page + [posts: feedPosts, lastUpdated: lastUpdated])
break
case '/blog/':
applyPagination(posts, 3, page.url)
break
Expand Down Expand Up @@ -104,4 +114,20 @@ class ResourceMapper {
updated: it.updated ? Date.parse(site.datetime_format, it.updated) : new Date(it.lastUpdated as Long)]
it + update
}

private def filterKnownTypes = { resources ->
def (knownResources, unknownResources) = resources.split { resource ->
site.known_file_types.any { type -> resource.location.endsWith(type) }
}
unknownResources << handleUnknownResources
knownResources
}

private def handleUnknownResources = { resources ->
def locations = resources.collect { it -> it.location}
log.warn "WARNING: you tried to use files with unknown type: ${locations.join(",\n")}.\n" +
"These files wasn't handled to prevent unexpected errors.\n" +
"If you really want to use this files, please extend the list of known file types by adding " +
"needed file extensions to the \"known_file_types\" in the SiteConfig.groovy."
}
}

0 comments on commit 1486ef4

Please sign in to comment.