Closed jerrylususu closed 1 week ago
看起来data.json里没问题
{
"month": "202409",
"title": "NotebookLM’s automatically generated podcasts are surprisingly effective",
"url": "https://simonwillison.net/2024/Sep/29/notebooklm-audio-overview/",
"timestamp": 1727703601
},
你遇到的问题源于代码在生成 README.md
中的链接路径时使用了当前月份 (CURRENT_MONTH
),而实际文件是根据书签的 month
字段保存到相应的月份文件夹中。这导致链接指向的月份与实际文件所在的月份不一致,从而无法打开链接。
具体来说,build_summary_readme_md
函数在生成链接时调用了 get_summary_file_path
,而 get_summary_file_path
使用的是全局变量 CURRENT_MONTH
:
def get_summary_file_path(title: str, timestamp: int, in_readme_md: bool = False) -> Path:
...
root: Path = Path(BOOKMARK_SUMMARY_REPO_NAME, CURRENT_MONTH)
...
但是,书签的 month
字段可能与 CURRENT_MONTH
不同。例如,data.json
中的 month
是 "202409"
,而代码运行时的 CURRENT_MONTH
是 "202410"
,这导致生成的链接指向错误的月份文件夹。
为了修复这个问题,需要确保在生成链接时使用书签的实际月份,而不是当前月份。具体步骤如下:
修改 get_summary_file_path
函数,使其接受 month
作为参数,而不是依赖全局变量 CURRENT_MONTH
。
在 build_summary_readme_md
函数中传递书签的 month
给 get_summary_file_path
。
以下是详细的修改步骤和代码:
get_summary_file_path
函数首先,修改 get_summary_file_path
函数,使其接受 month
参数:
def get_summary_file_path(title: str, timestamp: int, month: Optional[str] = None, in_readme_md: bool = False) -> Path:
date_str = datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d')
summary_filename: str = f"{date_str}-{slugify(title)}.md"
if in_readme_md:
if month is None:
raise ValueError("Month must be provided when in_readme_md is True")
root: Path = Path(".", month)
summary_filename = f"{date_str}-{quote(slugify(title))}.md"
else:
if month is None:
month = CURRENT_MONTH
root: Path = Path(BOOKMARK_SUMMARY_REPO_NAME, month)
summary_path: Path = Path(root, summary_filename)
return summary_path
build_summary_readme_md
函数接下来,在 build_summary_readme_md
函数中传递书签的 month
给 get_summary_file_path
:
def build_summary_readme_md(summarized_bookmarks: List[SummarizedBookmark]) -> str:
initial_prefix: str = """# Bookmark Summary
读取 bookmark-collection 中的书签,使用 jina reader 获取文本内容,然后使用 LLM 总结文本。详细实现请参见 process_changes.py。需要和 bookmark-collection 中的 Github Action 一起使用。
## Summarized Bookmarks
"""
summary_list: str = ""
sorted_summarized_bookmarks = sorted(summarized_bookmarks, key=lambda bookmark: bookmark.timestamp, reverse=True)
for bookmark in sorted_summarized_bookmarks:
summary_file_path = get_summary_file_path(
title=bookmark.title,
timestamp=bookmark.timestamp,
month=bookmark.month, # 传递书签的月份
in_readme_md=True
)
summary_list += f"- ({datetime.fromtimestamp(bookmark.timestamp).strftime('%Y-%m-%d')}) [{bookmark.title}]({summary_file_path})\n"
return initial_prefix + summary_list
在 process_bookmark_file
函数中,当创建新的 SummarizedBookmark
时,确保 month
字段正确设置为当前月份:
with open(f'{BOOKMARK_SUMMARY_REPO_NAME}/README.md', 'w', encoding='utf-8') as f:
f.write(build_summary_readme_md(summarized_bookmarks))
确保在新书签添加时,month
字段使用的是书签的实际月份,而不是 CURRENT_MONTH
。
以下是修正后的关键代码片段,供参考:
# 修改后的 get_summary_file_path
def get_summary_file_path(title: str, timestamp: int, month: Optional[str] = None, in_readme_md: bool = False) -> Path:
date_str = datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d')
summary_filename: str = f"{date_str}-{slugify(title)}.md"
if in_readme_md:
if month is None:
raise ValueError("Month must be provided when in_readme_md is True")
root: Path = Path(".", month)
summary_filename = f"{date_str}-{quote(slugify(title))}.md"
else:
if month is None:
month = CURRENT_MONTH
root: Path = Path(BOOKMARK_SUMMARY_REPO_NAME, month)
summary_path: Path = Path(root, summary_filename)
return summary_path
# 修改后的 build_summary_readme_md
def build_summary_readme_md(summarized_bookmarks: List[SummarizedBookmark]) -> str:
initial_prefix: str = """# Bookmark Summary
读取 bookmark-collection 中的书签,使用 jina reader 获取文本内容,然后使用 LLM 总结文本。详细实现请参见 process_changes.py。需要和 bookmark-collection 中的 Github Action 一起使用。
## Summarized Bookmarks
"""
summary_list: str = ""
sorted_summarized_bookmarks = sorted(summarized_bookmarks, key=lambda bookmark: bookmark.timestamp, reverse=True)
for bookmark in sorted_summarized_bookmarks:
summary_file_path = get_summary_file_path(
title=bookmark.title,
timestamp=bookmark.timestamp,
month=bookmark.month, # 传递书签的月份
in_readme_md=True
)
summary_list += f"- ({datetime.fromtimestamp(bookmark.timestamp).strftime('%Y-%m-%d')}) [{bookmark.title}]({summary_file_path})\n"
return initial_prefix + summary_list
通过以上修改,README.md
中生成的链接路径将基于书签的实际月份 (bookmark.month
) 而不是当前月份 (CURRENT_MONTH
),确保链接指向正确的文件夹,从而解决了无法打开链接的问题。
如果在实现过程中有任何疑问或进一步的问题,请随时告知!
fixed in 229f5dea6318c6c04b913507bee51154e6b24509
(2024-09-30) NotebookLM’s automatically generated podcasts are surprisingly effective