MCPcopy Index your code
hub / github.com/chinesehuazhou/python-weekly / _strip_frontmatter_for_github

Function _strip_frontmatter_for_github

resources/weekly_workflow.py:622–649  ·  view source on GitHub ↗

去掉 Astro 专用 frontmatter 字段,只保留 title 和 pubDate。

(content)

Source from the content-addressed store, hash-verified

620
621
622def _strip_frontmatter_for_github(content):
623 """去掉 Astro 专用 frontmatter 字段,只保留 title 和 pubDate。"""
624 lines = content.split('\n')
625 if not lines or lines[0].strip() != '---':
626 return content
627
628 # 找到 frontmatter 结束位置
629 end_idx = None
630 for i in range(1, len(lines)):
631 if lines[i].strip() == '---':
632 end_idx = i
633 break
634 if end_idx is None:
635 return content
636
637 fm_lines = lines[1:end_idx]
638 body_lines = lines[end_idx + 1:]
639
640 # 只保留 title 和 pubDate
641 keep_fields = {'title', 'pubDate'}
642 new_fm = []
643 for line in fm_lines:
644 key = line.split(':')[0].strip() if ':' in line else ''
645 if key in keep_fields:
646 new_fm.append(line)
647
648 result = ['---'] + new_fm + ['---', ''] + body_lines
649 return '\n'.join(result)
650
651
652def disclose_full_issue(weekly_no):

Callers 1

disclose_full_issueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected