Skip to content

Commit 00fa0fa

Browse files
committed
init code
1 parent d0269d4 commit 00fa0fa

File tree

9 files changed

+82
-0
lines changed

9 files changed

+82
-0
lines changed

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ module.exports = {
110110
HOME: '/home',
111111
BLOG: 'https://www.topcoder-dev.com/blog',
112112
BLOG_FEED: 'https://www.topcoder.com/blog/feed/',
113+
THRIVE_FEED: 'https://topcoder-dev.com/api/feeds/thrive',
113114
COMMUNITY: 'https://community.topcoder-dev.com',
114115
FORUMS: 'https://apps.topcoder-dev.com/forums',
115116
FORUMS_VANILLA: 'https://vanilla.topcoder-dev.com',

config/production.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module.exports = {
5858
CS: 'https://cs.topcoder.com',
5959
},
6060
EMAIL_VERIFY_URL: 'http://www.topcoder.com/settings/account/changeEmail',
61+
THRIVE_FEED: 'https://topcoder.com/api/feeds/thrive',
6162
},
6263
/* Filestack configuration for uploading Submissions
6364
* These are for the production back end */

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
"redux-promise": "^0.6.0",
141141
"request-ip": "^2.0.2",
142142
"require-context": "^1.1.0",
143+
"rss": "^1.2.2",
143144
"rss-parser": "^3.12.0",
144145
"serialize-javascript": "^2.1.1",
145146
"serve-favicon": "^2.5.0",

src/server/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import mmLeaderboardRouter from './routes/mmLeaderboard';
3131
import growsurfRouter from './routes/growsurf';
3232
import gSheetsRouter from './routes/gSheet';
3333
import blogRouter from './routes/blog';
34+
import feedsRouter from './routes/feeds';
3435

3536
/* Dome API for topcoder communities */
3637
import tcCommunitiesDemoApi from './tc-communities';
@@ -143,6 +144,7 @@ async function onExpressJsSetup(server) {
143144
server.use('/api/growsurf', growsurfRouter);
144145
server.use('/api/gsheets', gSheetsRouter);
145146
server.use('/api/blog', blogRouter);
147+
server.use('/api/feeds', feedsRouter);
146148

147149
// serve demo api
148150
server.use(

src/server/routes/feeds.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* The routes that expose assets and content from Contentful CMS to the CDN.
3+
*/
4+
5+
import express from 'express';
6+
import RSS from 'rss';
7+
import ReactDOMServer from 'react-dom/server';
8+
import md from 'utils/markdown';
9+
import {
10+
getService,
11+
} from '../services/contentful';
12+
13+
const cors = require('cors');
14+
15+
const routes = express.Router();
16+
17+
// Enables CORS on those routes according config above
18+
// ToDo configure CORS for set of our trusted domains
19+
routes.use(cors());
20+
routes.options('*', cors());
21+
22+
routes.get('/thrive', async (req, res, next) => {
23+
try {
24+
const data = await getService('EDU', 'master', true).queryEntries({
25+
content_type: 'article',
26+
limit: 20,
27+
order: '-sys.createdAt',
28+
include: 2,
29+
});
30+
const feed = new RSS({
31+
title: 'Topcoder Thrive - RSS feed',
32+
description: 'Tutorials And Workshops That Matter | Thrive | Topcoder',
33+
feed_url: 'https://topcoder.com/api/feeds/thrive',
34+
site_url: 'https://topcoder.com/thrive',
35+
image_url: 'https://images.ctfassets.net/b5f1djy59z3a/5kicYrFi5GoMqWs0ccsMsM/d3f4a4315588df5bdf0096208eb13581/Topcoder_Logo_200px.png',
36+
docs: 'https://www.topcoder.com/thrive/tracks?track=Topcoder',
37+
webMaster: '<kiril@wearetopcoder.com> Kiril Kartunov',
38+
copyright: '2021 - today, Topcoder',
39+
language: 'en',
40+
categories: ['Competitive Programming', 'Data Science', 'Design', 'Development', 'QA', 'Gig work', 'Topcoder'],
41+
ttl: '60',
42+
});
43+
if (data && data.total) {
44+
data.items.forEach((entry) => {
45+
feed.item({
46+
title: entry.fields.title,
47+
description: ReactDOMServer.renderToString(md(entry.fields.content)),
48+
url: `https://topcoder.com/thrive/articles/${entry.fields.slug || encodeURIComponent(entry.fields.title)}`,
49+
date: entry.fields.creationDate,
50+
categories: entry.fields.tags,
51+
author: entry.fields.contentAuthor[0].fields.name,
52+
});
53+
});
54+
}
55+
res.set('Content-Type', 'application/rss+xml');
56+
res.send(feed.xml({ indent: true }));
57+
} catch (e) {
58+
next(e);
59+
}
60+
});
61+
62+
export default routes;

src/shared/components/MetaTags.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function MetaTags({
2121
socialTitle,
2222
title,
2323
url,
24+
feed,
25+
feedTitle,
2426
}) {
2527
const img = `${domain}${image}`;
2628
const socTitle = socialTitle || title;
@@ -32,6 +34,9 @@ function MetaTags({
3234
{title}
3335
</title>
3436
<meta name="description" content={description} />
37+
{
38+
feed && <link rel="alternate" type="application/rss+xml" title={feedTitle} href={feed} />
39+
}
3540

3641
{/* Twitter cards. */}
3742
<meta name="twitter:card" content="summary_large_image" />
@@ -63,6 +68,8 @@ MetaTags.defaultProps = {
6368
socialDescription: null,
6469
socialTitle: null,
6570
url: null,
71+
feed: null,
72+
feedTitle: null,
6673
};
6774

6875
MetaTags.propTypes = {
@@ -74,6 +81,8 @@ MetaTags.propTypes = {
7481
socialTitle: PT.string,
7582
title: PT.string.isRequired,
7683
url: PT.string,
84+
feed: PT.string,
85+
feedTitle: PT.string,
7786
};
7887

7988
/* TODO: It is not good to depend on the domain written into redux state here,

src/shared/containers/EDU/Home.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export default class EDUHome extends React.Component {
5252
<MetaTags
5353
description={description}
5454
title={title}
55+
feed={config.URL.THRIVE_FEED}
56+
feedTitle="Topcoder Thrive - RSS feed"
5557
/>
5658
{/* Banner */}
5759
<div className={homeTheme.bannerContainer}>

src/shared/containers/EDU/Search.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ export default class EDUSearch extends React.Component {
102102
<MetaTags
103103
description={description}
104104
title={title}
105+
feed={config.URL.THRIVE_FEED}
106+
feedTitle="Topcoder Thrive - RSS feed"
105107
/>
106108
);
107109
// This container needs at least those variables

src/shared/containers/EDU/Tracks.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ export default class EDUTracks extends React.Component {
220220
<MetaTags
221221
description={description}
222222
title={title}
223+
feed={config.URL.THRIVE_FEED}
224+
feedTitle="Topcoder Thrive - RSS feed"
223225
/>
224226
);
225227
// This container needs at least those variables

0 commit comments

Comments
 (0)