跳转至

mkdocs 工作及备份流

为了防止鸽太久忘记工作流了,遂简化流程并备份于此

目录结构

Knight@DESKTOP-31LJ6LM MINGW64 /k/blog_mkdocs
$ tree -L 3 -d
.
|-- articles(草稿)
|   |-- aboutme
|   |-- games101
|   |-- kaggle
|   `-- leetcode
|-- gitee_backup(备份到gitee仓库)
|   `-- github-pages-backup
|       |-- auto_copy_git.sh(自动备份docs/, mkdocs.yml和其他文档)
|       `-- (docs)
`-- mkdocs-site(mkdocs建站以及提交github pages)
    |-- auto_genMkdocsSite_copy_git.sh
    |-- knight02-bit.github.io
    |   |-- other
    |   `-- site
    `-- mkdocs-site
        |-- mkdocs.yml(mkdocs配置)*
        |-- docs(markdown源文档)*
        `-- site(build出来的)

备份md源文件和mkdocs配置到gitee仓库

./auto_copy_git [commit信息,默认为"auto gitee update"]

auto_copy_git.sh

#!/bin/bash

# 设置源目录和目标目录
source_dir="../../articles/aboutme"
docs_dir="../../mkdocs-site/mkdocs-site"
target_dir="."

# 删除目标目录下已存在的文件和目录
if [ -f "$target_dir/index.md" ]; then
  rm "$target_dir/index.md"
  echo "旧的 index.md 已删除"
fi

if [ -d "$target_dir/docs" ]; then
  rm -r "$target_dir/docs"
  echo "旧的 docs 文件夹已删除"
fi

if [ -f "$target_dir/mkdocs.yml" ]; then
  rm "$target_dir/mkdocs.yml"
  echo "旧的 mkdocs.yml 已删除"
fi

# 复制 index.md 文件到目标目录
cp "$source_dir/index.md" "$target_dir"

# 复制 docs 文件夹和 mkdocs.yml 文件到目标目录
cp -r "$docs_dir/docs" "$target_dir/docs"
cp "$docs_dir/mkdocs.yml" "$target_dir"

echo "复制完成"

# 检查输入的 commit 信息,如果为空则使用默认信息
commit_message="$1"
if [ -z "$commit_message" ]; then
  commit_message="auto gitee update"
fi

# 提示用户确认是否继续执行
read -p "是否继续执行 git add . 和 git commit 和 git push?(y/n)" confirm
if [ "$confirm" != "y" ]; then
  echo "已取消操作"
  exit 1
fi

# 执行 git add . 和 git commit
git add .
git commit -m "$commit_message"

# 执行 git push
git push

echo "操作完成"

mkdocs build并提交

./auto_copy_git [commit信息,默认为"auto update"]

auto_genMkdocsSite_copy_git.sh

#!/bin/bash

# 设置默认的 commit 信息
commit_message="$1"
if [ -z "$commit_message" ]; then
  commit_message="auto update"
fi


cd ./mkdocs-site
mkdocs build

# 将 site 文件夹复制到 mkdocs-site/knight02-bit.github.io 目录下
cd ..
target_dir="knight02-bit.github.io"
if [ -d "$target_dir/site" ]; then
  rm -rf "$target_dir/site"
  echo "knight02-bit.github.io/site/ 已删除"
fi
cp -r mkdocs-site/site "$target_dir/"
echo "mkdocs-site/site复制成功"


cd "$target_dir"
git status


read -p "是否继续执行 git add . 和 git commit 和 git push?(y/n)" confirm
if [ "$confirm" != "y" ]; then
  echo "已取消操作"
  exit 1
fi


git add .
git commit -m "$commit_message"
git push

echo "操作完成"

评论