modified: generate.py

added 481 new Lemmy Instances
main
anthony 3 weeks ago
parent e89985fffc
commit 99433b7f41

@ -5,11 +5,24 @@ def load_social_media_data():
with open("./templates/sites.json", "r") as file: with open("./templates/sites.json", "r") as file:
return json.load(file) return json.load(file)
def extract_domain(link):
# Extract the domain from a link (e.g., "https://mastodon.social" -> "mastodon.social")
return link.split("//")[-1].split("/")[0]
def detect_platform(link, social_media_data): def detect_platform(link, social_media_data):
# Detect the platform from the link # Extract the domain from the link
domain = extract_domain(link)
# Check each platform's domains list
for platform, data in social_media_data.items():
if "domains" in data and domain in data["domains"]:
return platform
# Fallback: Check if the platform name is in the link (e.g., "twitter.com" -> "twitter")
for platform in social_media_data: for platform in social_media_data:
if platform in link: if platform in link:
return platform return platform
return None return None
def generate_html(links, social_media_data): def generate_html(links, social_media_data):
@ -32,7 +45,7 @@ def generate_html(links, social_media_data):
''' '''
else: else:
# If the platform is not recognized, use the domain name as the button text # If the platform is not recognized, use the domain name as the button text
domain = link.split("//")[-1].split("/")[0] # Extract domain from link domain = extract_domain(link)
buttons += f'<a href="{link}" class="button">{domain}</a>\n' buttons += f'<a href="{link}" class="button">{domain}</a>\n'
# Replace the placeholder with the generated buttons # Replace the placeholder with the generated buttons
@ -43,7 +56,7 @@ def generate_html(links, social_media_data):
with open(output_file, "w") as file: with open(output_file, "w") as file:
file.write(template) file.write(template)
print(f"Your Linktree '{output_file}' has been generated successfully!") print(f"HTML file '{output_file}' has been generated successfully!")
if __name__ == "__main__": if __name__ == "__main__":
# Load social media data # Load social media data

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My LinkTree</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.button {
display: flex;
align-items: center;
padding: 15px 30px;
font-size: 18px;
color: white;
background-color: #007BFF;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease;
margin: 10px;
width: 200px;
text-align: center;
}
.button:hover {
background-color: #0056b3;
}
.button img {
width: 24px;
height: 24px;
margin-right: 10px;
}
</style>
</head>
<body>
<a href="https://code.cif.su/anthony" class="button">
<img src="https://example.com/icons/github.svg" alt="github icon">
GitHub
</a>
<a href="https://mastodon.cif.su/@anthony" class="button">
<img src="https://example.com/icons/mastodon.svg" alt="mastodon icon">
Mastodon
</a>
</body>
</html>

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save