0%

在 firebase 上部署 hexo 静态博客

firebase 是股沟的一个 app 和 web 应用程序开发平台, 可以在上面部署静态博客.

本文主要 参考链接

参考链接里有些东西

注册 firebase, 创建新项目

firebase 官网

按照提示创建, 这里没什么难度.

关于自定义域名( 如果没有跳过这一步 )

firebase 默认提供了一个 项目id.firebaseapp.com 的域名.

要关联自己的域名的话

  1. 在 开发/Hosting 中点击 “关联域名”

  2. 填写顶级域名( domain.com ), 或子域名( child.domain.com )

  3. 在 DNS 提供商( 一般域名服务商也有这功能 ) 填写 TXT 记录:

    如我在 freenom 买的域名, 在域名的 DNS management 页面中填写

    name: 子域名或不填代表顶级域名( child/null )

    type: TXT

    target: 谷歌提供的一个验证码

    验证

  4. 成功后谷歌会给出两个 ip 地址, 跟步骤3类似填入 DNS 管理页面中. type 为A

  5. 坐等谷歌部署证书.

本地部署

关于 hexo 具体内容见 👉 链接. (这里只需要在一个文件夹中 clone hexo 就可以了)

在 hexo 项目文件夹中打开 powershell 输入

1
2
3
4
5
6
7
8
9
10
11
12
npm install -g firebase-tools
# 安装后登录, powershell 翻墙问题见文末
firebase login --no-localhost
# 问题选 y, 此时自动跳转到浏览器, 请求授权, 授权后复制那串认证码, 粘贴到 powershell 回车.
# 成功的话会显示 Success! Logged in as xxxx@gmail.com
firebase init
# 问题回答 y
# 空格选中 Configure and deploy Firebase Hosting sites 回车
# 选择项目
# 选择文件夹( 默认的 public 就对了 )
# 是否将链接都导向 /index.html, 看个人喜好选 y/n
# 是否覆盖 public/index.html 回答 N

我配置好后的 firebase.json

1
2
3
4
5
6
7
8
9
10
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}

最后执行

1
2
3
4
5
6
# 每次都 clean 一下
hexo clean
hexo g
# 此处也需要翻墙
firebase deploy
# 等待成功后, 在浏览器输入地址查看

powershell 翻墙

参考链接

微软文档

在 powershell 中输入

1
$Profile

他会返回一个文件的路径. 根据这个路径找到这个文件, 如果没有则创建它, 中间缺失的文件夹也创建.

然后在文末添加 参考链接 中的代码, 保存, 关闭.

在 powershell 中 输入 set-proxy ‘http://127.0.0.1:1080' ( 此处为 ssr/ss 的本地代理地址与端口, 按照实际情况填 )

更多详情见 参考链接

如果遇到 “此系统上禁止运行脚本xxxxxxxxx”

则用管理员身份打开 powershell, 输入set-executionpolicy remotesigned 按须选择 y 或 a