TypeError: cover.indexOf is not a function

7/21的時候,想說我又多寫一些文章,也有修改之前貼出來的文章,所以想要hexo cl(清除靜態網頁)完再hexo d -g(發布網頁)。但是當我要hexo d -g的時候,出現了如標題的這則訊息。
why?!

上網查了以後發現,這個錯誤會發生的原因是因為cover這個變數在被indexOf()使用之前,型別並不是string,因為indexOf()這個函式的功能是找出某字元在某字串 的位置,所以只要把cover轉成string就能解除這個錯誤。

Step 1
依據cmd給的錯誤訊息,找到random_cover.js。

Step 2
找到這行

1
const cover = data.cover

把它改成

1
const cover = data.cover + ""

這個動作可以將cover強制轉成string的型別,在JavaScript裡其實還有很多種轉成string的方式,這裡提供其中一種。

Step 3
問題解決,你又可以繼續發布任何東西到你架設的網站上了。

參考:

XXX.indexOf is not a function 问题

Support for password authentication was removed on August 13, 2021.

七夕這天(8/14),我一如往常地準備更新一些東西到我的部落格,結果在部屬的時候遇到了這個問題:

1
2
3
4
5
6
7
8
9
10
11
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: 無法存取 'https://github.com/Scar0615/scar0615.github.io/':The requested URL returned error: 403
FATAL {
err: Error: Spawn failed
at ChildProcess.<anonymous> (/Users/erichsieh/Desktop/scar/node_modules/hexo-util/lib/spawn.js:51:21)
at ChildProcess.emit (events.js:400:28)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
code: 128
}
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html

一開始我以為是自己的設定出現了問題,導致無法更新並部署,在看了上面的報錯之後,才知道Github在2021年8月13日之後,我們原先使用的密碼憑證無法使用了,要改成personal access token。不過我之前都在弄專題,而且也想順便多累積一些東西,再來想要怎麼解決這個問題。我參考了這篇轉換使用 Personal Access Token 更安全的操作 GitHub

照他的步驟做完後,如果想部署內容到Github Page,現在就可以了。只是在第一次部屬的時候會遇到下面的訊息:

1
2
3
4
[master 723df26] Site updated: 2021-12-26 11:05:50
23 files changed, 42 insertions(+), 42 deletions(-)
Username for 'https://github.com': Scar0615
Password for 'https://Scar0615@github.com':

這邊的密碼就是直接貼上剛剛由Github所產生的personal access token,到這邊就算是問題解決了,你又可以繼續發布任何東西到你架設的網站上了。

封面圖源:Pinterest