hexo个人博客经验浅谈

[我的博客地址](https://lzz1.top),本站基于 Hexo ,主题采用  [JSimple](https://github.com/tangkunyin/hexo-theme-jsimple)

### 使用hexo+github page建立个人博客优势

+ 简单,易学,主题多多,插件多多

+ 代码托管,无需自己的服务器

+ 全站支持https

+ 一条命令,生成全站所需文件

### 缺点

+ 不喜欢暴露自己文章的,可能是缺点,因为git仓库是公开的

+ 貌似只能在本地编写文章,然后提交到git仓库

### 准备工作(自己电脑操作,我的是win10)

1. node 环境支持,安装方式一大堆,不多说

扫描二维码关注公众号,回复: 5348802 查看本文章

2. git 安装,安装方式一大堆,不多说

### 有了上面支持后,安装hexo

> npm install -g hexo-cli

#### 安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件。

> hexo init 目录

> cd 目录

> npm install

#### OK大功告成

### 我用的主题是 JSimple,所以下载主题

> git clone https://github.com/tangkunyin/hexo-theme-jsimple themes/jsimple

### 网站配置 _config.yml

```

# Site
title: 你网站的标题
subtitle: 副标题
keywords: 关键字
description: 网站描述
author: 作者
language: 语言
    - zh-cn
    - en

timezone: 时区

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: 网站域名
root: /  网站目录
permalink: :category/:title.html  这是显示在浏览器里的链接
permalink_defaults:
  lang: en

# 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:
  - README.md
  - README.zhCN.md

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: true # Transform title into titlecase
external_link: false # Open external links in new tab
filename_case: 0s
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: false
  auto_detect: true
  tab_replace:

# Category & Tag
default_category: 随笔
category_map:  
   随笔: tech-notes
   人文: humanities
   其他: others
tag_map:  
  Hexo: hexo
  网站: website
  后端: backend
  前端: frontend
  JavaScript: javascript
  Vue: vue
  Php: php
  Mysql: mysql
  Python: python
  Linux: linux
  祝福: zhufu
  Excel: excel
  攻略: gonglue

# 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: http://hexo.io/plugins/
## Themes: http://hexo.io/themes/


theme: jsimple  这里写刚才下载的主题,大家可以尝试其它的主题
#theme: hexo-theme-hipaper

# Configuration for search module: hexo-generator-search 
search:
  path: search.json
  field: all
  content: true

# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
- type: git
  repo: [email protected]:你的/你的.github.io.git   这是仓库地址
  branch: master

```

### 这个主题还需要下载search插件

> npm install hexo-generator-search --save

#### 主题配置请看主题作者提供的文档

### 本地试跑

> hexo g -s

打开浏览器,输入localhost:4000

### 配置github,生成公钥和私钥

+ 打开黑窗口控制台

ssh-keygen -t rsa -C "[email protected]" 输你注册git的邮箱吧

+ 回车回车回车

在windows下查看[c盘->用户->自己的用户名->.ssh]id_rsaid_rsa.pub文件

+ 用记事本打开id_rsa.pub文件,复制内容

+ 登录git,选择Settings

+ 选择SSH and GPG keys

+ 这里需要添加SSH keys,点击new ssh key,粘贴刚才的内容,保存

### 这时就可以把本地代码,推到仓库了,运行命令

> hexo d

这时 http://your.github.io 就可以访问了

### 配置自己的域名

+ themes/jsimple/source 目录下有CNAME文件,打开,写入你的域名  如:lzz1.top

> hexo g -d

获取 ip 地址,并解析

+ ping your.github.io

这里可以得到ip地址

我的是阿里云的域名,所以登录阿里云控制台,找到域名,然后把刚才得到的ip解析到域名下

### 现在就可以愉快的访问了,如果网站没有支持https,打开存代码的git仓库,选择上面的settings,

找到 GitHub Pages  ,勾选Enforce HTTPS,OK

### 发表我的第一篇文章

> hexo new post 文章名

这是会在根目录下的source/_posts目录生成  文章名.md文件,打开,编写内容

> hexo clean

> hexo g -d

重复上述过程,就可以发布自己的文章了

猜你喜欢

转载自blog.csdn.net/qq_29065191/article/details/87937075
今日推荐