在 OpenShift 上免费搭建 Ghost 博客的过程

2015-12-17  本文已影响458人  DemoJameson

Ghost 简介

Ghost 是一个基于 Node.js 的开源博客平台,由前 WordPress UI 部门主管 John O’Nolan 和 WordPress 开发人员 Hannah Wolfe 创立,目的是为了给用户提供一种更加纯粹的内容写作发布平台。

Ghost 简单轻量部署快,后台使用具备预览功能的 Markdown 编辑器进行写作,这些就是我选择它的原因。(下面提及的 Bug 还没修复,所以现在改用 Hexo 了 —— Ghost 博客一览请点击

搭建过程

主要参考了《使用 Nitrous.IO+OpenShift 免费搭建 Ghost 博客》这篇文章,下面就将搭建的过程简单的记录一下,说说遇到的坑以及解决方法。

  1. 注册 OpenShift使用其提供的免费服务搭建 Ghost Blog。

  2. 注册 nitrous.io,该服务提供了一个在线的 Linux 开发环境,稍后需要使用这个环境安装 Ghost 和配置。注册后创建 Node.js IDE 时需要通过手机短信进行验证,经测试中国移动的号码无法使用免费的方案,遂借用 Heywire 这个手机应用(获得虚拟的美国号码,免费接收短信)完成了验证。

  3. 使用 nitrous.io 的 Node.js IDE 环境搭建 Ghost Blog:

  1. 这时已经可以通过http://ghost-用户名.rhcloud.com连接访问 Ghost Blog 了,但是由于众所周知的原因 OpenShift 很可能被墙了,这时候就得通过自定义域名来绕过围墙:
  1. 使用 CDN 加速访问(非必须):
  1. 也是因为众所周知的原因,需要替换 Google Font 使用 360 CDN 提供的字体库,打开 ghost/content/themes/[主题]/default.hbs 文件,搜索fonts.googleapis.com全部替换为fonts.useso.com

  2. 参考《解决 Ghost 中 gravatar 被墙不能显示的问题》,数据库相关信息可在 OpenShift 中找到:

     mysql -u [数据库用户名] -p -D [数据库名称]
     Enter password:[数据库密码]
     select image from users where email = "your email address";
     update users set image = "//去掉www的Gravatar地址" where email = "your email address";
    
  3. 主题安装:

     cd ~/ghost/content/themes/
     git clone [git地址]
    

可能需要为 git 设置默认的用户名以及邮箱,下载完主题后需删除目录下的 .git 目录以及 .gitignore,以免稍后无法应用更新。

  1. 添加多说(试用多说过程中弹出了广告)Disqus评论区以及 Swiftype 站内搜索的代码可以放置在后台Setting -> Code Injection中,不必修改主题。以下是我修改过的多说脚本(请将 short_name 改为自己的):
<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
    var s = document.createElement("section");
    s.className = "post-comments";
    s.innerHTML = '<div class="ds-thread" data-thread-key="' + location.pathname.replace(/\//g,"") + '" data-title="'+ document.title +'" data-url="' + location.href.replace(/^https/, "http") + '"></div>';
    document.querySelector(".post-container").parentNode.appendChild(s);
    var duoshuoQuery = {short_name:"xxxxxxxxx"};
    (function() {
        var ds = document.createElement('script');
        ds.type = 'text/javascript';ds.async = true;
        ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
        ds.charset = 'UTF-8';
        (document.getElementsByTagName('head')[0]
         || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
</script>
<!-- 多说公共JS代码 end -->
  1. 更新应用,在 nirtous 中做的所有更改均需通过 git 同步到 OpenShift 中,使用以下命令即可:
    cd ~/ghost
    git add .
    git commit -m "[随便输入什么内容]"
    git push
等待更新成功提示出现:`remote: Deployment completed with status: success`
  1. 开始写作,通过网址http://[你的域名]/ghost初始化博客,设置管理员账号密码,然后进入后台写作以及配置

未解之谜

参考资料

  1. 使用 Nitrous.IO+OpenShift 免费搭建 Ghost 博客
  2. 简单实现 Ghost 独立博客的 QQ 空间、新浪微博和人人网分享按钮
  3. 解决 Ghost 中 gravatar 被墙不能显示的问题
  4. 绑定 GoDaddy 域名到 OpenShift 应用
  5. 用 Prism 给 Ghost 添加代码高亮
  6. Ghost 博客平台:安装多说, Disqus
  7. 使用 Swiftype 完成 Ghost 搜索功能
上一篇 下一篇

猜你喜欢

热点阅读