換電腦後發現即使有用 time machine 做備份還是要重新部署
因為 push 至 github 的是已經編譯過後的檔案,所以沒有留原始檔的話,看起來應該沒救了(?)
step 1: 電腦環境設定
1 | git --version |

step 2: 重新建置 Hexo 環境
1 | #建立一個 blog 的資料夾 (blog_name 請自行命名~) |
若是有其他的要安裝請參考 Hexo 環境安裝
1 | cd blog_name |
將備份的檔案複製至新的 Hexo 環境
)
將除了 node_modules 跟 public 之外的檔案複製過去
node_modules 是放一些 library 的地方,執行 npm install 時就會下載相關的 library;而 public 是放原始檔編譯後的檔案,之後部署時會再建回來
複製完執行以下指令
1 | npm install |
可能會出現一些 Error or Warning,照著他的指示修正即可
step 3: 在本地端 preview 一下
上線前還是小心謹慎一點好,先在本地檢視一下有沒有如期正常顯示,畢竟裡面已經有嘔心瀝血作品
1 | #透過本機的 http://localhost:4000 查看 |
step 4: 重新部署 gogo
1 | hexo d -g |
番外: 部署問題
事情有時候總是沒這麼簡單的喇!!
看起來一般來說他給的這個網站裡面都能找到解法 ⬇️
Something’s wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html
分享一下我遇到的是 github Authentication Failed (身份驗證失敗)
解法:
1 | # 進去網站資料夾 |
將 https 方式改成用 ssh 方式
1 | deploy: |
Generating a new SSH key and adding it to the ssh-agent :link:
1
ls -al ~/.ssh
1
ssh-keygen -t ed25519 -C "your_email@example.com"
產生金鑰的過程中,會問 3 個問題,如果沒有特殊需求可以全部使用預設值(press Enter)就好
1
2
3
4
5
6# 金鑰儲存的位置與檔名,預設檔名是前面所提到 id_ed25519,可以更改檔名,ex: githud_key
Enter file in which to save the key (/home/username/.ssh/id_ed25519): [Press enter]
# 詢問是否指定金鑰保護密碼,若有設定密碼的話,之後使用每次使用時,這把金鑰時就要輸入密碼,請務必牢記。之後想修改金鑰密碼的話,可以透過 ssh-keygen 來設定。
Enter passphrase (empty for no passphrase):
Enter same passphrase again:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/username/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/username/.ssh/id_ed25519
Your public key has been saved in /Users/username/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:*************************** your_email@example.com
The key's randomart image is:
+--[ED25519 256]--+
| |
| |
| |
| |
| |
| |
| |
| |
| |
+----[SHA256]-----+設定金鑰代理
1
2eval "$(ssh-agent -s)"
# output: Agent pid 983501
2touch ~/.ssh/config
open ~/.ssh/configmodify ~/.ssh/config
1
2
3
4Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519 #!如果有改名的話這邊記得改1
2
3
4# Add your SSH private key to the ssh-agen
ssh-add -K ~/.ssh/id_ed25519
# copy it
pbcopy < ~/.ssh/id_ed25519.pub #!如果有改名的話這邊記得改Adding a new SSH key to your GitHub account:link:
連線測試
1
2ssh -T git@github.com
# output: Hi XXX! You’ve successfully authenticated, but GitHub does not provide shell access.deploy on GitHub
1
hexo clean && hexo g && hexo d