mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 17:32:15 +03:00
6e075c78bf
refs https://linear.app/tryghost/issue/CORE-104/decouple-frontend-routing-events-from-urlserver-events - URL module is part of the backend heavily dependent on the model and fits perfectly here. Frontend should get the data it needs by passing a URL manager instance to it
21 lines
709 B
JavaScript
21 lines
709 B
JavaScript
const urlService = require('../../server/services/url');
|
|
const getContextObject = require('./context-object.js');
|
|
|
|
function getAuthorUrl(data, absolute) {
|
|
let context = data.context ? data.context[0] : null;
|
|
|
|
const contextObject = getContextObject(data, context);
|
|
|
|
if (data.author) {
|
|
return urlService.getUrlByResourceId(data.author.id, {absolute: absolute, secure: data.author.secure, withSubdirectory: true});
|
|
}
|
|
|
|
if (contextObject && contextObject.primary_author) {
|
|
return urlService.getUrlByResourceId(contextObject.primary_author.id, {absolute: absolute, secure: contextObject.secure, withSubdirectory: true});
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
module.exports = getAuthorUrl;
|