Loading

博客搭建

vscode+hexo+github+action+pages+cdn+gitee+博客园部署

hexo安装可以参考官网,首先要保证本地能运行
_config.yml这部分我要设置两个仓库

deploy:
  type: git
  repository: 
    github: git@github.com:lxy417/lxy417.github.io.git
    gitee: git@gitee.com:hslxy/blog.git
  branch: master

这里我们用了github pages和gitee pages,然后用github action自动部署

把hexo的整个传到github上,而不是仅仅public那些

在github和gitee配置公钥

然后在.github\workflows\deploy.yml下写自动部署的脚本

# This is a basic workflow to help you get started with Actions

name: Hexo-deploy

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "master" branch
  push:
    branches: [ "master" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-18.04
    if: github.event.repository.owner.id == github.event.sender.id


    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - name: Checkout source
        uses: actions/checkout@v2
        with:
          ref: master

      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '12'

      - name: Setup Hexo
        env:
          ACTION_DEPLOY_KEY: ${{ secrets.HEXO }}
        run: |
          mkdir -p ~/.ssh/
          echo "$ACTION_DEPLOY_KEY" > ~/.ssh/id_rsa
          chmod 700 ~/.ssh
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan github.com >> ~/.ssh/known_hosts
          ssh-keyscan gitee.com >> ~/.ssh/known_hosts
          git config --global user.email "你的邮箱"
          git config --global user.name "你的名字"
          npm install hexo-cli -g
          npm install

      - name: Deploy
        run: |
          hexo clean
          hexo deploy

${{ secrets.HEXO }}要改为你自己私钥名称
这个会自动编译hexo并部署到github和gitee上
然后又自动执行pages部署,这时候就可以看到博客了。

20220820142756

配合vscode

装cnblogs的插件
20220821173231
这个插件能自动发布内容到博客园

装PicGo插件,用来搭建图床,我用的七牛云和又拍云,注意PicGo的上传图片的快捷键和博客园的快捷键有冲突,所以我把PicGo的快捷键改为ctrl+win+u,博客园的快捷键默认ctrl+alt+u

由于hexo的md有一些信息需要用hexo new命令生成,这里我们使用koroFileHeader插件
20220821173910
然后配置md自动生成头,比较重要的几个配置在这

// 头部注释
"fileheader.customMade": {
    // 头部注释默认字段
    "Author": "meteor",
    "Date": "Do not edit", // 设置后默认设置文件生成时间
    "LastEditTime": "Do not edit", // 设置后,保存文件更改默认更新最后编辑时间
    "FilePath": "only file name without ext", // 设置后,默认生成文件相对于项目的路径
    // "custom_string_obkoro1": "可以输入预定的版权声明、个性签名、空行等"
    "tags": "",
},
"md": {
    "head": "---",
    "middle": "",
    "end": "---",
}

cdn我用的七牛云和又拍云,加速不同内容

posted @ 2022-08-20 13:08  要努力哇  阅读(54)  评论(0)    收藏  举报