first
@ -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>{header_html}</header>"
|
||||
|
||||
# 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"<div class='draggable text'>{text_content}</div>"
|
||||
|
||||
elif file_extension == 'md':
|
||||
md_content = read_file(file_path)
|
||||
md_html = markdown.markdown(md_content)
|
||||
html_content += f"<div class='draggable text'>{md_html}</div>"
|
||||
|
||||
elif file_extension == 'pdf':
|
||||
html_content += f"<div class='draggable'><iframe src='./contents/garden/{filename}'></iframe></div>"
|
||||
|
||||
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"<div class='draggable'><img src='./contents/garden/compressed/compressed_{filename}'></div>"
|
||||
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"<div class='draggable'><video controls src='./contents/garden/compressed/compressed_{filename}'></video></div>"
|
||||
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"<footer>{footer_html}</footer>"
|
||||
|
||||
return html_content
|
||||
|
||||
# Generate the final HTML
|
||||
final_html = f"""
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{website_title}</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<meta name="description" content="{website_description}">
|
||||
<style>
|
||||
body {{
|
||||
background-color: {background_color};
|
||||
color: {text_color};
|
||||
}}
|
||||
|
||||
.text{{
|
||||
border: solid {text_color};
|
||||
}}
|
||||
|
||||
a{{color: {text_color};}}
|
||||
|
||||
footer a, header a{{color: {text_color_header_footer};}}
|
||||
|
||||
header, footer{{
|
||||
background-color: {background_color_header_footer};
|
||||
color: {text_color_header_footer};
|
||||
}}
|
||||
.draggable {{
|
||||
position: absolute;
|
||||
cursor: move;
|
||||
}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<button onclick="toggleView()">Toggle View</button>
|
||||
{generate_html()}
|
||||
<script src="scripts/script.js"></script>
|
||||
</body>
|
||||
</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!")
|
After Width: | Height: | Size: 7.3 MiB |
After Width: | Height: | Size: 6.2 MiB |
After Width: | Height: | Size: 6.8 MiB |
After Width: | Height: | Size: 6.3 MiB |
After Width: | Height: | Size: 6.1 MiB |
After Width: | Height: | Size: 6.2 MiB |
After Width: | Height: | Size: 2.4 MiB |
After Width: | Height: | Size: 1.9 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 1.9 MiB |
After Width: | Height: | Size: 1.9 MiB |
After Width: | Height: | Size: 2.0 MiB |
@ -0,0 +1,5 @@
|
||||
# ciao
|
||||
|
||||
## Io sono Bruno
|
||||
|
||||
Questo e' un testo su Bruno
|
@ -0,0 +1,8 @@
|
||||
kshvhbv \fhdbdsv\d\\
|
||||
|
||||
fgef
|
||||
bvf
|
||||
bs
|
||||
fhdbdsvsf
|
||||
bsfsbsfb
|
||||
sf
|
@ -0,0 +1 @@
|
||||
[Credits](http://federicoponi.it)
|
@ -0,0 +1,2 @@
|
||||
# Welcome to my garden!
|
||||
This is what I have in my magic desk
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
});
|
@ -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;
|
||||
}
|