Compare commits
	
		
			No commits in common. "1017f3b68cc296162abb7937e260cbab9966c9eb" and "4a462d4123aab248288a252b4da9369d1b4e067a" have entirely different histories.
		
	
	
		
			1017f3b68c
			...
			4a462d4123
		
	
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,3 +1 @@
 | 
			
		||||
__pycache__/
 | 
			
		||||
*.json
 | 
			
		||||
*.html
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,7 @@ class TableCell:
 | 
			
		||||
 | 
			
		||||
    def to_html(self):
 | 
			
		||||
        if self.is_header:
 | 
			
		||||
            html = f"<th title='{self.description}'>{self.name}</th>"
 | 
			
		||||
            html = f"<th title={self.description}>{self.name}</th>"
 | 
			
		||||
        elif not self.name:
 | 
			
		||||
            html = f'<td colspan="{self.colspan}" class="filler"></td>'
 | 
			
		||||
        else:
 | 
			
		||||
 | 
			
		||||
@ -2,31 +2,12 @@ from os import path, walk
 | 
			
		||||
from recipe import Recipe
 | 
			
		||||
from sys import argv
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def write_file_safely(filepath, content):
 | 
			
		||||
    if path.exists(filepath):
 | 
			
		||||
        response = input(f"File '{filepath}' exists. Overwrite? (y/N): ")
 | 
			
		||||
 | 
			
		||||
        if not response or not response.lower().startswith("y"):
 | 
			
		||||
            print(f"Skipping '{filepath}'")
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
    with open(filepath, 'w') as file:
 | 
			
		||||
        file.write(content)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if len(argv) < 2:
 | 
			
		||||
    print(f"Usage: {argv[0]} <recipe directory> [index_header.html]")
 | 
			
		||||
    print(f"Usage: {argv[0]} <recipe directory>")
 | 
			
		||||
    exit(1)
 | 
			
		||||
 | 
			
		||||
recipe_dir = argv[1]
 | 
			
		||||
 | 
			
		||||
if len(argv) > 2:
 | 
			
		||||
    with open(argv[2], 'r') as index_header_file:
 | 
			
		||||
        index_header_html = index_header_file.read()
 | 
			
		||||
else:
 | 
			
		||||
    index_header_html = ""
 | 
			
		||||
 | 
			
		||||
recipe_names = {}
 | 
			
		||||
for dirpath, dirnames, filenames in walk(recipe_dir):
 | 
			
		||||
    for filename in filenames:
 | 
			
		||||
@ -36,7 +17,8 @@ for dirpath, dirnames, filenames in walk(recipe_dir):
 | 
			
		||||
            html = recipe.to_html()
 | 
			
		||||
            html_filepath = path.join(dirpath, f"{filename.rsplit('.', maxsplit=1)[0]}.html")
 | 
			
		||||
 | 
			
		||||
            write_file_safely(html_filepath, html)
 | 
			
		||||
            with open(html_filepath, 'w') as html_file:
 | 
			
		||||
                html_file.write(html)
 | 
			
		||||
 | 
			
		||||
            recipe_names[recipe.name] = path.relpath(html_filepath, start=recipe_dir)
 | 
			
		||||
 | 
			
		||||
@ -50,19 +32,20 @@ index_html = f"""<!DOCTYPE html>
 | 
			
		||||
<body>
 | 
			
		||||
 | 
			
		||||
<header>
 | 
			
		||||
{index_header_html}
 | 
			
		||||
  <h1>Recipes</h1>
 | 
			
		||||
  <p>These are recipes that I'd like to share.</p>
 | 
			
		||||
</header>
 | 
			
		||||
 | 
			
		||||
<section>
 | 
			
		||||
  <h2>Recipes</h2>
 | 
			
		||||
<main>
 | 
			
		||||
  <ul>
 | 
			
		||||
{"\n".join([f"    <li><a href='./{filepath}'>{name}</a></li>" for name, filepath in recipe_names.items()])}
 | 
			
		||||
  </ul>
 | 
			
		||||
</section>
 | 
			
		||||
</main>
 | 
			
		||||
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
write_file_safely(path.join(recipe_dir, "index.html"), index_html)
 | 
			
		||||
with open(path.join(recipe_dir, "index.html"), 'w') as index_file:
 | 
			
		||||
    index_file.write(index_html)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user