neocities-site/generator.py

46 lines
1.5 KiB
Python

import os
static = os.listdir("pages/static/")
posts = os.listdir("pages/posts")
templates = ["header","navbar","body","footer"]
for staticPage in static:
with open("site/" + staticPage, 'w+') as output:
for page in templates:
with open ("templates/" + page + ".htm") as template:
for line in template:
if "%Content%" in line:
line = ""
with open("pages/static/" + staticPage) as content:
for line1 in content:
line += "\t\t\t" + line1
output.write(line)
def makeGifGallery():
gifs = []
for file in os.listdir('site/images/gifs/customgifs/'):
with open("templates/gifwrap.htm") as wrap:
for line in wrap:
gif = line.replace("%gif%", "images/gifs/customgifs/" + file)
gifs.append(gif)
with open("pages/posts/gifs.htm") as gifstpl:
with open("pages/static/gifs.htm","w+") as output:
output.write('<h1>GIFs I have made</h1>')
output.write('\n<table style="width: 800px; margin-left: auto; margin-right: auto;">')
count = 0
for gif in gifs:
if count==0:
output.write('\n<tr>\n')
count += 1
output.write('<td>' + gif + '</td>')
if count%3==0:
output.write('\n</tr>\n<tr>')
output.write('\n</table>\n\n')
makeGifGallery()