Hipo log

升级Ghost到0.9.0

Last updated on

toc

Intro

三峡瀑布

之前blog所使用的是0.5.7的Ghost,最近又时间就顺手升级了下。

根据官方文档先升级到了0.7.1版本。

本来想先在本地测试的,结果估计是Mac node版本过高无法成功安装所需的node模块,一咬牙直接服务端升级,居然成功了,此刻就是ghost 0.7.1版本。

随后在0.7.1版本上升级到了最新版本(写此文时是0.9.0)。

值得注意的是替换完文件,npm install --production之后最好来一次nam start --production这个时候Ghost会做些版本升级。

七牛插件

还是使用了之前0.5.7版的七牛插件

nam install qiniu --production

config.js文件

config = { production: { storage: { provider: 'qiniu', bucketname: 'xxx', ACCESS_KEY: 'xxx', SECRET_KEY: 'xxx', root: 'xxx', prefix: 'xxx' } } }

替换core/server/storage/index.js文件为:

var errors = require('../errors'), storage = {}; var config = require('../config'); function getStorage(storageChoice) { // TODO: this is where the check for storage apps should go // Local file system is the default. Fow now that is all we support. // storageChoice = 'local-file-store'; storageChoice = (config.storage && config.storage.provider) || 'local-file-store'; if (storage[storageChoice]) { return storage[storageChoice]; } try { // TODO: determine if storage has all the necessary methods. storage[storageChoice] = require('./' + storageChoice); } catch (e) { errors.logError(e); } // Instantiate and cache the storage module instance. storage[storageChoice] = new storage[storageChoice](); return storage[storageChoice]; } module.exports.getStorage = getStorage;

core/server/storage/目录下增加qiniu.js文件

// Qiniu CDN support // Copyright: GhostChina.com var _ = require('lodash'), express = require('express'), fs = require('fs-extra'), path = require('path'), util = require('util'), utils = require('../utils'), Promise = require('bluebird'), config = require('../config'), errors = require('../errors'), baseStore = require('./base'), crypto = require('crypto'), qiniu = require('qiniu'), qiniuConfig = config.storage, qiniuStore; qiniu.conf.ACCESS_KEY = qiniuConfig.ACCESS_KEY; qiniu.conf.SECRET_KEY = qiniuConfig.SECRET_KEY; qiniu.conf.USER_AGENT = 'Ghost ' + config.ghostVersion; var putPolicy = new qiniu.rs.PutPolicy(qiniuConfig.bucketname); function QiniuStore () { } util.inherits(QiniuStore, baseStore); QiniuStore.prototype.save = function (image) { var uptoken = putPolicy.token(); var md5sum = crypto.createHash('md5'), ext = path.extname(image.name), targetDirRoot = qiniuConfig.root, targetFilename, key, extra = new qiniu.io.PutExtra(); var savedpath = path.join(config.paths.imagesPath, image.name); return Promise.promisify(fs.copy)(image.path, savedpath).then(function(){ return Promise.promisify(fs.readFile)(savedpath); }).then(function(data){ md5 = md5sum.update(data).digest('hex'); targetFilename = path.join(targetDirRoot, md5.replace(/^(\w{1})(\w{2})(\w+)$/, '$1/$2/$3')) + ext; targetFilename = targetFilename.replace(/\\/g, '/'); key = targetFilename.replace(/^\//, ''); return Promise.promisify(qiniu.io.put)(uptoken, key, data, extra); }).then(function() { // Remove temp file return Promise.promisify(fs.unlink)(savedpath); }).then(function () { // prefix + targetFilename var fullUrl = qiniuConfig.prefix + targetFilename; return fullUrl; }).catch(function (e) { errors.logError(e); return Promise.reject(e); }); }; QiniuStore.prototype.exists = function (filename) { return new Promise(function (resolve) { fs.exists(filename, function (exists) { resolve(exists); }); }); }; QiniuStore.prototype.serve = function (){ // For some reason send divides the max age number by 1000 return express['static'](config.paths.imagesPath, {maxAge: utils.ONE_YEAR_MS}); }; module.exports = QiniuStore;

Disqus,统计代码安装

最后自然不要遗漏了,disqus,和统计代码的安装😄,可以参考我之前从wordpress迁移的文章