1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #!/bin/bash # 设置Hexo博客目录 hexo_dir="/root/blog"
# 设置Markdown文件目录 markdown_dir="/root/Markdown"
for file in "$markdown_dir"/*.md; do # 检查文件是否存在 if [ -f "$file" ]; then # 获取文件名(不包含扩展名) filename=$(basename -- "$file" .md)
# 检查目标目录是否已存在同名文件 if [ -f "$hexo_dir/source/_posts/$filename.md" ]; then echo "Skipping $filename.md - File already exists in destination directory." # 删除原始Markdown文件 rm "$file" echo "Deleted $filename.md from $markdown_dir/" else # 获取当前时间并格式化 current_time=$(date "+%Y-%m-%d %H:%M:%S")
# 添加front matter到文件中,包括当前时间 echo -e "---\ntitle: $filename\ndate: $current_time\n---" | cat - "$file" > temp && mv temp "$file" # 将Markdown文件复制到Hexo博客目录 mv "$file" "$hexo_dir/source/_posts/" echo "Moved $filename.md to $hexo_dir/source/_posts/" fi fi done
cd "$hexo_dir"
hexo generate
|