import re

from common import file

def get_excerpt(filename):
    content = file.read_file(filename)
    excerpt = content.replace('<p>', '').replace('</p>', '')
    excerpt = re.sub('!\[\]\((.*?)\)', '', excerpt)
    excerpt = re.sub('(\[.+\]\([^\)]+\))', '', excerpt)
    excerpt = re.sub('<.+>', '', excerpt)
    excerpt_list = excerpt.split("\n")
    excerpt_output = ""
    for item in excerpt_list:
        excerpt_output = excerpt_output + item.lstrip("#*-'")
    if len(excerpt_output) > 140:
        excerpt = excerpt_output[:140]
    return excerpt
@@ -507,37 +507,434 @@
     
-excerpt = excerpt_output%5B:140
+split_index = 140%0A        excerpt_output_replace = excerpt_output.replace(%22.%22, %22%E3%80%82%22).replace(%22,%22, %22%EF%BC%8C%22)%0A        dot_index = excerpt_output_replace.find(%22%E3%80%82%22, 140, 240)%0A        comma_index = excerpt_output_replace.find(%22%EF%BC%8C%22, 140, 240)%0A        if dot_index != -1:%0A            split_index = dot_index%0A        if comma_index != -1 and dot_index == 1:%0A            split_index = comma_index%0A        excerpt = excerpt_output%5B:split_index
 %5D%0A  

设置100字的空余，找到最近的逗号或句号