Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Team1157/site
Browse files Browse the repository at this point in the history
  • Loading branch information
Cthulhu42 committed Aug 12, 2024
2 parents 8e7d1f9 + 5965851 commit 8bdfefb
Showing 1 changed file with 31 additions and 47 deletions.
78 changes: 31 additions & 47 deletions ...vuepress/public/photopagehtmlgenthingy.py → photospagegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@

def create_image_viewer():
# Create output directory
output_dir = 'image_viewer'
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
os.makedirs(output_dir)

output_dir = 'src'
if not os.path.exists(output_dir):
os.makedirs(output_dir)

# Create thumbnails directory
thumbnails_dir = os.path.join(output_dir, 'thumbnails')
os.makedirs(thumbnails_dir)
thumbnails_dir = os.path.join(output_dir, '.vuepress', 'public', 'thumbnails')
os.makedirs(thumbnails_dir, exist_ok=True)

# Function to process images in a directory
def process_directory(directory, relative_path=''):
html_content = ''
for item in os.listdir(directory):
item_path = os.path.join(directory, item)
relative_item_path = os.path.join(relative_path, item)

if os.path.isdir(item_path):
# Create corresponding folder in output directory
output_subdir = os.path.join(output_dir, relative_item_path)
os.makedirs(output_subdir, exist_ok=True)

# Add folder to HTML content
html_content += f'<h2>{item}</h2>\n'
html_content += '<div class="image-grid">\n'
Expand All @@ -38,7 +32,7 @@ def process_directory(directory, relative_path=''):
folder_name = creation_date.strftime('%Y-%m-%d')

# Create folder for the image
folder_path = os.path.join(output_dir, relative_path, folder_name)
folder_path = os.path.join(output_dir, '.vuepress', 'public', relative_path, folder_name)
os.makedirs(folder_path, exist_ok=True)

# Copy original image to its folder
Expand All @@ -52,48 +46,38 @@ def process_directory(directory, relative_path=''):

# Add image to HTML content
html_content += f'''
<div class="image-item">
<a href="{os.path.join(relative_path, folder_name, item)}" target="_blank">
<img src="{os.path.join('thumbnails', thumbnail_name)}" alt="{item}">
</a>
<p>{item}<br>{folder_name}</p>
</div>
<div class="image-item">
<a href="/{os.path.join(relative_path, folder_name, item)}" target="_blank">
<img src="/thumbnails/{thumbnail_name}?url" alt="{item}">
</a>
<p>{item}<br>{folder_name}</p>
</div>
'''

return html_content

# Generate HTML content
html_content = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Viewer</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }
.image-item { text-align: center; }
.image-item img { max-width: 100%; height: auto; }
</style>
</head>
<body>
<h1>Image Viewer</h1>
'''
# Generate VuePress page content
page_content = f'''---
author: written by ada t
title: Photos
createTime: {datetime.now().strftime('%Y/%m/%d %H:%M:%S')}
permalink: /photos
---
# Image Viewer
# Process the img directory and its subdirectories
html_content += process_directory('img')
<ClientOnly>
<div class="image-viewer">
{process_directory('src/.vuepress/public/img/')}
</div>
</ClientOnly>
html_content += '''
</body>
</html>
'''
'''

# Write HTML file
with open(os.path.join(output_dir, 'index.html'), 'w') as f:
f.write(html_content)
# Write VuePress page file
with open(os.path.join(output_dir, 'photos.md'), 'w') as f:
f.write(page_content)

print("Image viewer created successfully in the 'image_viewer' directory.")
print("VuePress page created successfully in the 'src/photos.md' file.")

if __name__ == "__main__":
create_image_viewer()

0 comments on commit 8bdfefb

Please sign in to comment.