GitHub+Hexo 搭建教程及踩过的坑

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_37608784/article/details/82882870

出于对自己搭建博客的好奇,这两天就自己亲自操作一遍。网络上各种教程,但很多都是有从业经验的人写的,对于入门的小白就有各种门槛,一出错,不知道怎么解决,网上一顿乱搜,还是没解决,就搁置了,这个是很多小白半路放弃的原因。自己在搭建过程中也有想放弃的想法,后来想想都搞了这么久了,半途而废不好。好了,先扔一个超级基础的教程,我也是根据这个教程一步一步来,少走了很多弯路,但还是碰到一点坑,该篇博客主要是针对这个基础教程,自己实践过程中自己遇到的坑。

最适合新手的 GitHub + Hexo 「大话」博客搭建教程

坑1:Git Shell替换成Git Bash,直接按照教程安装

由于自己之前安装的是Git Desktop,安装的对应的命令终端是Git Shell,虽然bash是一种shell,但自己对于其中的命令运用的不熟悉,两者的关系也没有深入了解,觉得自己用Git Shell和Git Bash 一样,到后面根据教程,自己搞得晕头转向。自己安装的Git Desktop,通过在Git Shell中命令提示Git Desktop版本太低,想要更新Git Desktop,结果显示不能更新。果断抛弃Git Desktop,按照教程来。

坑2:添加SSH Key 到GitHub

教程中写的要找到C盘下面的id_rsa.pub文件,自己一开始一直没有生成成功,严格按照教程中来。

坑3:执行命令 hexo s

在安装完Hexo使用hexo s 启动服务本地预览,先在浏览器中输入localhost:4000,看完了再输入Ctrl+C,自己也是比较糊涂,输入万hexo s,直接Ctrl+C,结果在浏览器中查看localhost:4000,总显示网页无法打开。

坑4:博客更换主题

在你的Hexo根目录下的themes文件夹中是一些你下载的主题,根据教程要修改_config.yml中的主题

## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: hexo-theme-yilia

注意修改的是theme后面的部分,我使用的是hexo-theme-yilia,之前自己修改错了,结果一直没有变过来,默认主题是landscape。

步骤:

  • 打开Git Bash,输入cd D:/Administrator/Hexo/themes (注意前面是我自己安装的Hexo 的根目录,修改为自己的根目录),通过命令切换到themes文件夹内

  • 然后把需要用的主题从github网站上clone下来 git clone https://github.com/litten/hexo-theme-yilia.git,克隆下来后,在themes文件夹中可以看到新的主题文件夹hexo-theme-yilia

  • 输入hexo s查看即可看到新的界面

坑5:自己创建MarkDown博客进行上传

步骤:

  • 打开Git Bash,输入hexo n "文件名",在Hexo根目录下的source->_posts文件夹中即可看到你创建的MarkDown文件

  • 使用Typora打开MarkDown文件进行编辑你的博客,编辑完后Ctrl+S保存

  • Git Bash中输入hexo g生成

  • 输入hexo s 启动本地服务预览

  • 输入hexo d 部署到GitHub博客上,稍等一会即可看到博客发布成功

坑6:自己写新博客往上传的时候一直出错

新创建MarkDown文件的时候打开之后,光标自动在tags:后面,中间没有空格,在自己添加tags的时候或者不写tags的时候,后面一定要加个空格,否则上传的时候报错

坑7:_config.yml文件修改的时候出错

修改该配置文件的时候一定要细心,在它默认的“标头:”后面加内容或者修改内容的时候一定要有一个空格。

下面分享一个我修改的完整的_config.yml文件

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
​
# Site
title: Vampire's Blog  #我的
subtitle: "Sword of Damocles"  #我的
description: "蜗牛,起码也是一头牛"  #我的
author: Vampire  #我的
language: zh-Hans
timezone: Asia/Shanghai  #我的
​
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://Vampires1124.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: true
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: false
  tab_replace:
  
# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
  path: ''
  per_page: 10
  order_by: -date
  
# 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: hexo-theme-yilia  #我的主题
​
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repository: [email protected]:Vampires1124/Vampires1124.github.io.git  #我的
  branch: master
​

上面标注“#我的”就是我修改过的地方,其他地方没有变动。

以上就是我实操过程中遇到的一些问题,总结一下。

猜你喜欢

转载自blog.csdn.net/weixin_37608784/article/details/82882870