A scripts for managing hugo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BLOGREPO=$BLOGPATH/.repo/Blog | |
BLOG_POSTS=$BLOGREPO/content/posts | |
BLOG_IMAGES=$BLOGPATH/.repo/blog-images | |
NOWPATH=`pwd` | |
log() { | |
cd $BLOGREPO | |
git lg | |
cd $NOWPATH | |
} | |
push() { | |
cd $1 | |
git add . | |
git commit -m "Update: $(date +%Y-%m-%d)" | |
git push | |
cd $NOWPATH | |
} | |
pull() { | |
cd $1 | |
git pull | |
cd $NOWPATH | |
} | |
server() { | |
cd $BLOGREPO | |
hugo server | |
cd $NOWPATH | |
} | |
new() { | |
cd $BLOGREPO | |
num=0 | |
while true; do | |
file_num=`echo ${num}|awk '{printf("%03d\n", $0)}'` | |
file="$BLOG_POSTS/${file_num}.md" | |
if test -f $file; then | |
let num+=1 | |
else | |
hugo new posts/${file_num}.md | |
mkdir $BLOG_IMAGES/r/${file_num} | |
break | |
fi | |
done | |
cd $NOWPATH | |
} | |
if [ ! -z "$1" ]; then | |
if [ "$1" == "repo" ]; then cd $BLOGREPO | |
elif [ "$1" == "log" ]; then log | |
elif [ "$1" == "lg" ]; then log | |
elif [ "$1" == "server" ]; then server | |
elif [ "$1" == "new" ]; then new | |
elif [ "$1" == "push" ]; then | |
echo "===Push Posts===" | |
push $BLOGREPO | |
echo "" | |
echo "===Push Images===" | |
push $BLOG_IMAGES | |
elif [ "$1" == "pull" ]; then | |
echo "===Pull Posts===" | |
pull $BLOGREPO | |
echo "" | |
echo "===Pull Images===" | |
pull $BLOG_IMAGES | |
elif [ "$1" == "edit" ]; then | |
if [ "$2" == "tools" ]; then | |
vim $BASH_SOURCE | |
fi | |
fi | |
else | |
cd $BLOGPATH | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$BLOGREPO="$env:BLOGPATH\.repo\Blog" | |
$BLOGPOSTS="$BLOGREPO\content\posts" | |
$BLOGIMAGES="$env:BLOGPATH\.repo\blog-images" | |
$LOG='git lg' | |
$PUSH='git add .; git commit -m "Update: $(Get-Date -Format yyyy-M-d)"; git push' | |
$PULL='git pull' | |
$SERVER='hugo server' | |
function run { | |
param ( | |
$path=$BLOGREPO, | |
$cmd | |
) | |
try { | |
Push-Location -Path $path | |
Invoke-Expression $cmd | |
} | |
finally { | |
Pop-Location | |
} | |
} | |
function new { | |
function file_num { | |
param ( | |
$num | |
) | |
$file_num="{0:d3}" -f $num | |
if (Test-Path "$BLOGPOSTS\$file_num.md") { | |
$num += 1 | |
file_num $num | |
} else { | |
return $file_num | |
} | |
} | |
$file_num=file_num 0 | |
Invoke-Expression "hugo new posts/$file_num.md" | |
Write-Host $(New-Item -ItemType Directory -Force -Path "$BLOGIMAGES/r/$file_num")" created" | |
} | |
if ($args -eq "repo") { | |
Set-Location $BLOGREPO | |
} elseif ($args -eq "log") { | |
run $BLOGREPO $LOG | |
} elseif ($args -eq "lg") { | |
run $BLOGREPO $LOG | |
} elseif ($args -eq "server") { | |
run $BLOGREPO $SERVER | |
} elseif ($args -eq "new") { | |
run $BLOGREPO new | |
} elseif ($args -eq "push") { | |
Write-Host "===Push Posts===" | |
run $BLOGREPO $PUSH | |
Write-Host "===Push Images===" | |
run $BLOGIMAGES $PUSH | |
} elseif ($args -eq "pull") { | |
Write-Host "===Pull Posts===" | |
run $BLOGREPO $PULL | |
Write-Host "===Pull Images===" | |
run $BLOGIMAGES $PULL | |
} else { | |
Set-Location $env:BLOGPATH | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment