以后写文章,只需要在 _post/ 文件加中,加入带有 YAML 头信息(YAML front matter)的 markdown 文件,然后 push 到 Github,就会被自动渲染成 HTML。比如,增加一篇名为 My First Post 的博客,在本地创建一个文件名带有日期的 markdown 文件 2015-04-20-my-first-post.md(里面要写好头信息):
1 2 3 4 5 6 7
--- layout: post title: My First Post --- # 这是我的第一篇博客
/* By default it's not affixed in mobile views, so undo that */ .bs-docs-sidebar.affix { position: static; } @media (min-width: 768px) { .bs-docs-sidebar { padding-left: 10px; } }
/* First level of nav */ .bs-docs-sidenav { margin-top: 40px; margin-bottom: 20px; }
/* All levels of nav */ .bs-docs-sidebar.nav > li > a { display: block; padding: 4px10px; font-size: 20px; font-weight: 300; color: #696969; /*no wrap*/ overflow:hidden; white-space:nowrap; text-overflow:ellipsis } .bs-docs-sidebar.nav > li > a:hover, .bs-docs-sidebar.nav > li > a:focus { padding-left: 10px; color: #563d7c; text-decoration: none; background-color: transparent; border-left: 1px solid #563d7c; } .bs-docs-sidebar.nav > .active > a, .bs-docs-sidebar.nav > .active:hover > a, .bs-docs-sidebar.nav > .active:focus > a { padding-left: 9px; font-weight: 300; color: red; background-color: transparent; border-left: 2px solid #563d7c; }
/* Nav: second level (shown on .active) */ .bs-docs-sidebar.nav.nav { /* display: none; Hide by default, but at >768px, show it */ /* padding-bottom: 10px; */ } .bs-docs-sidebar.nav.nav > li > a { padding-top: 1px; padding-bottom: 1px; padding-left: 20px; font-size: 18px; font-weight: bold; } .bs-docs-sidebar.nav.nav > li > a:hover, .bs-docs-sidebar.nav.nav > li > a:focus { padding-left: 19px; } .bs-docs-sidebar.nav.nav > .active > a, .bs-docs-sidebar.nav.nav > .active:hover > a, .bs-docs-sidebar.nav.nav > .active:focus > a { padding-left: 18px; font-weight: bold; color: red; }
/* Nav: 3rd level (shown on .active) */ .bs-docs-sidebar.nav.nav.nav { /*display: none; Hide by default, but at >768px, show it */ /* padding-bottom: 10px;*/ } .bs-docs-sidebar.nav.nav.nav > li > a { padding-top: 1px; padding-bottom: 1px; padding-left: 30px; font-size: 17px; font-weight: normal; } .bs-docs-sidebar.nav.nav.nav > li > a:hover, .bs-docs-sidebar.nav.nav.nav > li > a:focus { padding-left: 29px; } .bs-docs-sidebar.nav.nav.nav > .active > a, .bs-docs-sidebar.nav.nav.nav > .active:hover > a, .bs-docs-sidebar.nav.nav.nav > .active:focus > a { padding-left: 28px; font-weight: bold; color: red; }
/* * Side Nav Affixing * * reference to: * https://github.com/twbs/bootstrap/blob/master/docs/assets/js/src/application.js#L35 */ setSideNavAffixing:function() {
// Scrollspy var $window = $(window) var $body = $(document.body)
$body.scrollspy({ target: '.bs-docs-sidebar' }) $window.on('load', function () { $body.scrollspy('refresh') })
// Sidenav affixing setTimeout(function () { var $sideBar = $('.bs-docs-sidebar')
$sideBar.affix({ offset: { top: function () { var offsetTop = $sideBar.offset().top var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10) var navOuterHeight = $('.bs-docs-bar-top').height()
setTimeout(function () { $('.bs-top').affix() }, 100) }, // end of setSideNavAffixing:function()
/* Generate directory tree * * side_nav_element: side navigation element * article_body_element: article body container. * * processing: search header elements(h1,h2,h3) in `article_body_element`, * generate directory tree list, and put them into side_nav_element. */ createBlogDirectory:function (side_nav_element, article_body_element){ if(!article_body_element || article_body_element.length < 1 || !side_nav_element) { returnfalse; }
var nodes = article_body_element.find("h1,h2,h3"); var ulSideNav = side_nav_element;
$.each(nodes,function(){ var $this = $(this);
var nodetext = $this.text(); // There maybe HTML tags in header inner text, use regex to erase them nodetext = nodetext.replace(/<\/?[^>]+>/g,""); nodetext = nodetext.replace(/ /ig, "");
// btw: Jekyll generates id for each header. var nodeid = $this.attr("id"); if(!nodeid) { nodeid = "top"; }
var item_a = $("<a></a>"); item_a.attr("href", "#" + nodeid); item_a.text(nodetext);
var ret_li; // wrapper: ul ( in the template, outside this code ) // h1: layer 1: li - a // h2: layer 2: ul - li - a // h3: layer 3: ul - ul - li - a switch($this.get(0).tagName) { case"H1": var li_a = $("<li></li>").append(item_a); ret_li = li_a; break; case"H2": var li_a = $("<li></li>").append(item_a); var nav_li_a = $("<ul class=\"nav\"></ul>").append(li_a); ret_li = nav_li_a; break; case"H3": var li_a = $("<li></li>").append(item_a); var nav_li_a = $("<ul class=\"nav\"></ul>").append(li_a); var nav_nav_li_a = $("<ul class=\"nav\"></ul>").append(nav_li_a); ret_li = nav_nav_li_a; break; }
if(!ret_li) { // do nothing } else { ulSideNav.append(ret_li); } }) // end of each
// Generate the side navigation `ul` elements // BlogDirectory.createBlogDirectory($("#sideNav"), $(".bs-docs-container")); BlogDirectory.createBlogDirectory($("#sideNav"), $(".post-container"));