Ghost/core/frontend/services/routing/controllers/rss.js
Hannah Wolfe 22e13acd65 Updated var declarations to const/let and no lists
- All var declarations are now const or let as per ES6
- All comma-separated lists / chained declarations are now one declaration per line
- This is for clarity/readability but also made running the var-to-const/let switch smoother
- ESLint rules updated to match

How this was done:

- npm install -g jscodeshift
- git clone https://github.com/cpojer/js-codemod.git
- git clone git@github.com:TryGhost/Ghost.git shallow-ghost
- cd shallow-ghost
- jscodeshift -t ../js-codemod/transforms/unchain-variables.js . -v=2
- jscodeshift -t ../js-codemod/transforms/no-vars.js . -v=2
- yarn
- yarn test
- yarn lint / fix various lint errors (almost all indent) by opening files and saving in vscode
- grunt test-regression
- sorted!
2020-04-29 16:51:13 +01:00

52 lines
1.8 KiB
JavaScript

const _ = require('lodash');
const debug = require('ghost-ignition').debug('services:routing:controllers:rss');
const url = require('url');
const security = require('../../../../server/lib/security');
const settingsCache = require('../../../../server/services/settings/cache');
const rssService = require('../../rss');
const helpers = require('../helpers');
// @TODO: is this really correct? Should we be using meta data title?
function getTitle(relatedData) {
relatedData = relatedData || {};
let titleStart = _.get(relatedData, 'author[0].name') || _.get(relatedData, 'tag[0].name') || '';
titleStart += titleStart ? ' - ' : '';
return titleStart + settingsCache.get('title');
}
/**
* @description RSS controller.
*
* @TODO: The collection controller does almost the same. Merge!
* @param {Object} req
* @param {Object} res
* @param {Function} next
*/
module.exports = function rssController(req, res, next) {
debug('rssController');
const pathOptions = {
page: 1, // required for fetchData
slug: req.params.slug ? security.string.safe(req.params.slug) : undefined
};
// CASE: Ghost is using an rss cache - normalize the URL for use as a key
// @TODO: This belongs to the rss service O_o
const baseUrl = url.parse(req.originalUrl).pathname;
helpers.fetchData(pathOptions, res.routerOptions, res.locals)
.then(function formatResult(result) {
const response = _.pick(result, ['posts', 'meta']);
response.title = getTitle(result.data);
response.description = settingsCache.get('description');
return response;
})
.then(function (data) {
return rssService.render(res, baseUrl, data);
})
.catch(helpers.handleError(next));
};