fix(sitemap): Update challenge urls to use new url format (#16164)

Closes #16121
This commit is contained in:
Onel Harrison
2017-12-11 16:39:33 -05:00
committed by Quincy Larson
parent d52efaec8d
commit fb98968433
2 changed files with 7 additions and 6 deletions

View File

@ -10,19 +10,19 @@ const appUrl = 'https://www.freecodecamp.org';
// app: ExpressApp, // app: ExpressApp,
// modelName: String, // modelName: String,
// nameProp: String, // nameProp: String,
// blockProp: String,
// map: (nameProp: String) => String // map: (nameProp: String) => String
// ) => Observable[models] // ) => Observable[models]
function getCachedObservable(app, modelName, nameProp, map) { function getCachedObservable(app, modelName, nameProp, blockProp, map) {
return observeQuery( return observeQuery(
app.models[modelName], app.models[modelName],
'find', 'find',
{ fields: { [nameProp]: true } } { fields: { [nameProp]: true, [blockProp]: true } }
) )
.flatMap(models => { .flatMap(models => {
return Observable.from(models, null, null, Scheduler.default); return Observable.from(models, null, null, Scheduler.default);
}) })
.filter(model => !!model[nameProp]) .filter(model => !!model[nameProp] && !!model[blockProp])
.map(model => model[nameProp])
.map(map ? map : (x) => x) .map(map ? map : (x) => x)
.toArray() .toArray()
::timeCache(cacheTimeout[0], cacheTimeout[1]); ::timeCache(cacheTimeout[0], cacheTimeout[1]);
@ -30,7 +30,8 @@ function getCachedObservable(app, modelName, nameProp, map) {
export default function sitemapRouter(app) { export default function sitemapRouter(app) {
const router = app.loopback.Router(); const router = app.loopback.Router();
const challenges$ = getCachedObservable(app, 'Challenge', 'dashedName'); const challengeProps = ['dashedName', 'block'];
const challenges$ = getCachedObservable(app, 'Challenge', ...challengeProps);
const stories$ = getCachedObservable(app, 'Story', 'storyLink', dasherize); const stories$ = getCachedObservable(app, 'Story', 'storyLink', dasherize);
function sitemap(req, res, next) { function sitemap(req, res, next) {
const now = moment(new Date()).format('YYYY-MM-DD'); const now = moment(new Date()).format('YYYY-MM-DD');

View File

@ -87,7 +87,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
each challenge in challenges each challenge in challenges
url url
loc #{appUrl}/challenges/#{challenge} loc #{appUrl}/challenges/#{challenge.block}/#{challenge.dashedName}
lastmod= now lastmod= now
changefreq weekly changefreq weekly
priority= 0.9 priority= 0.9