阿里云自建Ghost博客完全攻略

阿里云自建Ghost博客完全攻略
The sweetness always comes after bitterness.

购买

蹲点阿里云 双十一活动 ,拿下首年优惠:

项目 内容 价格(元)
服务器 2核2G3M50G 36
域名 xiong-chao.cn 1

安装

How to install & setup Ghost on Ubuntu 20.04 or 22.04
A full production install guide for how to install the Ghost professional publishing platform on a production server running Ubuntu 20.04 or 22.04.

参考官方教程即可,其中需要注意的点有:

  1. 安装完 Node.js 后将 npm 切换到国内源,否则超时。
npm config set registry=https://registry.npmmirror.com/
  1. 在运行 ghost install 前必须先安装 yarn,否则会超时。
sudo apt-get install yarn
  1. 安装完成后添加 sharp,否则上传图片出错。
cd /var/www/<sitename>

sudo npm install sharp

设置

页眉 header

隐藏

<style>
  .nav-login, .nav-subscribe {
	display: none;
  }
</style>

在新标签页打开链接

<script>
  const anchors = document.querySelectorAll('a');

  for (x = 0, l = anchors.length; x < l; x++) {
    const regex = new RegExp('/' + window.location.host + '/');
    
    if (!regex.test(anchors[x].href)) {
      anchors[x].setAttribute('target', '_blank');
    }
  }
</script>

隐藏Powered By Ghost、登录(不同主题名称不同)

<style>
      .gh-powered-by {
              display: none; !important
      }
      .gh-foot-menu {
              display: none; !important
      }
</style>