如何从零开始搭建个人博客(pages+hexo)

1 篇文章 0 订阅

原文地址:https://www.vita2333.win/skills/how-to-create-a-blog/

利用github/coding net的pages服务,配合Hexo模板,可以快速地搭建一个免费、静态的个人博客。

准备

在安装hexo之前,需要完成以下环境配置:

配置Node.js环境

保持默认设置即可,一路Next,安装很快就结束了。

配置Git环境

  • 下载git安装文件 windows 64
  • win+R输入cmd进入控制台,进行git的全局配置,输入:
git config --global user.name "你的名字"
git config --global user.email "你的邮箱"

注册github账号(coding net账号)

因为墙的问题,百度无法收录github下的pages,所以建议在githubcoding net上同时部署你的博客,这样国外走github,国内走coding,两不误。

完成注册后登陆你的账号,点击页面右上角的加号,选择New repository:

在Repository name下填写你的名字.github.io,如图所示:

正确创建之后,你将会看到如下界面:

接下来再开启pages服务:点击界面右侧的Settings,然后GitHub Pages

点击Automatic page generator,Github将会自动替你创建出一个gh-pages的页面。 到此准备阶段完成!

安装和配置Hexo

创建你要安装hexo的文件夹,比如在E盘创建Hexo文件夹作为安装根目录。
进入控制台,依次输入以下代码来进入到你刚才创建的根目录:

输入以下代码来安装hexo:

npm install hexo-cli -g

安装好hexo以后,进行初始化:

hexo init

你会发现你的目录下多出了几个文件,然后输入:

npm install

npm将会自动安装你需要的组件,只需要等待npm操作即可。

首次体验hexo

在命令行中,输入:

hexo g

然后:

hexo s

在浏览器中打开http://localhost:4000/,你将会看到:

好了,hexo已经成功安装了!下一步,将本地的hexo部署在github的pages服务上。

配置github pages

打开根目录下的_config.yml进行配置:

# Site #站点信息
title: blog Name #标题
subtitle: Subtitle #副标题
description: my blog desc #描述
author: me #作者
language: zh-CN #语言
timezone: Asia/Shanghai #时区

# URL
url: http://yoururl.com   #用于绑定域名, 其他的不需要配置
root: /
#permalink: :year/:month/:day/:title/
permalink: posts/title.html
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 #新文章标题
default_layout: post #默认模板(post page photo draft)
titlecase: false #标题转换成大写
external_link: true #新标签页里打开连接
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:

# Category & Tag #分类和标签
default_category: uncategorized #默认分类
category_map:
tag_map:

# Date / Time format #日期时间格式
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination #分页
per_page: 10 #每页文章数, 设置成 0 禁用分页
pagination_dir: page

# Extensions #插件和主题
## 插件: http://hexo.io/plugins/
## 主题: http://hexo.io/themes/
theme: next

# Deployment #部署, 同时发布在 GitHub 和 GitCafe 上面
deploy:
  type: git
  repo: 
    github: git@github.com:vita1222/vita2333.github.io.git,master
    coding: git@git.coding.net:vita2333/vita2333.coding.me.git,master

# Disqus #Disqus评论系统
disqus_shortname: 

完成Deploynebt部分的配置,你的网站就可以通过http://yoururl.com(你的域名)进行访问了!

文章参考

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值