TitanPages靜態(tài)博客生成器
TitanPages是一個(gè)靜態(tài)博客生成器, 可以配合githubpages輕松的搭建自己的博客。
展示網(wǎng)站請(qǐng)轉(zhuǎn)到: https://qibin0506.github.io/
如何使用
step 1.
下載源碼編譯源碼(linux用戶(hù), 可以直接下載tt文件;windows用戶(hù)可直接下載tt.zip解壓使用)
step 2.
創(chuàng)建文件, 在你的工作空間用命令行運(yùn)行以下命令:
tt -type create -file 你的文件名稱(chēng)
例如: tt -type create -file 我的第一篇博客
step 3.
寫(xiě)作, 打開(kāi)/raw/你的文件名稱(chēng)文件, 進(jìn)行文章的書(shū)寫(xiě)(注意: 文章的格式必須是markdown的)
step 4.
編譯markdown文件,寫(xiě)作完成后, 運(yùn)行命令:
tt -type build -file 你的文件名稱(chēng) [-author 作者] [-tmpl 要使用的模板文件]
例如: tt -type build -file 我的第一篇博客 -author 亓斌 -tmpl ./content.html
(注意: []中的參數(shù)為可選參數(shù), 具體content.html模板如何書(shū)寫(xiě)會(huì)在下面介紹)
現(xiàn)在在/html目錄下會(huì)生成對(duì)應(yīng)文件名的html文件.
step 5.
生成目錄, 運(yùn)行命令:
tt -type cate
運(yùn)行該命令, 在/html目錄中會(huì)生成一個(gè)category.auto.js的javascript文件.
step 6.
文章模板文件content.html的書(shū)寫(xiě):
使用占位符{{.Title}}表示文章的標(biāo)題
使用占位符{{.Date}}表示文章的日期
使用占位符{{.Author}}表示文章的作者
使用占位符{{.Desc}}表示文章的描述
使用占位符{{.Content}}表示文章內(nèi)容
注意: 關(guān)于占位符{{.desc}}的說(shuō)明: 建議將這個(gè)描述放在<meta name='description'></meta>中,這樣,在生成目錄的時(shí)候才會(huì)產(chǎn)生摘要信息.
step 7.
關(guān)于自動(dòng)生成的category.auto.js文件的說(shuō)明, 這個(gè)文件是關(guān)于文章索引信息的, 我們需要在目錄頁(yè)調(diào)用這個(gè)文件里的函數(shù):
pageCount() 函數(shù)會(huì)返回分頁(yè)頁(yè)碼總數(shù)(默認(rèn)分頁(yè)大小為5)
getQueryString(query) 函數(shù)可以獲取指定的querystring參數(shù), 通常我們用來(lái)獲取當(dāng)前頁(yè)碼
get(currentPage) 函數(shù)會(huì)根據(jù)當(dāng)前頁(yè)碼返回?cái)?shù)據(jù)數(shù)組, 該數(shù)組中包含了索引頁(yè)需要的信息
索引信息數(shù)組中包含的信息如下:
title 文章的標(biāo)題
date 文章生成的時(shí)間
desc 文章的簡(jiǎn)要描述
demo中的例子:
window.onload = function() { var page = getQueryString("page") var count = pageCount() if (page == null) {
page = 1 }else {
page = parseInt(page)
} if(page > 1) { document.getElementById("nav").innerHTML += "<a class='newer-posts' href='?page="+(page - 1)+"'>← Newer Posts</a>" } document.getElementById("nav").innerHTML += "<span class='page-number'>Page "+page+" of "+count+"</span>" if(page < count) { document.getElementById("nav").innerHTML += "<a class='older-posts' href='?page="+(page + 1)+"'>← Older Posts</a>" } if (page <= count) { var result = get(page) for (var i=0;i<result.length;i++) { document.getElementById("content").innerHTML += "<article class='post'><header class='post-header'><span class='post-meta'><time datetime='"+result[i].date+"' itemprop='datePublished'>"+result[i].date+"</time><h2 class='post-title'><a href='./html/"+result[i].title+".html'>"+result[i].title+"</a></h2></header><section class='post-excerpt'><p>"+result[i].desc+"</p> <p><a href='./html/"+result[i].title+".html' class='excerpt-link'>Read More...</a></p></section></article>" }
}
}