用Hexo+Gitee搭建个人博客(基于Windows系统)

Hexo+Gitee搭建个人博客


一、安装Git


二、安装 node.js


三、安装hexo

  1. 在cmd命令窗口用npm安装淘宝镜像源cnpm(国内网速问题)。

    npm install -g cnpm --registry=https://registry.npm.taobao.org
    
  2. 用cnpm安装Hexo

    cnpm install -g hexo-cli
    
  3. 验证安装是否成功。

    hexo -v
    
  4. 在你安装的电脑磁盘的目录下创建一个任意名字的文件夹,可手动创建或在cmd命令窗口创建(比如我安装在D盘的blog文件夹中)

    mkdir blog
    
  5. 进入blog文件夹,初始化hexo。

    hexo init
    
  6. 打开hexo。

    hexo s
    

    进入localhost:4000访问博客。


四、用hexo写博客

  1. 在cmd命令窗口中创建一篇新的博客。

    hexo n "我的第一篇博客"
    
  2. 在你安装的博客目录下找到新创建的博客,用任一Markdown编辑软件编辑博客内容。

    (在D:\blog\source_posts 目录下打开“我的第一篇博客.md”进行编辑)

  3. 编辑完保存文件,在cmd窗口执行以下命令。

    hexo clean 				# 清除记录
    hexo g					# 生成静态网页
    hexo s					# 启动hexo
    

    然后打开localhost:4000 就可以在本地服务器看到你新编辑的博客。


五、将博客部署到gitee上

Gitee是一个静态网页托管服务器,托管后就可在任意网络设备上访问你的博客了。

  1. 进入Gitee官网,注册账号。

  2. 在个人主页中找到新建仓库,建立一个新的仓库。

  3. 通过cmd窗口安装一个hexo插件。

    cnpm install hexo-deployer-git --save
    
  4. 在cmd窗口或直接在blog文件夹中用记事本打开hexo的配置文件_config.yml

    用cmd打开:

    notepad _config.yml
    

    在文件夹中打开:

    D:\blog_config.yml

  5. 修改文件中的部分参数。

    deploy:
    	type: git
    	repo: https://gitee.com/lv_neng_dong/study.git  	#仓库的地址
      	branch: master
    
  6. 上传文件到gitee仓库。

    git config --global user.email "注册时的邮箱"
    git config --global user.name "注册时的用户名"
    hexo d 			# 上传到远端仓库
    
  7. 上传之后在Gitee仓库会看到搓出来一些文件。

    在Gitee仓库中找到右上方的“服务0”,打开”Gitee Pages”服务,点击左下方的“更新。

    之后会在中间部分刷新出一个网址,点击即可访问你的博客。

    (每次更新博客后都需要重新“更新”!!!)



六、常见的问题

  • 将本地博客部署到Gitee远端时,无法加载主体样式。

    在cmd窗口或直接在blog文件夹中用记事本打开hexo的配置文件_config.yml

    修改其中的部分参数。

    修改前:
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://yoursite.com
    root: /					# 改为  /你的仓库名/
    
    修改后:
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://yoursite.com
    root: /study/
    
  • 只能显示安装当天的博客,第二天更新的博客无法显示。

    同上修改部分参数

    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://yoursite.com		# 修改url为你的Gitee地址。
    root: /study/
    
    修改后
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://lv_neng_dong.gitee.io
    root: /study/
    

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值