mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 10:42:45 +03:00
🔥 remove imageRelPath (#7927)
refs #7488 - remove imageRelPath - instead add a static image prefix to the url helper
This commit is contained in:
parent
0201c431d7
commit
2a52af1d99
@ -51,7 +51,7 @@ module.exports = function setupBlogApp() {
|
||||
// Serve robots.txt if not found in theme
|
||||
blogApp.use(serveSharedFile('robots.txt', 'text/plain', utils.ONE_HOUR_S));
|
||||
// Serve blog images using the storage adapter
|
||||
blogApp.use('/content/images', storage.getStorage().serve());
|
||||
blogApp.use('/' + utils.url.STATIC_IMAGE_URL_PREFIX, storage.getStorage().serve());
|
||||
|
||||
// Theme static assets/files
|
||||
blogApp.use(staticTheme());
|
||||
|
@ -3,7 +3,6 @@
|
||||
"appRoot": ".",
|
||||
"corePath": "core/",
|
||||
"clientAssets": "core/built/assets",
|
||||
"imagesRelPath": "content/images",
|
||||
"helperTemplates": "core/server/helpers/tpl/",
|
||||
"adminViews": "core/server/views/",
|
||||
"internalAppPath": "core/server/apps/",
|
||||
|
@ -16,7 +16,6 @@ exports.isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
|
||||
|
||||
/**
|
||||
* transform all relative paths to absolute paths
|
||||
* @TODO: imagesRelPath is a dirty little attribute (especially when looking at the usages)
|
||||
* @TODO: re-write this function a little bit so we don't have to add the parent path - that is hard to understand
|
||||
*
|
||||
* Path must be string.
|
||||
@ -45,8 +44,7 @@ exports.makePathsAbsolute = function makePathsAbsolute(obj, parent) {
|
||||
} else {
|
||||
if (_.isString(configValue) &&
|
||||
(configValue.match(/\/+|\\+/) || configValue === '.') &&
|
||||
(configValue[0] !== '/' && configValue[0] !== '\\') &&
|
||||
pathsKey !== 'imagesRelPath'
|
||||
(configValue[0] !== '/' && configValue[0] !== '\\')
|
||||
) {
|
||||
self.set(parent + ':' + pathsKey, path.join(__dirname + '/../../../', configValue));
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ ImageHandler = {
|
||||
loadFile: function (files, baseDir) {
|
||||
var store = storage.getStorage(),
|
||||
baseDirRegex = baseDir ? new RegExp('^' + baseDir + '/') : new RegExp(''),
|
||||
imageFolderRegexes = _.map(config.get('paths').imagesRelPath.split('/'), function (dir) {
|
||||
imageFolderRegexes = _.map(utils.url.STATIC_IMAGE_URL_PREFIX.split('/'), function (dir) {
|
||||
return new RegExp('^' + dir + '/');
|
||||
});
|
||||
|
||||
@ -37,7 +37,7 @@ ImageHandler = {
|
||||
|
||||
return Promise.map(files, function (image) {
|
||||
return store.getUniqueFileName(store, image, image.targetDir).then(function (targetFilename) {
|
||||
image.newPath = utils.url.urlJoin('/', utils.url.getSubdir(), config.get('paths').imagesRelPath,
|
||||
image.newPath = utils.url.urlJoin('/', utils.url.getSubdir(), utils.url.STATIC_IMAGE_URL_PREFIX,
|
||||
path.relative(config.getContentPath('images'), targetFilename));
|
||||
|
||||
return image;
|
||||
|
@ -35,7 +35,7 @@ function serveFavicon() {
|
||||
// we are using an express route to skip /content/images and the result is a image path
|
||||
// based on config.getContentPath('images') + req.path
|
||||
// in this case we don't use path rewrite, that's why we have to make it manually
|
||||
filePath = settingsCache.get('icon').replace(/\/content\/images\//, '');
|
||||
filePath = settingsCache.get('icon').replace(new RegExp(utils.url.STATIC_IMAGE_URL_PREFIX), '');
|
||||
|
||||
var originalExtension = path.extname(filePath).toLowerCase(),
|
||||
requestedExtension = path.extname(req.path).toLowerCase();
|
||||
|
@ -38,7 +38,7 @@ LocalFileStore.prototype.save = function save(image, targetDir) {
|
||||
// For local file system storage can use relative path so add a slash
|
||||
var fullUrl = (
|
||||
utils.url.urlJoin('/', utils.url.getSubdir(),
|
||||
config.get('paths').imagesRelPath,
|
||||
utils.url.STATIC_IMAGE_URL_PREFIX,
|
||||
path.relative(config.getContentPath('images'), targetFilename))
|
||||
).replace(new RegExp('\\' + path.sep, 'g'), '/');
|
||||
|
||||
|
@ -7,7 +7,8 @@ var moment = require('moment-timezone'),
|
||||
config = require('./../config'),
|
||||
settingsCache = require('./../api/settings').cache,
|
||||
// @TODO: unify this with routes.apiBaseUrl
|
||||
apiPath = '/ghost/api/v0.1';
|
||||
apiPath = '/ghost/api/v0.1',
|
||||
STATIC_IMAGE_URL_PREFIX = 'content/images';
|
||||
|
||||
/** getBaseUrl
|
||||
* Returns the base URL of the blog as set in the config. If called with secure options, returns the ssl URL.
|
||||
@ -231,7 +232,7 @@ function urlFor(context, data, absolute) {
|
||||
secure = data.author.secure;
|
||||
} else if (context === 'image' && data.image) {
|
||||
urlPath = data.image;
|
||||
imagePathRe = new RegExp('^' + getSubdir() + '/' + config.get('paths').imagesRelPath);
|
||||
imagePathRe = new RegExp('^' + getSubdir() + '/' + STATIC_IMAGE_URL_PREFIX);
|
||||
absolute = imagePathRe.test(data.image) ? absolute : false;
|
||||
secure = data.image.secure;
|
||||
|
||||
@ -328,3 +329,14 @@ module.exports.urlJoin = urlJoin;
|
||||
module.exports.urlFor = urlFor;
|
||||
module.exports.urlPathForPost = urlPathForPost;
|
||||
module.exports.apiUrl = apiUrl;
|
||||
|
||||
/**
|
||||
* If you request **any** image in Ghost, it get's served via
|
||||
* http://your-blog.com/content/images/2017/01/02/author.png
|
||||
*
|
||||
* /content/images/ is a static prefix for serving images!
|
||||
*
|
||||
* But internally the image is located for example in your custom content path:
|
||||
* my-content/another-dir/images/2017/01/02/author.png
|
||||
*/
|
||||
module.exports.STATIC_IMAGE_URL_PREFIX = STATIC_IMAGE_URL_PREFIX;
|
||||
|
@ -94,7 +94,6 @@ describe('Config', function () {
|
||||
'contentPath',
|
||||
'corePath',
|
||||
'internalAppPath',
|
||||
'imagesRelPath',
|
||||
'adminViews',
|
||||
'helperTemplates',
|
||||
'clientAssets'
|
||||
@ -106,7 +105,6 @@ describe('Config', function () {
|
||||
appRoot = path.resolve(__dirname, '../../../../');
|
||||
|
||||
pathConfig.should.have.property('appRoot', appRoot);
|
||||
pathConfig.should.have.property('imagesRelPath', 'content/images');
|
||||
});
|
||||
|
||||
it('should allow specific properties to be user defined', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user