mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
c902d91c81
- This fits more closely, as this service is to so with rendering helpers and small parts - Whereas we want to use "rendering" for things concerned with rendering pages
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
// # URL helper
|
|
// Usage: `{{url}}`, `{{url absolute="true"}}`
|
|
//
|
|
// Returns the URL for the current object scope i.e. If inside a post scope will return post permalink
|
|
// `absolute` flag outputs absolute URL, else URL is relative
|
|
|
|
const {metaData} = require('../services/proxy');
|
|
const {SafeString} = require('../services/handlebars');
|
|
const logging = require('@tryghost/logging');
|
|
const sentry = require('../../shared/sentry');
|
|
const errors = require('@tryghost/errors');
|
|
|
|
const {getMetaDataUrl} = metaData;
|
|
|
|
module.exports = function url(options) {
|
|
const absolute = options && options.hash.absolute && options.hash.absolute !== 'false';
|
|
let outputUrl = getMetaDataUrl(this, absolute);
|
|
|
|
try {
|
|
outputUrl = encodeURI(decodeURI(outputUrl));
|
|
} catch (err) {
|
|
// Happens when the outputURL contains an invalid URI character like "%%" or "%80"
|
|
|
|
// Send the error not to be blind to these
|
|
const error = new errors.IncorrectUsageError({
|
|
message: `The url "${outputUrl}" couldn't be escaped correctly`,
|
|
err: err
|
|
});
|
|
sentry.captureException(error);
|
|
logging.error(error);
|
|
|
|
return new SafeString('');
|
|
}
|
|
|
|
return new SafeString(outputUrl);
|
|
};
|