/
publish-hexo-on-github
148 lines (109 loc) · 7.06 KB
/
publish-hexo-on-github
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html>
<!--head-->
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-MC9CSTSNW6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-MC9CSTSNW6');
</script>
<title>JAS0N HUANG</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="google-site-verification" content="DoQOqkvX376V4rp4mmeGYFGrLOB-wrUCMMKlqgrqmuQ" />
<link rel="stylesheet" href="/css/style.css">
<script type="text/javascript">
let apiUrl = 'https://www.googleapis.com/youtube/v3/channels?part=snippet&id=UC9ckyA_A3MfXUa0ttxMoIZw&key=AIzaSyBiuF1WCpG7TaCY8xtd4cb73Sn-5NTPrb0'
let xhr = new XMLHttpRequest()
xhr.open('get', apiUrl, true)
xhr.send()
xhr.onreadystatechange = function(){
if(this.readyState ===4 && this.status === 200){
let data = JSON.parse(this.responseText)
console.log(data)
}
}
</script>
<meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="JAS0N HUANG" type="application/atom+xml">
</head>
<body>
<div class="container">
<div class="blog_header">
<a href="/">
<h1 class="blog_title">
<img src="/images/Jas0nhuang.svg" alt="jas0nhuang">
<!-- %= config.title %-->
</h1>
</a>
<div class="container">
<nav class="blog_nav">
<a class="menu_item" href="/archives">文章</a>
<a class="menu_item" href="/tags">標籤</a>
<a class="menu_item" href="/about">關於</a>
<a class="menu_item" href="/atom.xml">RSS</a>
</nav>
</div>
</div>
</div>
<div class="body">
<div class="main">
<div class="full">
<h1 class="page_title">如何在 GitHub上發佈 Hexo網站</h1>
<p>決定好主題,寫好幾篇文章或還沒寫好文章,網站都可以發佈到網路上了。</p>
<p>本篇文章以 GitHub Pages為例,使用的 GitHub帳號為 JAS0NHUANG, GitHub Pages網址是 JAS0NHUANG.github.io.git。</p>
<hr>
<p>!!!以下 GitHub設定的部分其實與 Hexo的發佈無關,我之前以為要先設定好才能使用 Hexo deploy,其實不然。不把這一部分刪除,留個之前錯誤觀念的記錄!!!</p>
<h3 id="設定並推送至-GitHub遠端程式庫"><a href="#設定並推送至-GitHub遠端程式庫" class="headerlink" title="設定並推送至 GitHub遠端程式庫"></a>設定並推送至 GitHub遠端程式庫</h3><p>先把本地端 git程式庫初始化(init),加入(add)所有檔案至程式庫然後提交(commit)</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">git init</span><br><span class="line">git add *</span><br><span class="line">git commit -m "init"</span><br></pre></td></tr></table></figure>
<p>設定遠端程式庫位址</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">git remote add origin git@github.com:jas0nhuang/jas0nhuang.github.io.git</span><br></pre></td></tr></table></figure>
<p>!!!以上與 Hexo部署無關!!!</p>
<hr>
<h2 id="建立-SSH金鑰"><a href="#建立-SSH金鑰" class="headerlink" title="建立 SSH金鑰"></a>建立 SSH金鑰</h2><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">ssh-keygen</span><br></pre></td></tr></table></figure>
<p>金鑰檔的位置只能用完整路徑,不能用 ~/代替 /home/USERNAME/,所以通常金鑰檔路徑會是 /home/USERNAME/.ssh/id_rsa,請自行以用戶名替換 USERNAME,可選擇是否要設定密碼。</p>
<p>先啟動 ssh-agent,然後將新建金鑰加入為此程式庫使用,這裡就可以使用 ~/代替家目錄了</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">ssh-agent -s</span><br><span class="line">ssh-add ~/.ssh/id_rsa</span><br></pre></td></tr></table></figure>
<p>顯示公用金鑰</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">cat ~/.ssh/id_rsa.pub</span><br></pre></td></tr></table></figure>
<p>複製,並加入到 GitHub</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">https://github.com/settings/ssh/new</span><br></pre></td></tr></table></figure>
<h2 id="使用-Hexo部署工具"><a href="#使用-Hexo部署工具" class="headerlink" title="使用 Hexo部署工具"></a>使用 Hexo部署工具</h2><p>在 _config.yml檔案裡設定部署方式以及遠端程式庫位址</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">deploy:</span><br><span class="line">type: git</span><br><span class="line">repo: git@github.com:jas0nhuang/jas0nhuang.github.io.git</span><br></pre></td></tr></table></figure>
<p>npm安裝 hexo-deployer-git, –save選項會在 package.json檔案裡加入 Node依賴關係</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">npm instal hexo-deployer-git --save</span><br></pre></td></tr></table></figure>
<p>然後就可以用 Hexo部署了</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">hexo deploy</span><br></pre></td></tr></table></figure>
<p>執行時會跳出 SSH認證,要求輸入金鑰密碼。</p>
<hr>
<ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Blogging/" rel="tag">Blogging</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/" rel="tag">Git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Hexo/" rel="tag">Hexo</a></li></ul>
</div>
</div>
</div>
<section id="comments">
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'JAS0NHUANG';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a target="_blank" rel="noopener" href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</section>
<!--footer-->
<footer class="blog_footer">
<p>
JAS0N HUANG
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">
<img src="/images/cc.svg" alt="CC" height="16"></a>
2019
</p>
</footer>
</body>
</html>