Command line client for Write.as https://write.as/apps/cli
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
407 B

  1. package posts
  2. import (
  3. "strings"
  4. )
  5. func ExtractTitle(content string) (title string, body string) {
  6. if hashIndex := strings.Index(content, "# "); hashIndex == 0 {
  7. eol := strings.IndexRune(content, '\n')
  8. // First line should start with # and end with \n
  9. if eol != -1 {
  10. body = strings.TrimLeft(content[eol:], " \t\n\r")
  11. title = content[len("# "):eol]
  12. return
  13. }
  14. }
  15. body = content
  16. return
  17. }