compose.sh 996 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. # pickmy.org post composer
  3. # by: Jay/nq4t/@music_onhold
  4. # usage: ./compose.sh [category] [title]
  5. # example: /compose.sh blog MY AWESOME POST TITLE NO YOU DON'T NEED TO ENCLOSE IT!
  6. # run in the root of your site files/repository
  7. # assumes categories are directories in root
  8. # Variables and category argument
  9. category=$1
  10. pd=$(date +'%Y-%m-%d')
  11. pt=$(date +'%T')
  12. file=blog$$.md
  13. # Ditch the category argument
  14. shift 1
  15. # Read everything else as title.
  16. title=$@
  17. t=${title,,}
  18. t=${t// /-}
  19. fd=$(date +'%Y/%^b/%d')
  20. # Let's write the front matter to our temp file.
  21. printf -- "---\ntitle: $title\nlayout: post\ndate: $pd $pt\npermalink: /$category/$fd-$t.php\nexcerpt_separator: <!--more-->\n---\n\n" >> $file
  22. # Write the post in whatever editor you want.
  23. nano + $file
  24. # Move the file to category/_posts replacing spaces with hyphen
  25. mv $file $category/_posts/$pd-${t// /-}.md
  26. # Display some output to verify it's done.
  27. printf "\nPost $title created in $category: $category/_posts/$pd-$t.md\n\n"