<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title></title>
    <link>https://homary.github.io</link>
    <atom:link href="https://homary.github.io/feed.xml" rel="self" type="application/rss+xml" />
    <description></description>
    <language>en-us</language>
    <pubDate>Tue, 05 Mar 2019 01:30:52 +0000</pubDate>
    <lastBuildDate>Tue, 05 Mar 2019 01:30:52 +0000</lastBuildDate>

    
      <item>
        <title>在vue.js中使用videojs播放rtmp视频流</title>
        <link>https://homary.github.io/%E5%9C%A8Vue.js%E4%B8%AD%E4%BD%BF%E7%94%A8Videojs%E6%92%AD%E6%94%BErtmp%E8%A7%86%E9%A2%91%E6%B5%81</link>
        <pubDate>Tue, 05 Mar 2019 00:00:00 +0000</pubDate>
        <author></author>
        <description>&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;由于项目需要,需要在对接海康或者大华等摄像头,并实时展示在网页上.采用的传输协议为`rtmp`,在框架选择上选择`Video.js@7.4.2`.下面记录一下`Video.js`的使用:  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;介绍&lt;br /&gt;
 Video.js是一款web视频播放器，支持html5和flash两种播放方式.  更有自定义皮肤，插件，组件，语言还有丰富的选项配置.&lt;br /&gt;
 本次使用videojs 播放rtmp直播视频流媒体.&lt;/li&gt;
  &lt;li&gt;安装
    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;     npm install video.js videojs-flash    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;使用
    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &amp;lt;template&amp;gt;
     &amp;lt;video id=&quot;video&quot; class=&quot;video-js vjs-default-skin   
     vjs-big-play-centered flex-grid&quot;   
     style=&quot;width:100%;height:100%;object-fit: fill&quot;  
     muted controls autoplay poster= './video.jpg' loop&amp;gt;
       抱歉, 你的浏览器不支持
     &amp;lt;/video&amp;gt;
 &amp;lt;/template&amp;gt;
 &amp;lt;script&amp;gt;
     import videojs from 'video.js'
     import 'video.js/dist/video-js.css'
     import 'videojs-flash'

     ...
     // 实例化  
     let options = {
             autoplay: true,
             preload: true,
             techOrder: ['flash', 'html5'],
             notSupportMessage: '此视频暂无法播放',
             fluid: true
         }

     this.player = videojs('#video', options, function(){

     })
 &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
    &lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;videojs(el, options, cb)&lt;/code&gt;: 接受三个参数: &lt;code class=&quot;highlighter-rouge&quot;&gt;video&lt;/code&gt;标签&lt;code class=&quot;highlighter-rouge&quot;&gt;id&lt;/code&gt;, 要实例化的&lt;code class=&quot;highlighter-rouge&quot;&gt;videojs&lt;/code&gt;配置, 回调函数;&lt;br /&gt;
常用的&lt;code class=&quot;highlighter-rouge&quot;&gt;videojs&lt;/code&gt;配置选项:&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;preload: 是否预加载&lt;/li&gt;
  &lt;li&gt;muted : 实现静音播放, 有一些浏览器需要静音才能实现加载之后自动播放&lt;/li&gt;
  &lt;li&gt;controls: 将显示视频控件, 如果不需要则去掉controls即可&lt;/li&gt;
  &lt;li&gt;autoplay: 视频在加载完成之后自动播放&lt;/li&gt;
  &lt;li&gt;poster: 视频封面图片&lt;/li&gt;
  &lt;li&gt;loop: true/false, 是否循环播放&lt;/li&gt;
  &lt;li&gt;notSupportMessage: 浏览器无法播放时的提示信息&lt;/li&gt;
  &lt;li&gt;techOrder: 播放控件,默认是&lt;code class=&quot;highlighter-rouge&quot;&gt;html5&lt;/code&gt;,这里需要播放&lt;code class=&quot;highlighter-rouge&quot;&gt;rtmp&lt;/code&gt;所以首选项要是&lt;code class=&quot;highlighter-rouge&quot;&gt;flash&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;fluid: 流式布局,自适应父元素大小&lt;br /&gt;
