安裝
brew install hugo
hugo new site blog
下載主題
初次運行
cd blog
hugo --theme=LeaveIt --baseurl="https://asketch.github.io"
cd public
touch README.md
git init
git add README.md
git commit -m "first commiit"
git remote add origin git@github.com:asketch/asketch.github.io.git
git add -A
# 第一次提交
git push -u origin master
# 非第一次提交
git push origin master
# 暴力的方法
git push upstream master
如果不是第一次上傳文件,而是進行更新:
git pull origin master
git push origin master
通常情況下
cd MySite
hugo --theme=LeaveIt --baseUrl="https://yourName.github.io/"
cd public
git status
git add -A
git commit -m "second commit"
git pull
git push origin master
發布腳本
在blog目錄用腳本發布
# 授權
chmod +x deploy.sh
使用腳本
./deploy.sh
腳本本體
echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"
# Build the project.
# 替換baseUrl
hugo --theme=LeaveIt --baseUrl="https://asketch.github.io/" # if using a theme, replace with `hugo -t <YOURTHEME>`
# Go To Public folder
cd public
# Add changes to git.
git add -A
# Commit changes.
msg="rebuilding site `date`"
if [ $# -eq 1 ]
then msg="$1"
fi
git commit -m "$msg"
# Push source and build repos.
git pull
git push origin master
# Come Back up to the Project Root
cd ..
綁定域名
域名解析--添加記錄--
添加兩個A類型的記錄,一個主機記錄www,一個為@,記錄值都是xxx.github.io
然后,修改文件CNAME文件
xxx.github.io
評論 valine
- 配置文件
# Valine.
# You can get your appid and appkey from https://leancloud.cn
# more info please open https://valine.js.org
[params.valine]
enable = true
appId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'
appKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'
notify = false # mail notifier , https://github.com/xCss/Valine/wiki
verify = false # Verification code
avatar = 'mm'
placeholder = '說點什么吧...'
visitor = true
- 主題目錄下的layouts--》partials下新建一個名為comments.html文件
<!-- valine -->
{{- if .Site.Params.valine.enable -}}
<!-- id 將作為查詢條件 -->
<div id="vcomments"></div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
<script type="text/javascript">
new Valine({
el: '#vcomments' ,
appId: '{{ .Site.Params.valine.appId }}',
appKey: '{{ .Site.Params.valine.appKey }}',
notify: '{{ .Site.Params.valine.notify }}',
verify: '{{ .Site.Params.valine.verify }}',
avatar:'{{ .Site.Params.valine.avatar }}',
placeholder: '{{ .Site.Params.valine.placeholder }}',
visitor: '{{ .Site.Params.valine.visitor }}'
});
</script>
{{- end }}
- 接下來,在LeaveIt的主題下的
layouts/_default/single.html
找到
<div class="post-comment">
<!-- 加入評論功能 -->
{{ partial "comments.html" . }}
</div>
- 開啟郵件通知(待續)
評論gitalk
主題的 layouts/partials
文件夾中創建 gitalk.html
文件
{{ if .Site.Params.enableGitalk }}
<div id="gitalk-container"></div>
<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
clientID: '{{ .Site.Params.Gitalk.clientID }}',
clientSecret: '{{ .Site.Params.Gitalk.clientSecret }}',
repo: '{{ .Site.Params.Gitalk.repo }}',
owner: '{{ .Site.Params.Gitalk.owner }}',
admin: ['{{ .Site.Params.Gitalk.owner }}'],
id: location.pathname, // Ensure uniqueness and length less than 50
distractionFreeMode: false // Facebook-like distraction free mode
});
(function() {
if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
document.getElementById('gitalk-container').innerHTML = 'Gitalk comments not available by default when the website is previewed locally.';
return;
}
gitalk.render('gitalk-container');
})();
</script>
{{ end }}
可能是single中,在模板中插入
{{ partial "gitalk.html" . }}
站點配置
[params]
enableGitalk = true
[params.gitalk]
clientID = "[Client ID]" # Your client ID
clientSecret = "[Client Secret]" # Your client secret
repo = "mogeko.github.io" # The repo to store comments
owner = "Mogeko" # Your GitHub ID
admin= "Mogeko" # Required. Github repository owner and collaborators. (Users who having write access to this repository)
id= "location.pathname" # The unique id of the page.
labels= "gitalk" # Github issue labels. If you used to use Gitment, you can change it
perPage= 15 # Pagination size, with maximum 100.
pagerDirection= "last" # Comment sorting direction, available values are 'last' and 'first'.
createIssueManually= false # If it is 'false', it is auto to make a Github issue when the administrators login.
distractionFreeMode= false # Enable hot key (cmd|ctrl + enter) submit comment.
目錄 toc
在/themes/LeaveIt/layouts/partials/
下新建toc.html
文件
<div class="post-toc" id="post-toc">
<h2 class="post-toc-title">{{ T "toc" }}</h2>
{{ $globalAutoCollapseToc := .Site.Params.autoCollapseToc | default false }}
<div class="post-toc-content{{ if not (or .Params.autoCollapseToc (and $globalAutoCollapseToc (ne .Params.autoCollapseToc false))) }} always-active{{ end }}">
{{.TableOfContents}}
</div>
</div>
<script type="text/javascript">
window.onload = function () {
var fix = $('.post-toc');
var end = $('.post-comment');
var fixTop = fix.offset().top, fixHeight = fix.height();
var endTop, miss;
var offsetTop = fix[0].offsetTop;
$(window).scroll(function () {
var docTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
if (end.length > 0) {
endTop = end.offset().top;
miss = endTop - docTop - fixHeight;
}
if (fixTop < docTop) {
fix.css({ 'position': 'fixed' });
if ((end.length > 0) && (endTop < (docTop + fixHeight))) {
fix.css({ top: miss });
} else {
fix.css({ top: 0 });
}
} else {
fix.css({ 'position': 'absolute' });
fix.css({ top: offsetTop });
}
})
}
</script>
在/themes/LeaveIt/assets/css/_custom.scss
中添加下面的toc樣式,可以根據自己的喜好自定義修改
.post-toc {
position: absolute;
width: 200px;
margin-left: 780px;
padding: 10px;
word-wrap: break-word;
box-sizing: border-box;
.post-toc-title {
margin: 0;
font-weight: 400;
text-transform: uppercase;
}
.post-toc-content {
&.always-active ul {
display: block;
}
>nav>ul {
margin: 10px 0;
}
ul {
padding-left: 0;
list-style: none;
ul {
padding-left: 15px;
display: none;
}
.has-active > ul {
display: block;
}
}
}
a:hover {
color: #c05b4d;
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
a {
display: block;
line-height: 30px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
-webkit-transition-duration: .2s;
transition-duration: .2s;
-webkit-transition-property: -webkit-transform;
transition-property: -webkit-transform;
transition-property: transform;
transition-property: transform,-webkit-transform;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
}
@media only screen and (max-width: 1224px) {
.post-toc {
display: none;
}
}
在文章頁的模板/themes/LeaveIt/layouts/_default/single.html
中 ``標簽后引入TOC模板
{{ if ( .Site.Params.toc | default true ) }}
{{ partial "toc.html" . }}
{{ end }}
最后,站點配置config.toml
toc = true # 是否開啟目錄
autoCollapseToc = true # Auto expand and collapse toc
放大文章內圖片顯示
LeaveIt主題內置了LightGallery燈箱效果,所以圖片原狀態是比較小,需要點擊才能放大,但是通過添加下面的代碼就可以讓圖片放大顯示,對眼睛舒服點。
在 assets/css/_custom.scss
中添加下面代碼
.post-warp .post-content img {
max-width: 100%;
}
添加閱讀進度條
首先將這一段代碼插入到 header
的模板中
LeaveIt 的 header
在 /layouts/partials/header.html
,插入到第 2 行和第 16
{{ if (and .IsPage (not .Params.notsb)) }}
<div class="top-scroll-bar"></div>
{{ end }}
然后在/assets/css/_custom.scss
文件中為我們的進度條添加樣式
// 頂部閱讀進度條
.top-scroll-bar {
position: fixed;
top: 0;
left: 0;
z-index: 9999;
display: none;
width: 0;
height: 3px;
background: #ef3982;
}
再然后,新建一個 js腳本 文件 /assets/js/_custom.js
,來控制我們的進度條。
// ==============================
// Custom JavaScript
// ==============================
// 頂部閱讀進度條
$(document).ready(function () {
$(window).scroll(function(){
$(".top-scroll-bar").attr("style", "width: " + ($(this).scrollTop() / ($(document).height() - $(this).height()) * 100) + "%; display: block;");
});
});
最后,使用 `` 標簽將 js 腳本引入到博客中,使其生效。
在 /layouts/partials/js.html
文件中添加以下內容,然后將 $custom
加入到變量 $vendorscript
中
{{ $custom := resources.Get "/js/_custom.js" }}
長url自動換行
主題目錄下的/LeaveIt/assets/css/_common/_page/post.scss
文件,找到.post-content
代碼塊 在里面添加下面的代碼
.post-content {
padding-top: 2rem;
word-break: break-all;//here
word-wrap: break-word;//hrer
h2,
h3,
h4,
h5,
h6 {
padding-top: .8em;
padding-bottom: .3em;
}
代碼樣式
assets/css/_common/_page/post.scss
中 code:not([class])
的樣式代碼
/* 原來的代碼 */
code:not([class]) {
padding: 5px 5px;
background: #fff;
border: 1px solid #ddd;
box-shadow: 1px 1px 0 #fff, 2px 2px 0 #ddd;
margin-left: 3px;
margin-right: 3px;
.dark-theme &:not([class]) {
background: transparent;
box-shadow: 1px 1px 0 $dark-font-secondary-color, 2px 2px 0 $dark-font-secondary-color;
}
}
/* 修改成自己想要的樣式 */
code:not([class]) {
padding: 2px 4px;
background: #2d2d2d; //
color: #ef3982;
border-radius: 2px;
margin-left: 3px;
margin-right: 3px;
.dark-theme &:not([class]) {
background: #2d2d2d;
color: #e06c75;
}
}
去掉 I miss you!(>﹏<)
assets/js/main.js
第24-26行
// window.onblur = function() {
// document.title = 'I miss you!(>﹏<)';
// }
移動設備適合性
一般在/themes/<THEME>/layouts/robots.txt
,本主題下禁止了搜索引擎爬取我的樣式或者腳本。接下來刪除中間部分,修改結果為:
User-agent: *
Sitemap: {{ "sitemap.xml" | absLangURL }}
其他
- 添加了一個靜態網頁指向一個網盤
hugo 的 static 靜態文件夾內放置 html 文件。如,static/test/index.html
,編譯之后訪問路徑 主站/test
進入到 index.html 內容
about頁面需要整改