建站小结

本来已经搞定,本地预览没有问题,上传到github上却出现了问题,又纠结了几天。。。

接下来说说建站的过程吧,/(ㄒoㄒ)/~~。

安装node.js

先安装node.js,去官网下,一直next就好,一般不用配(node.js是js运行平台,封装了Google V8引擎,具有轻量高效的特点,用它能快速生成页面)

然后安装git

(一个分布式的版本管理工具,把本地的hexo内容提交到github),一直next就好。。。

注册github账号

建仓库,注意仓库名 username.git.io 这样就能直接通过username.git.io访问博客页面了

安装hexo

node.js和git都安装好后,首先创建一个文件夹(如blog)用来存放hexo的配置文件
进入刚才创建的文件夹中(blog)鼠标右键选择git bash here 执行如下命令
npm install -g hexo 或者 npm install hexo-deployer-git --save(##命令千万不要错了。。。##)
成功之后执行init命令初始化hexo
hexo init
然后执行hexo s,根据提示可以在本地预览hexo的初始模板

博客文件夹中有一些文件

node_modules: 存放hexo的依赖插件
source: 存放我们写的文章
themes: 存放主题文件
_config.yml:hexo配置文件(站点配置文件)

然后去配置一下显示隐藏的文件,目录中没有.git文件夹的话就执行git init
之后就能看见.git文件了,这是为了能用git上传
安装基本完成
我之前就是命令打错了,文件目录有个.npmignore的文件,导致之后用git上传的时候将整个文件夹的内容都上传到github,然后还傻傻的去访问自己的博客主页,一直404,又去百度各种找答案,唉,说多了都是泪。。。
正常目录不是.npmignore文件而是.gitignore文件

配置sshkey

还是在你博客文件目录下执行
git config --global user.name "githubName" git config --global user.email "githubEmail"
生成key
ssh-keygen -t rsa -C "githubEmail"
然后看提示,正常一路回车就行
之后就去到C:\Users\Administrator.ssh将id_rsa.pub用记事本打开,复制里面的内容
进入你的github仓库点击上面的setting,右边的deploy keys
填好标题(任意,长点具体点更好)
再将你刚才复制的东西放在key里,勾上下面的允许改写,点击add key就行了
然后在回到本地执行ssh -T git@github.com测试下是否成功,成功的话仓库那边的钥匙也会变成绿色的
到这里配置就完成了,我们就可以开始写我们自己的博客了

模板的选择

这里贴个链接,是一些主题推荐
Hexo博客主题推荐
选好主题后,复制地址(复制好的地址一般以.git结尾),使用命令git clone address copy到本地,然后将模板文件放在themes文件夹中

_config.yml文件的配置

该文件就在博客目录下,用于博客的一些主要配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: 月初
subtitle: 别打我,我知道我很蠢。。。
description:
author: 月初
language: zh-Hans
timezone:

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://baiyuechu.github.io
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
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: false
tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: yelee

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git

repo: https://github.com/baiyuechu/baiyuechu.github.io.git

branch: master

以上是我的博客配置,按需要更改即可

yelee主题使用

还是贴个链接吧
yelee主题使用说明

开始写博客

source/_posts文件夹下新建.md文件
markdown的语法规则挺简单,就不多说了(虽然很简单,但是百度到的自己写了,却预览不出该有的效果/(ㄒoㄒ)/~~ 还是找个机会写篇博客吧。。。)
说一下设置标签吧,在开头添加tags: [java]即可,有多个标签的话,用逗号隔开即可
右边的有个标签云页面,怎么设置的说明文档上并没有详细的说明,又要缠着度娘去了/(ㄒoㄒ)/~~。。。
之后写个详细点的使用说明吧
那么,就到这里了,嘉㖏

文章目录
  1. 1. 安装node.js
  2. 2. 然后安装git
  3. 3. 注册github账号
  4. 4. 安装hexo
  5. 5. 博客文件夹中有一些文件
  6. 6. 配置sshkey
  7. 7. 模板的选择
  8. 8. _config.yml文件的配置
  9. 9. yelee主题使用
  10. 10. 开始写博客
|