美文网首页
搭建个人博客之路(hexo+github)

搭建个人博客之路(hexo+github)

作者: 可听_ | 来源:发表于2017-11-10 17:11 被阅读0次

前言

在刚刚加入实验室之后,第一份任务便是用GitHub pages与Hexo搭建一个个人博客,由于这两周演讲比赛的原因,一直将这个任务给搁置了,这两天终于完善的走了好几遍搭建这个博客的流程,所以想按自己的思路将所看的帖子都按照自己的想法整理一遍。(笑……)

一、准备工作

使用软件:

备注:不同软件版本的安装与使用会有差异

二、安装Git

  • 大部分按默认安装,一路点击”Next”
    image
  • 这里选择对应的windows选项,如下图
    image
    image
  • 等待安装完成
    image

三、安装Node.js

  • Node安装更加简单,还是一路”Next”,最后等待安装完成即可
    image
    image

四、验证软件并正确安装

  • 同时按下Win键和R键(或者点击“开始菜单”->点击“运行”),打开运行窗口,输入“cmd”
    然后输入以下命令,结果与下图相同则说明安装正确,若不正确可以卸载软件重新安装
1.    git --version
2.    node -v
3.    npm -v
image

五、申请GitHub

  • 点击GitHub进入官网注册帐号
  • 按下图分别输入用户名、邮箱、密码,然后点击注册
    image
  • 按默认点击“Finish sign up”


    image
  • 点击”New repository”,新建一个版本库
    image
  • 输入Repository name:yourname.github.io(yourname与你的注册用户名一致,这个就是你博客的域名了)
    image
  • 到此github帐号申请完成
    image
  • 启用GitHub Page
    点击右边的“Setting”菜单进入设置,点击”Launch automatic page generator”
    image
  • 点击底部的”Continue to layouts”
    image
  • 最后点击”Publish page”,发布github默认生成的一个静态站点
    image
  • 验证邮箱,点击个人设置
    image
  • 点击”Send verification Email”发送验证邮件
    image
  • 进入你的邮箱,查收验证邮件进行验证
    image

六、安装Hexo

hexo是基于node.js的静态博客,官网也是搭建在GitHub上

  • 在电脑上新建一个blog文件夹,该文件夹用于存放你的博客文件,然后右键单击选择“Git Bash”

    image
  • 安装hexo为了避免出现被“墙”的情况,使用淘宝NPM镜像,输入以下命令等待安装完成:

$ npm install -g cnpm --registry=https://registry.npm.taobao.org
  • image
  • 使用淘宝NPM安装Hexo

$ cnpm install -g hexo-cli

与原先的npm完全一样,只是命令改为cnpm,一样等待hexo安装完成

image

出现的WARN可以不用理会,继续输入以下命令

$ cnpm install hexo --save

安装完成后,在输入命令,验证是否安装正确

$ hexo -v

image

七、本地运行hexo

  • 初始化hexo
$ hexo init

image
  • 安装生成器
$ cnpm install

image

*运行hexo,以后要在本地运行博客只要输入该命令即可

   $ hexo s -g

image

打开浏览器,输入localhost:4000,就可以在本地看到你的个人博客了

QQ图片20171110164907.png
  • 停止运行,按住Ctrl+C键即可停止

八、管理博客

  • 配置信息
    使用Sublime_Text编辑器(绿色软件无需安装,解压即可使用)打开blog/_config.yml文件,进行配置
    image
#博客名称
title: 我的博客
#副标题
subtitle: 一天进步一点
#简介
description: 记录生活点滴
#博客作者
author: John Doe
#博客语言
language: zh-CN
#时区
timezone:
#博客地址,与申请的GitHub一致
url: http://elfwalk.github.io
root: /
#博客链接格式
permalink: :year/:month/:day/:title/
permalink_defaults:
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: true
  tab_replace:
default_category: uncategorized
category_map:
tag_map:
#日期格式
date_format: YYYY-MM-DD
time_format: HH:mm:ss
#分页,每页文章数量
per_page: 10
pagination_dir: page
#博客主题
theme: landscape
#发布设置
deploy: 
  type: git
  #elfwalk改为你的github用户名
  repository: https://github.com/elfwalk/elfwalk.github.io.git
  branch: master
  • 写一篇文章
    输入创建文章命令,生成一个md文件(/blog/source/_posts/)
$ hexo new "hello"

image
用编辑器打开hello.md文件,编写完后保存
title: hello
date: 2015-07-01 22:37:23
categories:
  - 日志
  - 二级目录
tags:
  - hello
---
摘要:
<!--more-->
正文:

九、发布博客

配置SSH keys

我们如何让本地git项目与远程的github建立联系呢?用SSH keys。

  • 生成新的SSH Key:
$ ssh-keygen -t rsa -C "邮件地址@youremail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<直接回车>

注意1: 此处的邮箱地址,你可以输入自己的邮箱地址;
注意2: 此处的「-C」的是大写的「C」
然后系统会要你输入密码:

Enter passphrase (empty for no passphrase):<输入加密串>
Enter same passphrase again:<再次输入加密串>

在回车中会提示你输入一个密码,这个密码会在你提交项目时使用,如果为空的话提交项目时则不用输入。这个设置是防止别人往你的项目里提交内容。
注意:输入密码的时候没有*字样的,你直接输入就可以了。
最后看到这样的界面,就成功设置ssh key了:

image
  • 添加SSH Key到GitHub
    在本机设置SSH Key之后,需要添加到GitHub上,以完成SSH链接的设置。
    1、打开本地C:\Documents and Settings\Administrator.ssh\id_rsa.pub文件。此文件里面内容为刚才生成人密钥。如果看不到这个文件,你需要设置显示隐藏文件。准确的复制这个文件的内容,才能保证设置的成功。
    2、登陆github系统。点击右上角的 Account Settings—>SSH Public keys —> add another public keys
    3、把你本地生成的密钥复制到里面(key文本框中), 点击 add key 就ok了

设置git身份信息

$ git config --global user.name "你的用户名"
$ git config --global user.email "你的邮箱"

image
  • 发布更新博客
$ hexo d -g

发布时需要输入github的帐号和密码,输入密码时是看不到自己输入的内容的

image

发布成功后,访问yourname.github.io看下成果

—————————————END—————————————

相关文章

网友评论

      本文标题:搭建个人博客之路(hexo+github)

      本文链接:https://www.haomeiwen.com/subject/tobbmxtx.html