Skip to content

Commit ef1c784

Browse files
committed
Add rss icon to page.
- also defaults to current year for posts api
1 parent 208deba commit ef1c784

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

public/img/rss_icon_24px_orange.svg

+5
Loading

public/index.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
<title>dev-web firehose</title>
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7-
<link rel="manifest" href="manifest.json">
87
<meta name="theme-color" content="#37474F">
98
<meta name="description" content="Developer resource from Google Web DevRel and from around the web.">
109
<meta name="keywords" content="HTML,CSS,JavaScript,web,PWA,tutorials,code,tweets">
1110
<meta name="author" content="Eric Bidelman">
1211
<meta name="google-site-verification" content="j4g2UAPd-Fnxh2o_daravb8lvXwZuatJt5kVSbdM0Fc" />
12+
<link rel="alternate" type="application/rss+xml" href="https://devwebfeed.appspot.com/posts/2018?format=rss" title="DevWeb Firehose RSS feed">
13+
<link rel="manifest" href="manifest.json">
1314
<link rel="icon" sizes="192x192" href="img/firehose.png">
1415
<link rel="shortcut icon" href="img/firehose.png">
1516
<link rel="stylesheet" href="styles.css">
@@ -48,7 +49,12 @@
4849
<h1 class="title layout center-center"><a href="/">dev-web firehose</a></h1>
4950
<h4 class="subtitle layout center-center">
5051
articles, tuts, <a href="?tweets">tweets</a>, code snippets
51-
<a href="#" onclick="return toggleHelp()" class="layout"><img src="img/help_24px.svg" height="18" width="18" class="helpicon"></a>
52+
<a href="#" onclick="return toggleHelp()" class="layout">
53+
<img src="img/help_24px.svg" height="18" width="18" class="helpicon" title="Help" alt="Help">
54+
</a>
55+
<a href="https://devwebfeed.appspot.com/posts/2018?format=rss" target="_blank" class="layout">
56+
<img src="img/rss_icon_24px_orange.svg" width="18" height="18" class="rssicon" title="Subscribe to RSS feed" alt="Subscribe to RSS feed">
57+
</a>
5258
</h4>
5359
</hgroup>
5460
<div id="filtering" class="layout center-center" hidden>

public/rss.mjs

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import url from 'url';
18+
const URL = url.URL;
1719
import RSS from 'rss';
1820

1921
class RSSFeed {
@@ -22,14 +24,15 @@ class RSSFeed {
2224
this.feedUrl = feedUrl;
2325
}
2426

25-
create(posts, feedUrl) {
27+
create(posts) {
28+
const siteOrigin = new URL(this.feedUrl).origin;
2629
const feed = new RSS({
2730
/* eslint-disable camelcase */
2831
title: 'DevWeb Firehose',
2932
description: 'Developer resource from Google Web DevRel and from around the web',
3033
feed_url: this.feedUrl,
31-
site_url: 'https://devwebfeed.appspot.com/',
32-
image_url: 'https://devwebfeed.appspot.com/img/firehose.png',
34+
site_url: siteOrigin,
35+
image_url: `${siteOrigin}/img/firehose.png`,
3336
pubDate: new Date(),
3437
ttl: 180,// mins for feed to be cached.
3538
// custom_namespaces: {

public/styles.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ header h4 {
111111
line-height: 1.2;
112112
}
113113

114-
.helpicon {
114+
.helpicon, .rssicon {
115115
margin-left: calc(var(--default-padding) / 2);
116116
}
117117

server.mjs

+1-5
Original file line numberDiff line numberDiff line change
@@ -394,17 +394,13 @@ app.post('/posts', async (req, res) => {
394394
// });
395395

396396
app.get('/posts/:year?/:month?/:day?', async (req, res) => {
397-
const year = req.params.year;
397+
const year = req.params.year || util.currentYear;
398398
// Pad values if missing leading '0'.
399399
const month = req.params.month ? req.params.month.padStart(2, '0') : null;
400400
const day = req.params.day ? req.params.day.padStart(2, '0') : null;
401401
const maxResults = req.query.maxresults ? Number(req.query.maxresults) : null;
402402
const format = req.query.format || null;
403403

404-
if (!year) {
405-
return res.status(400).send({error: 'No year specified.'});
406-
}
407-
408404
const rssPosts = await feeds.collectRSSFeeds();
409405
const posts = util.uniquePosts(
410406
await dbHelper.getPosts(year, month, day, rssPosts, maxResults));

0 commit comments

Comments
 (0)