Commit 3e4cd5cd53d0b8d6f4964b7960386bb0b6763182
Always use only the first line in the post title
Including when the title is not a heading.Greg K Nicholson committed on 10/15/2017, 5:04:05 PM
Parent: a1d3ac16dfab4dabf37b36f6c2ffbae74f80753b
Files changed
scuttleblog.py | changed |
scuttleblog.py | |||
---|---|---|---|
@@ -49,19 +49,19 @@ | |||
49 | 49 … | return user_posts | |
50 | 50 … | ||
51 | 51 … | def define_post_text(text): | |
52 | 52 … | text = text.strip() | |
53 … | + title = text.splitlines()[0] | ||
53 | 54 … | if re.match('#', text): | |
54 | 55 … | # The first line is a heading. Use it as the title and strip it from the body. | |
55 | - title = text.splitlines()[0] | ||
56 | 56 … | body = ''.join(text.splitlines(keepends=True)[1:]).strip() \ | |
57 | 57 … | if len(text.splitlines()) > 1 \ | |
58 | 58 … | else '' | |
59 | 59 … | else: | |
60 | 60 … | # Truncate the first line and use it as the title. Keep everything in the body. | |
61 | 61 … | maxlength = 100 | |
62 | 62 … | ellipsis = '...' | |
63 | - title = text if len(text) <= maxlength else text[:maxlength].rsplit(' ', 1)[0] + ellipsis | ||
63 … | + title = title if len(title) <= maxlength else title[:maxlength].rsplit(' ', 1)[0] + ellipsis | ||
64 | 64 … | body = text | |
65 | 65 … | title = re.sub('^#+\s+', '', title) | |
66 | 66 … | # FIXME: This doesn't gracefully handle markdown near the start of a post. | |
67 | 67 … | return {'title': title, 'body': body} |
Built with git-ssb-web