boh.config 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export site_name="Your Blog"
  2. boh_pre_build() {
  3. echo "Build index"
  4. boh_blog_build_index
  5. }
  6. boh_post_build() {
  7. rm $source_dir"/index.md"
  8. echo "Moving posts"
  9. boh_blog_move_posts
  10. echo "Coping assets"
  11. if [ -d "$source_dir/_assets" ];then
  12. cp -R "$source_dir/_assets/"* "$destination_dir"
  13. fi
  14. }
  15. boh_blog_move_posts(){
  16. cut_at=`echo "/$destination_dir/posts/" | fold -w 1 | grep / -c`
  17. for file in `ls $destination_dir/posts/*.html`; do
  18. base_date=`echo $file | cut -d / -f $cut_at | cut -d - -f -3`
  19. newpath="$destination_dir/posts/"`date --date="$base_date" "+%Y/%m/%d"`"/"
  20. mkdir -p $newpath
  21. newpath=$newpath`echo $file | rev | cut -d / -f 1 | rev | cut -d - -f 4-`
  22. mv $file $newpath
  23. done
  24. }
  25. boh_blog_build_index(){
  26. cat <<EOF > "$source_dir/index.md"
  27. ---
  28. layout: index
  29. ---
  30. EOF
  31. cut_at=`echo "/$source_dir/posts/" | fold -w 1 | grep / -c`
  32. for file in `ls $source_dir/posts/*.md | sort -r`; do
  33. base_date=`echo $file | cut -d / -f $cut_at- | cut -d - -f -3`
  34. date=`date --date="$base_date" "+ %a %d, %b %Y"`
  35. link="/posts/"`date --date="$base_date" "+%Y/%m/%d"`"/"`echo $file | rev | cut -d / -f 1 | rev | sed 's/.md/.html/' | cut -d - -f 4-`
  36. frontmatter=`boh_parse_frontmatter $file`
  37. eval $frontmatter
  38. echo "<li><span class=\"post-meta\">$date</span><h2><a class =\"post-link\" href=\"$link\">$title</a></h2></li>" >> "$source_dir/index.md"
  39. done
  40. }