2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Standardize file path access throughout ghost

resolves #1390

update all string based references to file paths
to use the ./core/server/config/paths file
so that it is the single source of truth
This commit is contained in:
Harry Wolff 2013-12-08 19:49:02 -05:00
parent 968176c7d7
commit 9090764052
6 changed files with 29 additions and 24 deletions

View file

@ -8,6 +8,7 @@ var dataExport = require('../data/export'),
_ = require('underscore'),
schema = require('../data/schema'),
config = require('../config'),
debugPath = config.paths().webroot + '/ghost/debug/',
db;
@ -34,7 +35,7 @@ db = {
id: 'per-' + (notifications.length + 1)
};
return api.notifications.add(notification).then(function () {
res.redirect(config.paths().webroot + '/ghost/debug/');
res.redirect(debugPath);
});
});
});
@ -59,7 +60,7 @@ db = {
id: 'per-' + (notifications.length + 1)
};
return api.notifications.add(notification).then(function () {
res.redirect(config.paths().webroot + '/ghost/debug/');
res.redirect(debugPath);
});
});
}
@ -153,7 +154,7 @@ db = {
};
return api.notifications.add(notification).then(function () {
res.redirect(config.paths().webroot + '/ghost/debug/');
res.redirect(debugPath);
});
});
});

View file

@ -6,8 +6,10 @@ var path = require('path'),
url = require('url'),
requireTree = require('../require-tree'),
appRoot = path.resolve(__dirname, '../../../'),
themePath = path.resolve(appRoot + '/content/themes'),
pluginPath = path.resolve(appRoot + '/content/plugins'),
corePath = path.resolve(appRoot, 'core/'),
contentPath = path.resolve(appRoot, 'content/'),
themePath = path.resolve(contentPath + '/themes'),
pluginPath = path.resolve(contentPath + '/plugins'),
themeDirectories = requireTree(themePath),
pluginDirectories = requireTree(pluginPath),
localPath = '',
@ -23,11 +25,15 @@ function getPaths() {
'webroot': localPath === '/' ? '' : localPath,
'config': path.join(appRoot, 'config.js'),
'configExample': path.join(appRoot, 'config.example.js'),
'contentPath': contentPath,
'corePath': corePath,
'themePath': themePath,
'pluginPath': pluginPath,
'adminViews': path.join(appRoot, '/core/server/views/'),
'helperTemplates': path.join(appRoot, '/core/server/helpers/tpl/'),
'lang': path.join(appRoot, '/core/shared/lang/'),
'imagesPath': path.resolve(contentPath, 'images/'),
'imagesRelPath': 'content/images',
'adminViews': path.join(corePath, '/server/views/'),
'helperTemplates': path.join(corePath, '/server/helpers/tpl/'),
'lang': path.join(corePath, '/shared/lang/'),
'availableThemes': availableThemes,
'availablePlugins': availablePlugins
};

View file

@ -1,16 +1,14 @@
/*jslint regexp: true */
var _ = require('underscore'),
colors = require('colors'),
fs = require('fs'),
path = require('path'),
var _ = require('underscore'),
colors = require('colors'),
fs = require('fs'),
configPaths = require('./config/paths'),
path = require('path'),
errors,
// Paths for views
appRoot = path.resolve(__dirname, '..', '..'),
themePath = path.resolve(appRoot, 'content', 'themes'),
adminTemplatePath = path.resolve(appRoot, 'core', 'server', 'views'),
defaultErrorTemplatePath = path.resolve(adminTemplatePath, 'user-error.hbs'),
userErrorTemplatePath = path.resolve(themePath, 'error.hbs'),
defaultErrorTemplatePath = path.resolve(configPaths().adminViews, 'user-error.hbs'),
userErrorTemplatePath = path.resolve(configPaths().themePath, 'error.hbs'),
userErrorTemplateExists;
/**
@ -18,7 +16,7 @@ var _ = require('underscore'),
*/
errors = {
updateActiveTheme: function (activeTheme) {
userErrorTemplatePath = path.resolve(themePath, activeTheme, 'error.hbs');
userErrorTemplatePath = path.resolve(configPaths().themePath, activeTheme, 'error.hbs');
userErrorTemplateExists = undefined;
},

View file

@ -150,7 +150,7 @@ function setup(server) {
// Are we using sockets? Custom socket or the default?
function getSocket() {
if (config().server.hasOwnProperty('socket')) {
return _.isString(config().server.socket) ? config().server.socket : path.join(__dirname, '../content/', process.env.NODE_ENV + '.socket');
return _.isString(config().server.socket) ? config().server.socket : path.join(config.path().contentPath, process.env.NODE_ENV + '.socket');
}
return false;
}

View file

@ -164,7 +164,7 @@ function redirectToSignup(req, res, next) {
module.exports = function (server, dbHash) {
var oneYear = 31536000000,
root = config.paths().webroot,
corePath = path.join(config.paths().appRoot, 'core');
corePath = config.paths().corePath;
// Cache express server instance
expressServer = server;

View file

@ -8,10 +8,10 @@ var _ = require('underscore'),
path = require('path'),
when = require('when'),
errors = require('../errorHandling'),
config = require('../config'),
baseStore = require('./base'),
localFileStore,
localDir = 'content/images';
localFileStore;
localFileStore = _.extend(baseStore, {
// ### Save
@ -20,7 +20,7 @@ localFileStore = _.extend(baseStore, {
// - returns a promise which ultimately returns the full url to the uploaded image
'save': function (image) {
var saved = when.defer(),
targetDir = this.getTargetDir(localDir);
targetDir = this.getTargetDir(config.paths().imagesRelPath);
this.getUniqueFileName(this, image, targetDir).then(function (filename) {
nodefn.call(fs.mkdirs, targetDir).then(function () {
@ -55,7 +55,7 @@ localFileStore = _.extend(baseStore, {
// middleware for serving the files
'serve': function () {
return express['static'](path.join(__dirname, '/../../../', localDir));
return express['static'](config.paths().imagesPath);
}
});