更多的配置可以看&lt;a href=&quot;https://docs.videojs.com/tutorial-options.html&quot;&gt;videojs-options&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;常用方法和事件&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;autoplay()获取或者设置自动播放属性&lt;/li&gt;
  &lt;li&gt;currentTime()设置或者获取当前播放进度&lt;/li&gt;
  &lt;li&gt;duration()获取视屏的总长度，一般要等到视屏对象完全加载后才能获取到，一般我们会使用定时轮询的方式来获取总时长&lt;/li&gt;
  &lt;li&gt;ended()获取当前视屏对象是否已经处于结束状态&lt;/li&gt;
  &lt;li&gt;enterFullWindow() 当全屏不支持我们可以视频容器延伸到浏览器将让我们一样宽。经过试验改api完全无法使视屏进入全屏。分析源码后发现真正进入全屏的api应该是requestFullscreen()，但可惜该api只能又手势触发函数执行，连模拟点击都没法触发他。&lt;/li&gt;
  &lt;li&gt;exitFullscreen() 退出全屏，有效的&lt;/li&gt;
  &lt;li&gt;exitFullWindow() 退出全屏，试了没什么用&lt;/li&gt;
  &lt;li&gt;height() 设置/获取播放器的高度&lt;/li&gt;
  &lt;li&gt;width() 设置/获取播放器的宽度&lt;/li&gt;
  &lt;li&gt;isFullscreen() 检查是否处于全屏模式&lt;/li&gt;
  &lt;li&gt;load() 开始加载视屏&lt;/li&gt;
  &lt;li&gt;loop() 在视频中获取或设置循环属性元素&lt;/li&gt;
  &lt;li&gt;muted() 获取当前的静音状态&lt;/li&gt;
  &lt;li&gt;pause() 暂停视频&lt;/li&gt;
  &lt;li&gt;paused() 检查视屏是否暂停&lt;/li&gt;
  &lt;li&gt;play() 播放视屏&lt;/li&gt;
  &lt;li&gt;played() 检查视屏播放状态&lt;/li&gt;
  &lt;li&gt;preload() 获取或设置预加载属性&lt;/li&gt;
  &lt;li&gt;ready() 视屏对象加载完成后调用ready中的回调函数&lt;/li&gt;
  &lt;li&gt;poster() 获取或设置海报图像源url&lt;/li&gt;
  &lt;li&gt;reset() 重载视屏&lt;/li&gt;
  &lt;li&gt;src() 更换视频源&lt;/li&gt;
  &lt;li&gt;dispose() 销毁视频实例&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;更多事件以及&lt;code class=&quot;highlighter-rouge&quot;&gt;api&lt;/code&gt;&lt;a href=&quot;https://docs.videojs.com/docs/api/player.html&quot;&gt;videojs-api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;事件监听采用&lt;code class=&quot;highlighter-rouge&quot;&gt;on('listener', cb)&lt;/code&gt;,&lt;code class=&quot;highlighter-rouge&quot;&gt;off('list')&lt;/code&gt;移除事件监听&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	this.on('firstplay', e =&amp;gt; {});  
	this.on('progress', e =&amp;gt; {});  
	this.on('timeupdate', e =&amp;gt; {}); 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
  &lt;li&gt;视频开始加载时会触发&lt;code class=&quot;highlighter-rouge&quot;&gt;firstplay&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;实例化之后会触发&lt;code class=&quot;highlighter-rouge&quot;&gt;progress&lt;/code&gt;,有时候实例化之后无法与后台建立连接,可以在回调设置一个定时器,监听3s后的&lt;code class=&quot;highlighter-rouge&quot;&gt;currentTime()&lt;/code&gt;判断是否建立连接&lt;/li&gt;
  &lt;li&gt;视频播放时会不断触发&lt;code class=&quot;highlighter-rouge&quot;&gt;timeupdate&lt;/code&gt;事件,结合&lt;code class=&quot;highlighter-rouge&quot;&gt;currentTime()&lt;/code&gt;可以检测是否播放中断&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;遇到的问题&quot;&gt;遇到的问题&lt;/h4&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;videojs&lt;/code&gt;播放窗口小于400&lt;em&gt;300时无法自动播放,因为&lt;code class=&quot;highlighter-rouge&quot;&gt;video-js.swf&lt;/code&gt;文件跨域.播放&lt;code class=&quot;highlighter-rouge&quot;&gt;rtmp&lt;/code&gt;视频时&lt;code class=&quot;highlighter-rouge&quot;&gt;videojs&lt;/code&gt;会在&lt;code class=&quot;highlighter-rouge&quot;&gt;cdn&lt;/code&gt;上加载一个&lt;code class=&quot;highlighter-rouge&quot;&gt;video-js.swf&lt;/code&gt;文件,该文件必须同源才能支持播放窗口小于400&lt;/em&gt;300时自动播放&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;使用&lt;code class=&quot;highlighter-rouge&quot;&gt;dispose()&lt;/code&gt;销毁实例时会将页面上的&lt;code class=&quot;highlighter-rouge&quot;&gt;dom&lt;/code&gt;节点一并移除,如果需要二次复用,则可以在初始实例化时先将节点保存起来&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;videojs提示 (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) No compatible source was found for this video.可能是没有开始浏览器&lt;code class=&quot;highlighter-rouge&quot;&gt;flash&lt;/code&gt;支持,&lt;code class=&quot;highlighter-rouge&quot;&gt;chrome&lt;/code&gt;默认是询问,需要改成&lt;code class=&quot;highlighter-rouge&quot;&gt;允许&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</description>
      </item>
    
      <item>
        <title>Vue2.x回顾</title>
        <link>https://homary.github.io/Vue2.X%E5%9B%9E%E9%A1%BE</link>
        <pubDate>Fri, 22 Feb 2019 00:00:00 +0000</pubDate>
        <author></author>
        <description>&lt;h3 id=&quot;vue2x回顾&quot;&gt;Vue2.X回顾&lt;/h3&gt;

&lt;h4 id=&quot;写在前面&quot;&gt;写在前面&lt;/h4&gt;

&lt;p&gt;子曰: “温故而知新”;所以我经常在自己的学习生涯中进行阶段性回顾,方便以后复习.2019年准备入手学习&lt;code class=&quot;highlighter-rouge&quot;&gt;React&lt;/code&gt;,在这之前对自己已经掌握的&lt;code class=&quot;highlighter-rouge&quot;&gt;Vue&lt;/code&gt;进行一下回顾.&lt;/p&gt;

&lt;h4 id=&quot;开始之前&quot;&gt;开始之前&lt;/h4&gt;

