Skip to content

Commit 8647ab0

Browse files
committed
fix paths in posts.json
1 parent b643ac1 commit 8647ab0

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/substack2markdown/substack_scraper.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ def get_all_post_urls(self) -> List[str]:
149149

150150
def get_all_post_urls_offline(self) -> List[str]:
151151
# Read JSON data
152-
# NOTE this assumes that $post_slug is not used in args.output_directory_format
153-
# because post_slug is undefined at this point
154152
output_directory = self.output_directory_template.substitute(self.format_vars)
155153
self.format_vars["output_directory"] = output_directory
156154
posts_json_path = os.path.join(
@@ -540,6 +538,9 @@ async def scrape_posts(self, num_posts_to_scrape: int = 0) -> None:
540538
"""
541539
Iterates over all posts and saves them as markdown and html files
542540
"""
541+
output_directory = self.output_directory_template.substitute(self.format_vars)
542+
self.format_vars["output_directory"] = output_directory
543+
543544
posts_data = []
544545
count = 0
545546
total = num_posts_to_scrape if num_posts_to_scrape != 0 else len(self.post_urls)
@@ -548,9 +549,6 @@ async def scrape_posts(self, num_posts_to_scrape: int = 0) -> None:
548549
post_slug = url.split("/")[-1]
549550
self.format_vars["post_slug"] = post_slug
550551

551-
output_directory = self.output_directory_template.substitute(self.format_vars)
552-
self.format_vars["output_directory"] = output_directory
553-
554552
md_filepath = os.path.join(
555553
output_directory,
556554
self.md_path_template.substitute(self.format_vars)
@@ -654,8 +652,8 @@ async def scrape_posts(self, num_posts_to_scrape: int = 0) -> None:
654652
"like_count": like_count,
655653
"comment_count": comments_num,
656654
"date": date,
657-
"file_link": md_filepath,
658-
"html_link": html_filepath
655+
"file_link": os.path.relpath(md_filepath, output_directory),
656+
"html_link": os.path.relpath(html_filepath, output_directory),
659657
})
660658
else:
661659
print(f"File already exists: {md_filepath}")

0 commit comments

Comments
 (0)