Подскажите как заменить все ссылки в rss feed на свои посмотрите пример кода
var feed = parseRSS(rssFeed, fromLang, toLang);
return ContentService.createTextOutput(feed).setMimeType( ContentService.MimeType.RSS);
}
function parseRSS(feed, fromLang, toLang) {
var id = Utilities.base64Encode(feed + fromLang + toLang);
var cache = CacheService.getPublicCache();
var rss = cache.get(id);
if (rss != null) {
return rss;
}
var item, date, title, link, desc, guid;
var txt = UrlFetchApp.fetch(feed).getContentText();
var doc = Xml.parse(txt, false);
title = doc.getElement().getElement("channel").getElement( "title").getText();
rss = '<rss version="2.0">';
rss += "<channel><title>";
rss += LanguageApp.translate(title, fromLang, toLang);
rss += " (" + title + ")</title>";
var items = doc.getElement().getElement("channel").getElements ("item");
for (var i in items) {
try {
item = items[i];
title = item.getElement("title").getText();
link = item.getElement("link").getText();
date = item.getElement("pubDate").getText();
desc = item.getElement("description").getText();
guid = Utilities.base64Encode(link + fromLang + toLang);
title = LanguageApp.translate(title, fromLang, toLang);
desc = LanguageApp.translate(desc, fromLang, toLang, {contentType: "html"});
rss += "<item>";
rss += " <title>" + title + "</title>";
rss += " <link>" + link + "</link>";
rss += " <pubDate>" + date + "</pubDate>";
rss += " <guid>" + guid + "</guid>";
rss += " <description><![CDATA[" + desc + "]]></description>";
rss += "</item>";
} catch (e) {
Logger.log(e);
}
}
rss += "</channel></rss>";
cache.put(id, rss, 3600); // Cache the feed for an hour
return rss;
}
|