Skip to content

Instantly share code, notes, and snippets.

@finelagusaz
Last active December 31, 2018 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save finelagusaz/10449910 to your computer and use it in GitHub Desktop.
Save finelagusaz/10449910 to your computer and use it in GitHub Desktop.
カレントディレクトリ以下にあるMarkdown形式のファイルをPandocでHTMLに変換するためのシェルスクリプトです。
# Markdown形式のファイルパスを取得し配列に格納する
mdpath=($(find ./ -name "*.md"))
# カウンタ
cnt=0
# 配列でループ
for mdfile in ${mdpath[@]}; do
# 拡張子をhtmlに変換する
htfile=$(echo $mdfile | sed -e "s|\.md|.html|")
# ファイルの更新日時を比較する
if [ $mdfile -nt $htfile ]; then
# mdが新しければPandocでHTML生成
pandoc -i $mdfile -o $htfile
# 変換したファイル数をカウント
cnt=`expr $cnt+1`
fi
done
# 結果表示
echo "markdown to html: " $cnt "files"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment