83364492 2019-06-25
mkdir blog cd blog vi _config.yml // 创建并保存 _config.yml 文件 :wq 保存退出
include [filename]
引用通过site[variableName]
访问这些配置信息,部分可迁移至_data
中
下面是我的配置,其他具体参照官方文档 —— 配置
# Site settings author: kasmine title: Kasmine Blog SEOTitle: 廖晓娟的博客 | Kasmine Blog header-img: assets/img/home-bg.jpg post-img: assets/img/post-bg.jpg email: [email protected] description: "" keyword: "" # url: "https://www.kasmine.cn" # your host, for absolute URL baseurl: "/kasmine.blog" imgurl: "/kasmine.blog/assets/img" # baseurl: "" # 本地调试使用 # imgurl: "/assets/img" # Basic settings # 添加sass # @see http://markdotto.com/2014/09/25/sass-and-jekyll/ sass: sass_dir: _scss # style: compressed # SNS settings RSS: false weibo_username: kasmine # zhihu_username: kasmine github_username: Me-Momo #twitter_username: kasmine facebook_username: kasmineLiao # linkedin_username: firstname-lastname-idxxxx # Build settings # from 2016, 'pygments' is unsupported on GitHub Pages. Use 'rouge' for highlighting instead. highlighter: rouge # permalink: pretty permalink: /:year/:month/:day/:title.html paginate: 10 exclude: ["less","node_modules","Gruntfile.js","package.json","README.md","README.zh.md"] anchorjs: true # 如何设置 # Gems # from PR#40, to support local preview for Jekyll 3.0 gems: [jekyll-paginate] markdown: kramdown kramdown: input: GFM # use Github Flavored Markdown !important # Analytics settings TODO: # Google Analytics ga_track_id: 'UA-89922034-1' # Format: UA-xxxxxx-xx # ga_domain: # Sidebar settings sidebar: true # whether or not using Sidebar. sidebar-about-description: "认真学习 n(*≧▽≦*)n <br />拥抱大前端 " sidebar-avatar: /assets/img/avatar-kasmine.jpg # use absolute URL, seeing it's used in both `/` and `/about/` # Catalog settings catalog: true
主要是一些nav,footer等等公共组件
等等,根据实际抽取公共部分
可按照自己的需求扩展
@see https://www.bryanbraun.com/anchorjs/
function async(u, c) { var d = document, t = 'script', o = d.createElement(t), s = d.getElementsByTagName(t)[0]; o.src = u; if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); } s.parentNode.insertBefore(o, s); } async("//cdnjs.cloudflare.com/ajax/libs/anchor-js/1.1.1/anchor.min.js",function(){ anchors.options = { visible: 'always', placement: 'left', icon: '? ' }; anchors.add('.custom-link') })
优化搜索引擎搜索
<!-- Canonical URL --> <link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">
The SEO benefit of rel=canonical
Choosing a proper canonical URL for every set of similar URLs improves the SEO of your site. Because the search engine knows which version is canonical, it can count all the links towards all the different versions, as links to that single version. Setting a canonical is similar to doing a 301 redirect, but without actually redirecting.
来源: https://yoast.com/rel-canonical/
实现代码的高亮
<!-- Pygments Github CSS --> <link rel="stylesheet" href="{{ "/assets/css/syntax.css" | prepend: site.baseurl }}">
主要原理就是 查找博文页面的 h标签,然后动态添加 id,并添加侧边栏 导航
<!-- Side Catalog --> <script type="text/javascript"> function generateCatalog (selector) { var P = $('div.posts-container'),a,n,t,l,i,c; a = P.find('h1,h2,h3,h4,h5,h6'); a.each(function () { n = $(this).prop('tagName').toLowerCase(); i = "#"+$(this).prop('id'); t = $(this).text(); c = $('<a href="'+i+'" rel="nofollow">'+t+'</a>'); l = $('<li class="'+n+'_nav"></li>').append(c); $(selector).append(l); }); return true; } generateCatalog(".catalog-body"); // toggle side catalog $(".catalog-toggle").click((function(e){ e.preventDefault(); $('.side-catalog').toggleClass("fold") })) /* * Doc: https://github.com/davist11/jQuery-One-Page-Nav */ async("/js/jquery.nav.js", function () { $('.catalog-body').onePageNav({ currentClass: "active", changeHash: !1, easing: "swing", filter: "", scrollSpeed: 700, scrollOffset: 0, scrollThreshold: .2, begin: null, end: null, scrollChange: null, padding: 80 }); }); </script>
jekyll server --port PORT // 选择自己想要的端口 jekyll server -watch // 实现jekyll 实时更新
参考:这篇文章
直到现在又开始鼓捣Jekyll静态网站后台引擎,下面就讲讲Jekyll的学习,以及在用Jekyll创建网站的时候遇到的问题。不需要数据库,不需要后台知识,用Jekyll搭建个人中小型网站就是这么简单。