Skip to content

feat: Make static_site_generator.py a standalone script #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2025

Conversation

rbarker-dev
Copy link
Contributor

Description:

Enables better testing at CLI
Enables re-runs of html generation given a provided source json file like output.projects.json

Related Issue(s):

closes #80

**Description**:

Enables better testing at CLI
Enables re-runs of html generation given a provided source json file
like `output.projects.json`

**Related Issue(s)**:

closes #80

Signed-off-by: Roger Barker <roger.barker@swirldslabs.com>
@rbarker-dev rbarker-dev added the feature New Feature label May 2, 2025
@rbarker-dev rbarker-dev self-assigned this May 2, 2025
@rbarker-dev rbarker-dev linked an issue May 2, 2025 that may be closed by this pull request
@github-actions github-actions bot added the feat label May 2, 2025
Signed-off-by: Roger Barker <roger.barker@swirldslabs.com>
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors static_site_generator.py to function as a standalone CLI script, enhancing its testing and rerun capabilities.

  • Added CLI support with a main() function capturing JSON file input and handling file existence checks.
  • Updated the generate_site() function with a return type annotation.
Comments suppressed due to low confidence (1)

src/static_site_generator.py:44

  • [nitpick] Consider using the output_file parameter in the log message to ensure the log reflects the actual file path used when a different output file is provided.
logging.info("Static Site Generated @ ./_site/index.html")

Comment on lines +47 to +48
ss_gen = StaticSiteGenerator()
data_file:str = input("Enter the path to the json file with data: ")
Copy link
Preview

Copilot AI May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using argparse for handling command line arguments to improve user experience and provide more flexibility than interactive input.

Suggested change
ss_gen = StaticSiteGenerator()
data_file:str = input("Enter the path to the json file with data: ")
import argparse
parser = argparse.ArgumentParser(description="Generate a static site from a JSON data file.")
parser.add_argument("--data-file", required=True, help="Path to the JSON file with data.")
args = parser.parse_args()
ss_gen = StaticSiteGenerator()
data_file = args.data_file

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont want to

Comment on lines +54 to +55
with open(data_file, 'r') as f:
data = json.load(f)
Copy link
Preview

Copilot AI May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] It may be beneficial to wrap the JSON file loading in a try-except block to gracefully handle JSON decoding errors.

Suggested change
with open(data_file, 'r') as f:
data = json.load(f)
try:
with open(data_file, 'r') as f:
data = json.load(f)
except json.JSONDecodeError as e:
print(f"[bold red]Error: Failed to decode JSON from file {data_file}. Please check the file format.[/bold red]")
return

Copilot uses AI. Check for mistakes.

Co-authored-by: Andrew Brandt <andrew.brandt@hashgraph.com>
Signed-off-by: Roger Barker <roger.barker@swirldslabs.com>
@rbarker-dev rbarker-dev merged commit 2e36b60 into main May 2, 2025
5 checks passed
@rbarker-dev rbarker-dev deleted the 80-add-main-method-to-static_site-generator branch May 2, 2025 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add main method to static_site generator
2 participants