heox+github pages自建博客(Markdown的另类玩法)

heox+github pages自建博客

heox官网: https://hexo.io/zh-cn/
博客预览:https://suesoft.github.io/

1.自建博客

# 1.全局安装脚手架hexo-cli
npm install hexo-cli -g

# 2.创建 myBlog 项目
hexo init myBlog  # 此处失败的话需要挂梯子,解决1

cd myBlog
npm install
hexo server

解决1
Step1: ping 一下 github.com。如果结果显示100%丢失,那么就是因为无法连接到GitHub导致。

ping github.com

Step2: 从以下网站里面去获取能访问的ip,ping一下看能ping通不
站长工具网站ipaddressip.cn查询网DNS查询在线工具
Step3: 配置本地hosts(hosts在C:\Windows\System32\drivers\etc下)

# 13.114.40.48 是 Step2中获取的能 ping 通的ip地址
13.114.40.48 github.com

Step4: 刷新dns

ipconfig /flushdns

2. heox 发布到github pages上

  • 创建github项目
    登录github -> New -> Repository name(格式: 用户名.github.io) -> Description (填写描述) -> Public -> 创建
    创建成功后,复制项目链接(git@github.com:xxx/xxx.github.io.git)
  • github配置公私钥
    • 获取公私钥
      # 确保安装了git, 打开git bash here,执行以下操作获取公私钥
      ssh-keygen -t rsa -C "xx@xx.com"
      ls ~/.ssh
      cat ~/.ssh/id_rsa.pub  # copy
      
    • github添加ssh-key
      个人中心,找到settings -> SSH and GPG keys -> New SSH key -> 粘贴公钥
      验证是否配置成功: ssh -T git@github.com
      在这里插入图片描述
  • 安装hexo-deployer-git并推送
    网站: https://github.com/hexojs/hexo-deployer-git
    # 安装hexo-deployer-git
    npm install hexo-deployer-git --save
    # hexo generate
    hexo g
    # hexo deploy
    hexo d
    

3.保存源码

  • 更改仓库的默认分支
    可以新建一个source分支来保存源码
    在仓库的主页面,通过Settings -> Branchs,可以看到Default branch的Tab,显示的默认分支是master,可以勾选source,然后update即可将默认分支设置为source
  • 将本地hexo目录与远程仓库关联
    git remote add origin https://github.com/xxx/xxx.github.io.git
    

    注:如果此处关联不成功,可以把source分支下载下来,然后复制里面的.git文件夹到blog下’

  • 推送博客源码
    添加.gitignore文件
    .DS_Store
    Thumbs.db
    db.json
    *.log
    node_modules/
    public/
    .deploy*/
    
    推送
    git add .
    git commit -m 'hexo blog source file'
    git push origin source
    

4.hexo-theme-next主题

配置文件:http://theme-next.iissnan.com/getting-started.html

  • 更改主题hexo-theme-next
    cd myBlog
    # 之后的更新可以通过 git pull 来快速更新
    git clone https://github.com/next-theme/hexo-theme-next themes/next
    
    修改_config.yml文件
    # Extensions
    ## Plugins: https://hexo.io/plugins/
    ## Themes: https://hexo.io/themes/
    theme: next
    
    推送
    hexo clean
    hexo server
    hexo g  # hexo generate
    hexo d  # hexo deploy
    
  • 主题美化
    参考: https://zhuanlan.zhihu.com/p/251383216

5.使用hexo新建、编辑并预览文章

参考: https://zhuanlan.zhihu.com/p/132823826

  • 新建文章
    hexo支持三种布局(layout):post(默认)、draft、page
# 默认使用post布局,然后自动在source\_posts目录生成一个text1.md文件
hexo n text1
# 指定布局
hexo n [layout_name] text1

创建草稿布局并推送到_posts目录下。可以使用 hexo --draft 命令可以查看已有草稿。

hexo n draft draft1
hexo publish draft1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值