&lt;p&gt;工欲善其事必先利其器,最好先掌握&lt;code class=&quot;highlighter-rouge&quot;&gt;Webpack&lt;/code&gt;,&lt;code class=&quot;highlighter-rouge&quot;&gt;Babel&lt;/code&gt;,&lt;code class=&quot;highlighter-rouge&quot;&gt;ES6&lt;/code&gt;,&lt;code class=&quot;highlighter-rouge&quot;&gt;npm&lt;/code&gt;;&lt;br /&gt;
我几乎没用过&lt;code class=&quot;highlighter-rouge&quot;&gt;vue-cli&lt;/code&gt;提供的脚手架,除了快速开发否则我都是自己撘脚手架,这只是为了我可以接触更多的技术,学习到新的知识.下面附上我常用的配置:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
// webpack.config.js  
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const Autoprefixer = require('autoprefixer');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const LessFunc = require('less-plugin-functions');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const isProduction = process.env.NODE_ENV === 'production';

const DevServer = require('./webpack.server.js');

module.exports = {
	entry: {
		main: path.resolve(__dirname + '/src/index.ts'),
		lib: ['vue', 'vue-class-component']
	},
	output: {
		path: path.resolve(__dirname + '/build/'),
		filename: isProduction ? 'js/[name].min.js' : 'js/[name].js'
	},
	module: {
		rules: [
			{
                test: /\.tsx?$/,
                exclude: /node_modules/,
                loader: 'ts-loader',
                options: {
                    appendTsSuffixTo: [/\.vue$/]
                }
            },
			{
                test: /\.js$/,
                exclude: path.resolve(__dirname, '/node_modules'),
                loader: 'babel-loader',
                options: {
                    &quot;presets&quot;: [&quot;@babel/preset-env&quot;]
                }
            },
            {
                test: /\.less$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: ['css-loader', {
                        loader: 'postcss-loader',
                        options: {
                            plugins: [
                                require('autoprefixer')({
                                    browsers: ['last 5 versions']
                                })
                            ]
                        }
                    }, {
                        loader: 'less-loader',
                        options: {
                            plugins: [ new LessFunc() ]
                        }
                    }, {
                        loader: 'style-resources-loader',
                        options: {
                            patterns: path.resolve(__dirname, './src/style/common.less')
                        }
                    }]
                })
            },
            {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: ['css-loader']
                })
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.jpg|\.png|\.jpeg|\.svg|\.ttf|\.woff$/,
                use: [{
                    loader: 'file-loader',
                    options: {
                        name: '[name].[ext]',
                        outputpath: './img',
                        publicpath: './img'
                    }
                }]
            }
		]
	},
	plugins: [
        new HtmlWebpackPlugin({
            title: '主页',
            filename: 'index.html',
            template: './index.html',
            inject: 'body',
            hash: true,
            chunks: ['main', 'lib'],
            minify: {
                removeComments: true, //移除HTML中的注释
                collapseWhitespace: true, //移除空白字符
                minifyJS: true, 
                removeScriptTypeAttributes: true,
                removeStyleLinkTypeAttributes: true
            }
        }),
        Autoprefixer,
        new ExtractTextPlugin('[name].css'),
        new VueLoaderPlugin(),
        new CopyWebpackPlugin([{
            from: path.resolve(__dirname, './src/config.js'),
            toType: 'file'
        }])
    ],
    devServer: isProduction ? '' : DevServer,
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src')
        },
        extensions: ['.js', '.ts', '.json', '.less', '.css']
    },
    optimization: {
        splitChunks: {
            cacheGroups: {
                commons: {
                    name: 'lib',
                    chunks: 'all',
                    minChunks: 2
                }   
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Webpack&lt;/code&gt;常用配置说明:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;entry: 文件入口,可以有多个入口但是只能有一个出口;&lt;/li&gt;
  &lt;li&gt;output: 出口配置;&lt;/li&gt;
  &lt;li&gt;module: 配置不同文件处理的&lt;code class=&quot;highlighter-rouge&quot;&gt;rules&lt;/code&gt;;&lt;/li&gt;
  &lt;li&gt;plugins: 插件设置;&lt;/li&gt;
  &lt;li&gt;resolve: 设置别名(&lt;code class=&quot;highlighter-rouge&quot;&gt;alias&lt;/code&gt;)和省略引用后缀(&lt;code class=&quot;highlighter-rouge&quot;&gt;extensions&lt;/code&gt;)等;&lt;/li&gt;
  &lt;li&gt;DevServer: &lt;code class=&quot;highlighter-rouge&quot;&gt;webpack-dev-server&lt;/code&gt;设置;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;插件说明: &lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;html-webpack-plugin&lt;/code&gt;: 用于处理&lt;code class=&quot;highlighter-rouge&quot;&gt;html&lt;/code&gt;模板可以自动引入打包后的文件;&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;extract-text-webpack-plugin&lt;/code&gt;: 将&lt;code class=&quot;highlighter-rouge&quot;&gt;css&lt;/code&gt;文件从&lt;code class=&quot;highlighter-rouge&quot;&gt;js&lt;/code&gt;中分离;&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;style-resources-loader&lt;/code&gt;: 引入全局&lt;code class=&quot;highlighter-rouge&quot;&gt;less&lt;/code&gt;文件;&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;less-plugin-functions&lt;/code&gt;: 自定义&lt;code class=&quot;highlighter-rouge&quot;&gt;less&lt;/code&gt;函数;&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;autoprefixer&lt;/code&gt;: 配合&lt;code class=&quot;highlighter-rouge&quot;&gt;postcss-loader&lt;/code&gt;实现自动添加&lt;code class=&quot;highlighter-rouge&quot;&gt;css&lt;/code&gt;前缀;
&lt;code class=&quot;highlighter-rouge&quot;&gt;babel-loader&lt;/code&gt;: 处理&lt;code class=&quot;highlighter-rouge&quot;&gt;ES6&lt;/code&gt;语法;&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;ts-loader&lt;/code&gt;: 处理&lt;code class=&quot;highlighter-rouge&quot;&gt;TypeScript&lt;/code&gt;;&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;vue-loader&lt;/code&gt;: 处理&lt;code class=&quot;highlighter-rouge&quot;&gt;.vue&lt;/code&gt;文件(&lt;code class=&quot;highlighter-rouge&quot;&gt;webpack4.0&lt;/code&gt;之后处理&lt;code class=&quot;highlighter-rouge&quot;&gt;vue&lt;/code&gt;需要引入插件&lt;code class=&quot;highlighter-rouge&quot;&gt;vue-loader/lib/plugin&lt;/code&gt;);&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;copy-webpack-plugin&lt;/code&gt;: 用于拷贝文件;&lt;/p&gt;

&lt;h4 id=&quot;目录结构&quot;&gt;目录结构&lt;/h4&gt;

&lt;p&gt;下面是我经常用的项目结构:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;├── build 打包后目录
├── src
│   ├── assets/  静态文件目录
│   ├── components/  公共组件目录
│   ├── route/  `vue-router`路由
│   ├── store/ `vuex`目录
│   ├── style/  样式所在目录
│   ├── utils/ 工具函数目录
│   ├── views/  页面文件目录
│   ├── index.js 入口文件
│   ├── app.vue  
│   ├── config.js  全局配置文件
├── index.html
├── package.json
├── webpack.config.js
├── webpack.server.js
├── README.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;可以根据个人习惯进行更改;&lt;/p&gt;

&lt;h4 id=&quot;开始使用&quot;&gt;开始使用&lt;/h4&gt;

&lt;p&gt;在&lt;code class=&quot;highlighter-rouge&quot;&gt;index.js&lt;/code&gt;即入口文件中引入&lt;code class=&quot;highlighter-rouge&quot;&gt;vue&lt;/code&gt;,&lt;code class=&quot;highlighter-rouge&quot;&gt;vue-router&lt;/code&gt;,&lt;code class=&quot;highlighter-rouge&quot;&gt;vuex&lt;/code&gt;或者其他使用的框架,插件.&lt;br /&gt;
实例化一个&lt;code class=&quot;highlighter-rouge&quot;&gt;vue&lt;/code&gt;实例,并挂载到页面之上.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import Vue from 'vue';
import App from './app'; // 主页面

const vm = new Vue({
	render: h =&amp;gt; h(App) // 使用`render`函数渲染
}).$mount('#app') // 挂载到`html`页面上`id`为`app`的元素上;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;流程: 入口文件(&lt;code class=&quot;highlighter-rouge&quot;&gt;index.js&lt;/code&gt;) -&amp;gt; 页面文件(&lt;code class=&quot;highlighter-rouge&quot;&gt;app.vue&lt;/code&gt;) -&amp;gt; 渲染并挂载(&lt;code class=&quot;highlighter-rouge&quot;&gt;$mount(el)&lt;/code&gt;);&lt;/p&gt;

&lt;p&gt;其他页面的展示都是在&lt;code class=&quot;highlighter-rouge&quot;&gt;app.vue&lt;/code&gt;上,可以把&lt;code class=&quot;highlighter-rouge&quot;&gt;app.vue&lt;/code&gt;当成是画板,我们实现的其他组件都是在此画板上作画;&lt;/p&gt;

&lt;h4 id=&quot;路由&quot;&gt;路由&lt;/h4&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;vue-router&lt;/code&gt;让我们可以在不同的路由地址显示不同的组件,使用也很简单;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
// index.js
import Vue from 'vue';
import route from './route/index'; // 引入路由配置文件
import App from './app';

new Vue({
	el: '#app', // 与调用`$mount`一样  
	route,
	render: h =&amp;gt; h(App);
})  

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;路由配置&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// ./route/index.js  

import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

export default new VueRouter({
	mode: hash / history (默认hash),
	route: [
		{
		path: '/', // 路由
		name: 'test', // 名称  
		component:  // 模板
	}
	]
})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// app.vue  

&amp;lt;template&amp;gt;
	&amp;lt;div&amp;gt;
		&amp;lt;router-view&amp;gt;/*路由模板显示的窗口*/&amp;lt;/router-view&amp;gt;
	&amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;更多的配置翻阅&lt;code class=&quot;highlighter-rouge&quot;&gt;vue-router&lt;/code&gt;官方文档;&lt;/p&gt;
</description>
      </item>
    
      <item>
        <title>Css Grid网格布局学习整理</title>
        <link>https://homary.github.io/CSS-grid%E7%BD%91%E6%A0%BC%E5%B8%83%E5%B1%80%E5%AD%A6%E4%B9%A0%E6%95%B4%E7%90%86</link>
        <pubDate>Wed, 28 Nov 2018 00:00:00 +0000</pubDate>
        <author></author>
        <description>&lt;h2 id=&quot;网格布局&quot;&gt;网格布局&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;CSS网格布局引入了二维网格布局系统，可用于布局页面主要的区域布局或小型组件.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;网格容器&quot;&gt;网格容器&lt;/h3&gt;

&lt;p&gt;通过在元素上声明&lt;code class=&quot;highlighter-rouge&quot;&gt;display: grid&lt;/code&gt;或&lt;code class=&quot;highlighter-rouge&quot;&gt;display: inline-grid&lt;/code&gt;来创建一个网格容器;&lt;br /&gt;
这个元素的所有直系子元素都会成为网格元素.&lt;/p&gt;

&lt;h3 id=&quot;网格单元-网格轨道-网格线&quot;&gt;网格单元 网格轨道 网格线&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex3.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;网格单元: 每一个格都是一个一个网格单元&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;网格轨道: 行轨道和列轨道&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;网格线: 默认从左到右,从上到下开始为1,结尾为-1&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;轨道大小&quot;&gt;轨道大小&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;grid-template-columns: 定义网格的列轨道属性
    &lt;blockquote&gt;
      &lt;p&gt;用法: 列宽度 列宽度(有多少列就写多少个)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;grid-template-rows: 定义网格的行轨道属性
    &lt;blockquote&gt;
      &lt;p&gt;用法: 与&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-rows&lt;/code&gt;一样&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;grid-template: &lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-rows&lt;/code&gt;和&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-columns&lt;/code&gt;的缩写
    &lt;blockquote&gt;
      &lt;p&gt;用法: rows / cols&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;fr单位: 代表网格容器中可用空间的一等份&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;repeat(): 定义重复的行或者列
    &lt;blockquote&gt;
      &lt;p&gt;用法: repeat(数量, 大小)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;minmax(): 定义了一个长宽范围的闭区间
    &lt;blockquote&gt;
      &lt;p&gt;用法: minmax(最小值, 最大值)&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;下面我们声明一个网格容器.&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wrapper&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;one&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;two&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;three&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;four&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;five&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;将列数设置为5列:前两列大小为100px,后三列大小为可用空间的等份  &lt;br /&gt;
将函数设置为3行:高度最小为100px, 当内容超过100px自适应高度&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper{  
    display: grid;  
    grid-template-columns: repeat(2, 100px) repeat(3, 1fr);  
    grid-template-rows: repeat(3, minmax(100px, auto));  
} 
或用grid-template
.wrapper{  
    display: grid;  
    grid-template:repeat(3,minmax(100px,auto)) / repeat(2,100px) repeat(3,1fr);  
} 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex1.png&quot; alt=&quot;1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;我们使用Firefox打开,在控制台可以看到定义为网格容器的元素旁边有个gird标识&lt;br /&gt;
我们打开它就可以在页面看到我们定义的网格.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;隐式和显式网格-上面我们用grid-template-columns和grid-template-rows显式创建了一个3行5列的网格但如果我们的内容超出了显式定义的网格大小需要更多的网格的时候网格将会在隐式网格中创建行和列&quot;&gt;隐式和显式网格: 上面我们用&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-columns&lt;/code&gt;和&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-rows&lt;/code&gt;显式创建了一个3行5列的网格.但如果我们的内容超出了显式定义的网格大小,需要更多的网格的时候,网格将会在隐式网格中创建行和列&lt;/h3&gt;

&lt;p&gt;我们可以用&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-auto-columns&lt;/code&gt;和&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-auto-rows&lt;/code&gt;属性定义隐式网格中创建的轨道大小&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wrapper&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;One&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Two&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Three&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Four&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Five&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 200px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex2.png&quot; alt=&quot;2&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;网格间距&quot;&gt;网格间距&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;grid-row-gap: 网格横向间距&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;grid-column-gap: 网格纵向间距&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;grid-gap: &lt;code class=&quot;highlighter-rouge&quot;&gt;grid-row-gap&lt;/code&gt;和&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-column-gap&lt;/code&gt;的缩写&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;用法 grid-gap: 横向间距 / 纵向间距&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;我们创建一个横向间距为50px, 纵向间距为100px的网格&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wrapper&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;One&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Two&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Three&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Four&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Five&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper{
    display: grid;
    grid-template-column: repeat(3, 1fr);
    grid-gap: 50px / 100px; 
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex4.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;跨轨道放置网格元素&quot;&gt;跨轨道放置网格元素&lt;/h4&gt;

&lt;p&gt;在放置元素时,我们使用网格线定位.下面认识几个定义在网格单元上的属性.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;grid-column-start: 开始的列线&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;grid-column-end: 结束的列线&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;grid-column: &lt;code class=&quot;highlighter-rouge&quot;&gt;grid-column-start&lt;/code&gt;和&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-column-end&lt;/code&gt;的缩写&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;grid-row-start: 开始的行线&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;grid-row-end: 结束的行线&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;grid-row: &lt;code class=&quot;highlighter-rouge&quot;&gt;grid-row-start&lt;/code&gt;和&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-row-end&lt;/code&gt;的缩写&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;grid-area: &lt;code class=&quot;highlighter-rouge&quot;&gt;grid-row-start&lt;/code&gt; &lt;code class=&quot;highlighter-rouge&quot;&gt;grid-column-start&lt;/code&gt; &lt;code class=&quot;highlighter-rouge&quot;&gt;grid-row-end&lt;/code&gt; &lt;code class=&quot;highlighter-rouge&quot;&gt;grid-column-end&lt;/code&gt;的缩写&lt;/p&gt;
    &lt;blockquote&gt;
      &lt;p&gt;用法: grid-area: 行开始 / 列开始 / 行结束 / 列结束&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;下面我们把前两个元素放到了我们的三列网格中。从左至右，第一个元素从列线1开始，延伸至列线4，也就是我们这个例子中最右边的列线。并从行线1延伸到行线3，占据了两个行轨道。&lt;br /&gt;
&lt;em&gt;第二个元素从列线1开始，延伸了一个轨道。因为这是默认行为，所以不用指定结束线&lt;/em&gt;并且它从行线3到行线5，跨越了两个行轨道。剩下的元素会自动放到网格剩余的空间中。&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wrapper&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;box1&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;One&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;box2&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Two&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;box3&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Three&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;box4&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Four&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;box5&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Five&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper { 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    grid-auto-rows: 100px; 
} 
.box1 { 
    grid-area: 1 / 1 / 3 / 4;
} 
.box2 { 
    grid-column-start: 1; 
    grid-row: 3 / 5; 
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex5.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;使用span关键字定义跨越的轨道数&quot;&gt;使用span关键字,定义跨越的轨道数.&lt;/h4&gt;

&lt;p&gt;.box2从行线3到行线5跨越2个轨道&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.box2 { 
    grid-column-start: 1; 
    grid-row: 3 / 5; 
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;也可以写为&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.box2 { 
    grid-column-start: 1; 
    grid-row: 3 / span 2; 
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;命名网格区域&quot;&gt;命名网格区域&lt;/h3&gt;

&lt;p&gt;grid-area把网格线4个属性合为1个值,用于定位网格区域.在用网格线定义网格区域时,我们  通常指定网格区域的四条线来定义.&lt;/p&gt;

&lt;p&gt;我们也可以先给一个区域命名,然后在网格容器&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-areas&lt;/code&gt;属性值中指定这个区域的位置.&lt;br /&gt;
可以随意给区域命名,比如要创建下面的布局,我们可以先划分出4个主要区域:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;头部(header)&lt;/li&gt;
  &lt;li&gt;尾部(footer)&lt;/li&gt;
  &lt;li&gt;侧边栏(sidebar)&lt;/li&gt;
  &lt;li&gt;主要内容(content)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;通过子元素&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-area&lt;/code&gt;属性为这些区域分配一个名字.&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.header {
    grid-area: hd;
}
.footer {
    grid-area: ft;
}
.content {
    grid-area: main;
}
.sidebar {
    grid-area: sd;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;有了区域名字之后,我们就可以在网格容器上创建布局&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-auto-rows: minmax(100px, auto);
    grid-template-areas: 
      &quot;hd hd hd hd   hd   hd   hd   hd   hd&quot;
      &quot;sd sd sd main main main main main main&quot;
      &quot;ft ft ft ft   ft   ft   ft   ft   ft&quot;;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wrapper&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;header&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Header&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sidebar&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Sidebar&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Content&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;footer&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Footer&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex6.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;留出空白的网格单元&quot;&gt;留出空白的网格单元&lt;/h3&gt;

&lt;p&gt;在上面的例子中，已经实现了用区域填充网格，不留空余空间，不过你也可以用这种布局方法留出空的网格单元。留出空单元的方法是使用句点符，“.”。假如想把尾部区域仅显示在主要内容的下方，就应该让侧边栏下面的三个单元格为空。&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-auto-rows: minmax(100px, auto);
    grid-template-areas: 
      &quot;hd hd hd hd   hd   hd   hd   hd   hd&quot;
      &quot;sd sd sd main main main main main main&quot;
      &quot;.  .  .  ft   ft   ft   ft   ft   ft&quot;;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex7.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;网格定义的简写&quot;&gt;网格定义的简写&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template&lt;/code&gt; 属性可以同时设置以下属性&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-rows&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-columns&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-areas&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;使用&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template&lt;/code&gt;实现前面创建的布局&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper {
    display: grid;
    grid-template: 
      &quot;hd hd hd hd   hd   hd   hd   hd   hd&quot; minmax(100px, auto)
      &quot;sd sd sd main main main main main main&quot; minmax(100px, auto)
      &quot;ft ft ft ft   ft   ft   ft   ft   ft&quot; minmax(100px, auto)
      / 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ;           
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;第一个值是&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-areas&lt;/code&gt;的值,并且在每一行末尾声明了行大小,minmax(100px, auto)的作用.&lt;/p&gt;

&lt;p&gt;在&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-areas&lt;/code&gt;之后用一个左斜杠分隔,再之后是一个详细的列轨道清单.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;使用命名线布局&quot;&gt;使用命名线布局　　&lt;/h3&gt;

&lt;p&gt;在用&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-columns&lt;/code&gt;和&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-template-rows&lt;/code&gt;属性定义网络时,可以为网络中的部分或全部网格线命名.&lt;/p&gt;

&lt;p&gt;在定义网格时,把网格线的名字写在方括号内,名字随意.&lt;br /&gt;
不一定要把全部网格线都命名，只需要为布局时用到的关键线命名即可。&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper {
 display: grid;
 grid-template-columns: [main-start] 1fr [content-start] 1fr [content-end] 1fr [main-end];
  grid-template-rows: [main-start] 100px [content-start] 100px [content-end] 100px [main-end];
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;一旦这些网格线有了名字，我们就可以用比线序号更易用的线名字来定位项目了。&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.box1 {
  grid-column-start: main-start;
  grid-row-start: main-start;
  grid-row-end: main-end;
}
.box2 {
  grid-column-start: content-end;
  grid-row-start: main-start;
  grid-row-end: content-end;
}
.box3 {
  grid-column-start: content-start;
  grid-row-start: main-start;
}
.box4 {
  grid-column-start: content-start;
  grid-column-end: main-end;
  grid-row-start: content-end;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wrapper&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;box1&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;One&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;box2&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Two&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;box3&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Three&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;box4&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Four&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex7.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;为网格线定义多个名字&quot;&gt;为网格线定义多个名字&lt;/h4&gt;

&lt;p&gt;你可能想要给一条线命名多个名字，比如在上例中的 sidebar-end 和 main-start 其实是同一条线。为了实现这个效果，只要把多个名字都写到方括号里，然后用空格分隔就行了：[sidebar-end main-start]。在引用时可以使用其中的任何一个名字。&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;自动定位的默认规则&quot;&gt;自动定位的默认规则&lt;/h3&gt;

&lt;p&gt;创建网格之后,所有子项目都会把自己摆放在网格中,每个单元格一个.默认方向是按行排列,网格会首先尝试在第1行的每个单元格中摆放项目。如果已经通过 grid-template-rows 属性创建了其他行，网格就会继续把项目摆放到这些行中。如果在显式的网格中没有足够的行用来摆放所有的项目，隐式的新行就会被创建出来。&lt;/p&gt;

&lt;p&gt;在默认情况下，网格中被自动创建的隐式行的尺寸是自适应大小的，也就是说它们会包含所有属于它们的内容，而不会让内容溢出。&lt;/p&gt;

&lt;p&gt;不过可以通过 &lt;code class=&quot;highlighter-rouge&quot;&gt;grid-auto-rows&lt;/code&gt; 属性来控制它们的大小&lt;/p&gt;

&lt;h3 id=&quot;按列自动定位&quot;&gt;按列自动定位&lt;/h3&gt;

&lt;p&gt;网格也可以按列来自动定位项目，只要设置&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-auto-flow&lt;/code&gt;的属性值为&lt;em&gt;column&lt;/em&gt;即可&lt;/p&gt;

&lt;p&gt;在下面的例子中，创建了一个行高为200像素的三个行轨道的网格，按列优先自动排列，先创建一个 300 像素宽的列，接着是一个 100像素宽的列，直至创建出足够多的列来容纳全部项目。&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper {
    display: grid;
    grid-template-rows: repeat(3, 200px);
    grid-gap: 10px;
    grid-auto-flow: column;
    grid-auto-columns: 300px 100px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;div class=&quot;wrapper&quot;&amp;gt;
   &amp;lt;div&amp;gt;One&amp;lt;/div&amp;gt;
   &amp;lt;div&amp;gt;Two&amp;lt;/div&amp;gt;
   &amp;lt;div&amp;gt;Three&amp;lt;/div&amp;gt;
   &amp;lt;div&amp;gt;Four&amp;lt;/div&amp;gt;
   &amp;lt;div&amp;gt;Five&amp;lt;/div&amp;gt;
   &amp;lt;div&amp;gt;Six&amp;lt;/div&amp;gt;
   &amp;lt;div&amp;gt;Seven&amp;lt;/div&amp;gt;
   &amp;lt;div&amp;gt;Eight&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex9.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;填充缺口&quot;&gt;填充缺口&lt;/h3&gt;

&lt;p&gt;至此，除了我们明确定位过的项目，其他项目一般都会被网格自动处理并且保持它们在 DOM 中的顺序，有时候就会产生缺口.&lt;/p&gt;

&lt;p&gt;当我们希望创建一种没有缺口的布局时,只需要在网格容器的&lt;code class=&quot;highlighter-rouge&quot;&gt;grid-auto-flow&lt;/code&gt;属性值中加入&lt;em&gt;dense&lt;/em&gt;关键字.&lt;/p&gt;

&lt;p&gt;经过以上设置，网格就会回填缺口，以前网格会遗留下缺口，而现在它会为此前的缺口找到适合它的项目，然后把项目从 DOM 中拿出来再放到缺口中去。&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;###　网格布局中的盒模型对齐　　&lt;/p&gt;

&lt;h4 id=&quot;网格容器上的属性&quot;&gt;网格容器上的属性&lt;/h4&gt;

&lt;p&gt;对齐方式与在flex容器中对flex项目对齐差不多&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;align-items 行轨道方向对齐&lt;/li&gt;
  &lt;li&gt;justify-items 列轨道方向对齐&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;子项目的属性&quot;&gt;子项目的属性&lt;/h4&gt;

&lt;p&gt;-align-self
-justify-self&lt;/p&gt;

&lt;p&gt;以上四个属性可选值都为&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;auto&lt;/li&gt;
  &lt;li&gt;normal&lt;/li&gt;
  &lt;li&gt;start&lt;/li&gt;
  &lt;li&gt;end&lt;/li&gt;
  &lt;li&gt;center&lt;/li&gt;
  &lt;li&gt;stretch&lt;/li&gt;
  &lt;li&gt;baseline&lt;/li&gt;
  &lt;li&gt;first baseline&lt;/li&gt;
  &lt;li&gt;last baseline&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;使项目水平垂直居中&quot;&gt;使项目水平垂直居中&lt;/h3&gt;

&lt;p&gt;通过组合使用 align 和 justify 属性，让项目居于网格区域的正中就变得非常容易了。&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.wrapper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: 10px;
  grid-auto-rows: 200px;
  grid-template-areas: 
    &quot;. a a .&quot;
    &quot;. a a .&quot;;
}
.item1 {
  grid-area: a;
  align-self: center;
  justify-self: center;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wrapper&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;item1&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Item 1&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-28/ex10.png&quot; alt=&quot;10&quot; /&gt;&lt;/p&gt;

</description>
      </item>
    
      <item>
        <title>使用github打造属于自己的个人博客</title>
        <link>https://homary.github.io/%E4%BD%BF%E7%94%A8github%E6%89%93%E9%80%A0%E5%B1%9E%E4%BA%8E%E8%87%AA%E5%B7%B1%E7%9A%84%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2(%E5%82%BB%E7%93%9C%E5%BC%8F%E6%93%8D%E4%BD%9C)</link>
        <pubDate>Fri, 16 Nov 2018 00:00:00 +0000</pubDate>
        <author></author>
        <description>&lt;h3 id=&quot;toready&quot;&gt;toReady&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt;
首先你需要一个 github 账号. 什么? 没有! =&amp;gt; &lt;a href=&quot;https://www.github.com&quot;&gt;www.github.com&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;todo&quot;&gt;toDo&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;新建一个仓库.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-16/1.png&quot; alt=&quot;1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-16/2.png&quot; alt=&quot;2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-16/3.png&quot; alt=&quot;3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-16/4.png&quot; alt=&quot;4&quot; /&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;在本地初始化一个仓库&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
新建一个文件夹,在该文件夹下打开控制台&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git  init // 初始化为一个空仓库  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在该目录下新建一个index.html,随便写点东西.并提交&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; git add .  
 git commit -m &quot;初始化&quot;  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;关联本地仓库与远程仓库&lt;br /&gt;
复制在github上创建好仓库之后显示的&lt;strong&gt;…or push an existing repository from the command line&lt;/strong&gt;标题下的那两行代码,在本地仓库控制台输入.接着输入你的github账户名以及密码,如果出现下面的提示则成功.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-16/6.png&quot; alt=&quot;6&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;引入jekyll模板&quot;&gt;引入jekyll模板&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;现在我们在github上刷新我们刚创建的仓库,已经能看到我们刚刚提交的文件了.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-16/7.png&quot; alt=&quot;7&quot; /&gt;&lt;/p&gt;

&lt;p&gt;在setting在看 GitHub Pages, 点击下面给的连接就可以看到我们在index.html写的东西.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../assets/images/2018-11-16/8.png&quot; alt=&quot;8&quot; /&gt;&lt;br /&gt;
&lt;img src=&quot;../assets/images/2018-11-16/9.png&quot; alt=&quot;9&quot; /&gt;&lt;/p&gt;

&lt;p&gt;现在我们就已经完成了我们的博客首页了,但是我们不能总是写html静态文件,我们要打造的是博客网站,这就需要用到jekyll这个工具.如果不想花时间学Jekyll语法的话,我们可以直接下载别人的模板.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://www.jekyll.com.cn/docs/structure/&quot;&gt;jekyll中文网—目录结构&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;在 &lt;a href=&quot;http://jekyllthemes.org/&quot;&gt;jekyllthemes&lt;/a&gt;在下载一个自己喜欢的模板&lt;/li&gt;
  &lt;li&gt;按照之间的步骤把下载好的模板上床到自己的Github远程仓库&lt;/li&gt;
  &lt;li&gt;在_post文件夹中放入自己写好的博客, 文件名必须是 年份-月份-日-标题&lt;/li&gt;
  &lt;li&gt;上传博客到Github中就可以访问.&lt;br /&gt;
&lt;br /&gt;
    &lt;h3 id=&quot;我们还需要给我们的博客添加评论功能这要用到gitment&quot;&gt;我们还需要给我们的博客添加评论功能,这要用到gitment.&lt;/h3&gt;
    &lt;h4 id=&quot;申请一个github-oauth-application&quot;&gt;申请一个Github OAuth Application&lt;/h4&gt;
    &lt;p&gt;Github头像下拉菜单 &amp;gt; Settings &amp;gt; 左边Developer settings下的OAuth Application &amp;gt; Register a new application，填写相关信息：&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Application name, Homepage URL, Application description 都可以随意填写.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Authorization callback URL 一定要写自己Github Pages的URL.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;填写完上述信息后按Register application按钮，得到Client ID和Client Secret.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;在jekyll博客调用gitment&quot;&gt;在jekyll博客调用gitment　　&lt;/h4&gt;
&lt;p&gt;在你需要添加评论系统的地方，一般是_layout/目录下的 post.html, 添加一下代码:　&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&amp;lt;div id=&quot;gitmentContainer&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;https://imsun.github.io/gitment/style/default.css&quot;&amp;gt;
&amp;lt;script src=&quot;https://imsun.github.io/gitment/dist/gitment.browser.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
    var gitment = new Gitment({
        id: '&amp;lt;%= page.date %&amp;gt;',
        owner: '你的github名',
        repo: '你的仓库名',
        oauth: {
            client_id: '上面得到的 Client ID',
            client_secret: '上面得到的 Client Secret',
        },
    });
    gitment.render('gitmentContainer')
&amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;初始化评论系统&quot;&gt;初始化评论系统　　&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;将上面代码添加成功并上传之后，就可以在博客页下看到一个评论框，还有看到以下错误&lt;em&gt;Error: Comments Not Initialized&lt;/em&gt;.说明该篇博文的评论系统还没初始化.&lt;/li&gt;
  &lt;li&gt;点击 Login with github后,使用github账号登陆,就可以看到上面错误信息处出现一个 &lt;em&gt;Initialize Comments&lt;/em&gt;的按钮.&lt;/li&gt;
  &lt;li&gt;点击Initialize Comments按钮后，就可以开始对该篇博文开始评论了， 同时也可以在对应的github仓库看到相应的issue。&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;gitment汉化&quot;&gt;gitment汉化&lt;/h4&gt;
&lt;p&gt;将上面模板里引入的CSS和js改成&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;https://billts.site/extra_css/gitment.css&quot;&amp;gt;
&amp;lt;script src=&quot;https://billts.site/js/gitment.js&quot;&amp;gt;&amp;lt;/script&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;遇到坑可以参考这个 &lt;a href=&quot;https://www.jianshu.com/p/57afa4844aaa&quot;&gt;Gitment评论功能接入踩坑教程&lt;/a&gt;&lt;/p&gt;
</description>
      </item>
    

  </channel>
</rss>
