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

来源:互联网 发布:loveless world知乎 编辑:程序博客网 时间:2024/06/05 20:57

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

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

准备

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

配置Node.js环境

  • 下载node.js安装文件 windows 32位 windows 64位

保持默认设置即可,一路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 #时区# URLurl: http://yoururl.com   #用于绑定域名, 其他的不需要配置root: /#permalink: :year/:month/:day/:title/permalink: posts/title.htmlpermalink_defaults:# Directory #目录source_dir: source #源文件public_dir: public #生成的网页文件tag_dir: tags #标签archive_dir: archives #归档category_dir: categories #分类code_dir: downloads/codei18n_dir: :lang #国际化skip_render:# Writing #写作new_post_name: :title.md #新文章标题default_layout: post #默认模板(post page photo draft)titlecase: false #标题转换成大写external_link: true #新标签页里打开连接filename_case: 0render_drafts: falsepost_asset_folder: falserelative_link: falsefuture: truehighlight: #语法高亮  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-DDtime_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(你的域名)进行访问了!

文章参考

  • 史上最详细的Hexo博客搭建图文教程
原创粉丝点击