Commit 0cc15bcd9a37b318d9087f8f0a7e09fee879a308
Simplify titles again
If the first line is short enough, use it as the title and strip it from the body. If the first list is too long, use a truncated version as the title, and leave the full version in the body.Greg K Nicholson committed on 10/15/2017, 11:52:10 PM
Parent: 36dcea55c65ac21eda7d833b2616ab35da5cc6ad
Files changed
scuttleblog.py | changed |
scuttleblog.py | ||
---|---|---|
@@ -63,23 +63,18 @@ | ||
63 | 63 … | |
64 | 64 … | def define_post_text(text): |
65 | 65 … | text = text.strip() |
66 | 66 … | title = text.splitlines()[0] |
67 | - if re.match('#', text): | |
68 | - # The first line is a heading. | |
69 | - # Use it as the title and strip it from the body. | |
67 … | + maxlength = 140 | |
68 … | + ellipsis = '...' | |
69 … | + if len(title) > maxlength: | |
70 … | + title = title[:maxlength].rsplit(' ', 1)[0] + ellipsis | |
71 … | + body = text | |
72 … | + else: | |
70 | 73 … | if len(text.splitlines()) > 1: |
71 | 74 … | body = ''.join(text.splitlines(keepends=True)[1:]).strip() |
72 | 75 … | else: |
73 | 76 … | body = '' |
74 | - else: | |
75 | - # Truncate the first line and use it as the title. | |
76 | - # Keep everything in the body. | |
77 | - maxlength = 100 | |
78 | - ellipsis = '...' | |
79 | - if len(title) > maxlength: | |
80 | - title = title[:maxlength].rsplit(' ', 1)[0] + ellipsis | |
81 | - body = text | |
82 | 77 … | title = re.sub('^#+\s+', '', title) |
83 | 78 … | return {'title': title, 'body': body} |
84 | 79 … | |
85 | 80 … | def build_post_structure(p): |
Built with git-ssb-web