Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Turn Google Site pages into RSS feed
Copyright 2011 Martin Hawksey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
Uses the new ContentServices to generate a RSS feed from a set of Google Site pages.
To use install then Publish > Deploy as web app. You'll need to use the olds style
service url{service_key}&siteurl={url
To make available to aggregators like Google Reader the service needs to allow
anonymous access
function doGet(e) {
var siteUrl = decodeURIComponent(e.parameter.siteurl);
var page = decodeURIComponent(;
var cache = CacheService.getPrivateCache();// using Cache service to prevent too many urlfetch
var cached = cache.get(siteUrl+page);
if (cached != null) { // if value in cache return it
var feed = cached;
} else {
var feed = turnSitesPageIntoRSS(siteUrl,page);
try {
cache.put(siteUrl+page, feed, 21600);// cache for 1/4 day
} catch (e) {
return ContentService.createTextOutput(feed).setMimeType(ContentService.MimeType.RSS);
function turnSitesPageIntoRSS(siteUrl, page){
//var siteUrl = '';
//var page = 'custom-methods';
var output = "";
var site = SitesApp.getSiteByUrl(siteUrl);
var topPage = SitesApp.getPageByUrl(siteUrl+page);
var rssHead = '<?xml version="1.0" encoding="UTF-8" ?> '+
' <rss version="2.0"><channel>'+
' <title>'+site.getTitle()+': '+topPage.getTitle()+'</title>' +
' <description>'+site.getSummary()+'</description>'+
' <link>'+siteUrl+page+'</link>';
var rssFoot = ' </channel></rss>';
var items = "";
output = rssHead;
var pages = topPage.getAllDescendants();
for (i in pages){
items = '<item>'+
'<pubDate>'+Utilities.formatDate(pages[i].getLastUpdated(), 'GMT', 'EEE, d MMM yy HH:mm:ss z') +'</pubDate>'+
output += items;
output += rssFoot;
return output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment