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

Closes #16121
pull/15800/merge
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,
// modelName: String,
// nameProp: String,
// blockProp: String,
// map: (nameProp: String) => String
// ) => Observable[models]
function getCachedObservable(app, modelName, nameProp, map) {
function getCachedObservable(app, modelName, nameProp, blockProp, map) {
return observeQuery(
app.models[modelName],
'find',
{ fields: { [nameProp]: true } }
{ fields: { [nameProp]: true, [blockProp]: true } }
)
.flatMap(models => {
return Observable.from(models, null, null, Scheduler.default);
})
.filter(model => !!model[nameProp])
.map(model => model[nameProp])
.filter(model => !!model[nameProp] && !!model[blockProp])
.map(map ? map : (x) => x)
.toArray()
::timeCache(cacheTimeout[0], cacheTimeout[1]);
@ -30,7 +30,8 @@ function getCachedObservable(app, modelName, nameProp, map) {
export default function sitemapRouter(app) {
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);
function sitemap(req, res, next) {
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
url
loc #{appUrl}/challenges/#{challenge}
loc #{appUrl}/challenges/#{challenge.block}/#{challenge.dashedName}
lastmod= now
changefreq weekly
priority= 0.9