commit b358202a49caac3e7fd2e4ea326be7fbc4b13388 Author: Federico Poni Date: Tue Jun 4 00:06:05 2024 +0200 first diff --git a/app.py b/app.py new file mode 100644 index 0000000..24007aa --- /dev/null +++ b/app.py @@ -0,0 +1,149 @@ +import os +import json +import markdown +from wand.image import Image +import subprocess +from datetime import datetime + +# Directory paths +garden_path = 'website/contents/garden/' +misc_path = 'website/contents/misc/' +compressed_path = os.path.join(garden_path, 'compressed') + +# Ensure the compressed folder exists +os.makedirs(compressed_path, exist_ok=True) + +# Load configuration settings from config.json +with open('config.json', 'r', encoding='utf-8') as config_file: + config = json.load(config_file) + +website_title = config['name_website'] +website_description = config['description'] +background_color = config['background_color'] +text_color = config['text_color'] +background_color_header_footer = config['background_color_header_footer'] +text_color_header_footer = config['text_color_header_footer'] + +# Helper function to read file content +def read_file(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + return file.read() + +# Function to compress images using ImageMagick +def compress_image(input_path, output_path): + with Image(filename=input_path) as img: + img.compression_quality = 50 # Adjust quality as needed + # img.dither() + img.save(filename=output_path) + +# Function to compress videos using ffmpeg +def compress_video(input_path, output_path): + subprocess.run(['ffmpeg', '-i', input_path, '-vcodec', 'libx264', '-crf', '28', output_path]) + +# Function to generate HTML content +def generate_html(): + html_content = "" + + # Read header content + header_content = read_file(os.path.join(misc_path, 'header.md')) + header_html = markdown.markdown(header_content) + html_content += f"
{header_html}
" + + # Get the files in the garden directory sorted by modification time + files = sorted( + os.listdir(garden_path), + key=lambda x: os.path.getmtime(os.path.join(garden_path, x)) + ) + + # Keep track of compressed files to manage deletions + compressed_files_to_keep = set() + + # Process each file in the garden directory + for filename in files: + file_path = os.path.join(garden_path, filename) + file_extension = filename.split('.')[-1].lower() + + if file_extension == 'txt': + text_content = read_file(file_path) + html_content += f"
{text_content}
" + + elif file_extension == 'md': + md_content = read_file(file_path) + md_html = markdown.markdown(md_content) + html_content += f"
{md_html}
" + + elif file_extension == 'pdf': + html_content += f"
" + + elif file_extension in ['png', 'jpg', 'jpeg', 'gif']: + compressed_image_path = os.path.join(compressed_path, f"compressed_{filename}") + compress_image(file_path, compressed_image_path) + html_content += f"
" + compressed_files_to_keep.add(compressed_image_path) + + elif file_extension in ['mp4', 'avi', 'mov', 'mkv']: + compressed_video_path = os.path.join(compressed_path, f"compressed_{filename}") + compress_video(file_path, compressed_video_path) + html_content += f"
" + compressed_files_to_keep.add(compressed_video_path) + + # Remove compressed files that no longer have a source file in the garden directory + for compressed_file in os.listdir(compressed_path): + compressed_file_path = os.path.join(compressed_path, compressed_file) + if compressed_file_path not in compressed_files_to_keep: + os.remove(compressed_file_path) + + # Read footer content + footer_content = read_file(os.path.join(misc_path, 'footer.md')) + footer_html = markdown.markdown(footer_content) + html_content += f"" + + return html_content + +# Generate the final HTML +final_html = f""" + + + + + + {website_title} + + + + + + + {generate_html()} + + + +""" + +# Save the final HTML to a file +with open('website/index.html', 'w', encoding='utf-8') as file: + file.write(final_html) + +print("Website generated successfully!") diff --git a/website/contents/garden/28939110848_fe332a710f_o.jpg b/website/contents/garden/28939110848_fe332a710f_o.jpg new file mode 100644 index 0000000..b714fbb Binary files /dev/null and b/website/contents/garden/28939110848_fe332a710f_o.jpg differ diff --git a/website/contents/garden/41001999900_14ee343161_o.jpg b/website/contents/garden/41001999900_14ee343161_o.jpg new file mode 100644 index 0000000..12e149c Binary files /dev/null and b/website/contents/garden/41001999900_14ee343161_o.jpg differ diff --git a/website/contents/garden/41911705355_4042c4ef5c_o.jpg b/website/contents/garden/41911705355_4042c4ef5c_o.jpg new file mode 100644 index 0000000..53bba8f Binary files /dev/null and b/website/contents/garden/41911705355_4042c4ef5c_o.jpg differ diff --git a/website/contents/garden/42095046344_8c4c0dc677_o.jpg b/website/contents/garden/42095046344_8c4c0dc677_o.jpg new file mode 100644 index 0000000..40dd3a4 Binary files /dev/null and b/website/contents/garden/42095046344_8c4c0dc677_o.jpg differ diff --git a/website/contents/garden/42095048424_447704ed3c_o.jpg b/website/contents/garden/42095048424_447704ed3c_o.jpg new file mode 100644 index 0000000..7685ba6 Binary files /dev/null and b/website/contents/garden/42095048424_447704ed3c_o.jpg differ diff --git a/website/contents/garden/42095064534_3276c0caed_o.jpg b/website/contents/garden/42095064534_3276c0caed_o.jpg new file mode 100644 index 0000000..01f19af Binary files /dev/null and b/website/contents/garden/42095064534_3276c0caed_o.jpg differ diff --git a/website/contents/garden/ansaldo-web.pdf b/website/contents/garden/ansaldo-web.pdf new file mode 100644 index 0000000..4fd8a45 Binary files /dev/null and b/website/contents/garden/ansaldo-web.pdf differ diff --git a/website/contents/garden/compressed/compressed_28939110848_fe332a710f_o.jpg b/website/contents/garden/compressed/compressed_28939110848_fe332a710f_o.jpg new file mode 100644 index 0000000..528ca6f Binary files /dev/null and b/website/contents/garden/compressed/compressed_28939110848_fe332a710f_o.jpg differ diff --git a/website/contents/garden/compressed/compressed_41001999900_14ee343161_o.jpg b/website/contents/garden/compressed/compressed_41001999900_14ee343161_o.jpg new file mode 100644 index 0000000..e704c5f Binary files /dev/null and b/website/contents/garden/compressed/compressed_41001999900_14ee343161_o.jpg differ diff --git a/website/contents/garden/compressed/compressed_41911705355_4042c4ef5c_o.jpg b/website/contents/garden/compressed/compressed_41911705355_4042c4ef5c_o.jpg new file mode 100644 index 0000000..6ac5ffc Binary files /dev/null and b/website/contents/garden/compressed/compressed_41911705355_4042c4ef5c_o.jpg differ diff --git a/website/contents/garden/compressed/compressed_42095046344_8c4c0dc677_o.jpg b/website/contents/garden/compressed/compressed_42095046344_8c4c0dc677_o.jpg new file mode 100644 index 0000000..50301ff Binary files /dev/null and b/website/contents/garden/compressed/compressed_42095046344_8c4c0dc677_o.jpg differ diff --git a/website/contents/garden/compressed/compressed_42095048424_447704ed3c_o.jpg b/website/contents/garden/compressed/compressed_42095048424_447704ed3c_o.jpg new file mode 100644 index 0000000..33a106f Binary files /dev/null and b/website/contents/garden/compressed/compressed_42095048424_447704ed3c_o.jpg differ diff --git a/website/contents/garden/compressed/compressed_42095064534_3276c0caed_o.jpg b/website/contents/garden/compressed/compressed_42095064534_3276c0caed_o.jpg new file mode 100644 index 0000000..44292ab Binary files /dev/null and b/website/contents/garden/compressed/compressed_42095064534_3276c0caed_o.jpg differ diff --git a/website/contents/garden/test.md b/website/contents/garden/test.md new file mode 100644 index 0000000..7aa67e5 --- /dev/null +++ b/website/contents/garden/test.md @@ -0,0 +1,5 @@ +# ciao + +## Io sono Bruno + +Questo e' un testo su Bruno \ No newline at end of file diff --git a/website/contents/garden/test.txt b/website/contents/garden/test.txt new file mode 100644 index 0000000..3df7055 --- /dev/null +++ b/website/contents/garden/test.txt @@ -0,0 +1,8 @@ +kshvhbv \fhdbdsv\d\\ + +fgef +bvf +bs +fhdbdsvsf +bsfsbsfb +sf \ No newline at end of file diff --git a/website/contents/misc/footer.md b/website/contents/misc/footer.md new file mode 100644 index 0000000..aa13dc8 --- /dev/null +++ b/website/contents/misc/footer.md @@ -0,0 +1 @@ +[Credits](http://federicoponi.it) \ No newline at end of file diff --git a/website/contents/misc/header.md b/website/contents/misc/header.md new file mode 100644 index 0000000..55a359d --- /dev/null +++ b/website/contents/misc/header.md @@ -0,0 +1,2 @@ +# Welcome to my garden! +This is what I have in my magic desk \ No newline at end of file diff --git a/website/scripts/script.js b/website/scripts/script.js new file mode 100644 index 0000000..bd40bc4 --- /dev/null +++ b/website/scripts/script.js @@ -0,0 +1,46 @@ +function randomPos(min, max) { + return Math.random() * (max - min) + min; + +} + +let w = document.body.clientWidth +let y = document.body.clientHeight - document.querySelector('footer').clientHeight +let x_start = document.querySelector('header').clientHeight + +document.querySelectorAll('.draggable').forEach(div => { + + div.style.left = randomPos(0,w)+'px' + div.style.top = randomPos(x_start,y)+'px' + + + div.onmousedown = function(event) { + let shiftX = event.clientX - div.getBoundingClientRect().left; + let shiftY = event.clientY - div.getBoundingClientRect().top; + + function moveAt(pageX, pageY) { + div.style.left = pageX - shiftX + 'px'; + div.style.top = pageY - shiftY + 'px'; + } + + function onMouseMove(event) { + moveAt(event.pageX, event.pageY); + } + + document.addEventListener('mousemove', onMouseMove); + + div.onmouseup = function() { + document.removeEventListener('mousemove', onMouseMove); + div.onmouseup = null; + }; + + div.ondblclick = function() { + document.removeEventListener('mousemove', onMouseMove); + }; + }; + + div.ondragstart = function() { + return false; + }; + + +}); \ No newline at end of file diff --git a/website/style.css b/website/style.css new file mode 100644 index 0000000..3d135e6 --- /dev/null +++ b/website/style.css @@ -0,0 +1,47 @@ +body, html{ + width: 100%; + height: 100%; + margin: 0; + padding: 0; +} + +img{ + width: 250px; + display: block; +} + +.text{ + padding: 10px; + width: 200px; + height: min-content; + overflow-y: scroll; + max-height: 300px; + +} + +.draggable { + position: absolute; + cursor: move; +} + +footer, header{ + position: fixed; + z-index: 99; + width: 100%; + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + gap: 0 +} + +header{ + top: 0; +} +footer{ + bottom: 0; +} + +header h1{ + margin-bottom: 0; +} \ No newline at end of file