pfad-foo entwirrt...
This commit is contained in:
parent
339cd88c6c
commit
e3392163ac
|
|
@ -4,7 +4,7 @@
|
|||
<p>Fedi: <a rel="me" href="https://chaos.social/@dm2lct">@dm2lct@chaos.social</a></p>
|
||||
<p>QRZ.com: <a href="https://www.qrz.com/db/dm2lct">https://www.qrz.com/db/dm2lct</a></p>
|
||||
<p>hamqth.com: <a href="https://www.hamqth.com/dm2lct">https://www.hamqth.com/dm2lct</a></p>
|
||||
<p>Built with 💜 using <a href="https://github.com/spectrasecure/arise">Arise</a></p>
|
||||
<p>Built with 💜 using <a href="https://gitea.dm2lct.radio/chrissy/purrpic">Purrpic =^.^=</a></p>
|
||||
</div>
|
||||
<!-- End Page Footer -->
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<!-- Basic Metadata -->
|
||||
<meta charset="utf-8" />
|
||||
<meta name="HandheldFriendly" content="True" />
|
||||
<meta name="generator" content="Arise" />
|
||||
<meta name="generator" content="Purrpic" />
|
||||
|
||||
<title>{{title}} · {{global_name}}</title>
|
||||
<meta name="description" content="{{description}}">
|
||||
|
|
@ -53,8 +53,8 @@
|
|||
hr {color:#fff;}
|
||||
.topbar a {color:#fff; text-decoration:none;}
|
||||
</style>
|
||||
<link rel="stylesheet" href="/config/main.css">
|
||||
<div class="logo"><a href="/"><img src="/config/logo.png" /></a></div>
|
||||
<link rel="stylesheet" href="../../conf/main.css">
|
||||
<div class="logo"><a href="/"><img src="../../conf/logo.png" /></a></div>
|
||||
<!-- End Styles+Logo -->
|
||||
<div class="header">
|
||||
<a href="/">Chrissys random stuff.</a>
|
||||
|
|
|
|||
|
|
@ -246,6 +246,8 @@ nav li {
|
|||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
padding: 0 4px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
/* Create four equal columns that sits next to each other */
|
||||
|
|
@ -253,12 +255,21 @@ nav li {
|
|||
flex: 25%;
|
||||
max-width: 25%;
|
||||
padding: 0 4px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.column img {
|
||||
margin-top: 8px;
|
||||
vertical-align: middle;
|
||||
width: 100%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.column div.desc {
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Responsive layout - makes a two column-layout instead of four columns */
|
||||
|
|
@ -266,6 +277,8 @@ nav li {
|
|||
.column {
|
||||
flex: 50%;
|
||||
max-width: 50%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,6 +287,8 @@ nav li {
|
|||
.column {
|
||||
flex: 100%;
|
||||
max-width: 100%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
165
purrpic.py
165
purrpic.py
|
|
@ -15,17 +15,19 @@ import configparser
|
|||
from pathlib import Path
|
||||
import datetime
|
||||
|
||||
BUILD_DIR = Path("./build")
|
||||
CONF_DIR = Path("./conf")
|
||||
BUILD_DIR = Path("./build").resolve()
|
||||
CONF_DIR = Path("./conf").resolve()
|
||||
THUMBSIZE = (300, 300)
|
||||
GLOBALNAME = "Chrissys random Imagelibrary"
|
||||
LICENCE = "CC BY-NC-SA 4.0"
|
||||
AUTHOR = "Luzia Christiane Tesar"
|
||||
LANGUAGE = "en"
|
||||
DESCRIPTION = ""
|
||||
DESCRIPTION = ""
|
||||
TODAY = datetime.datetime.today().strftime("%Y-%m-%d")
|
||||
CANONICALURL = "https://dm2lct.radio"
|
||||
|
||||
exclude = set(['.thumbnails'])
|
||||
exclude = set([".thumbnails", ".git", "conf", "build"])
|
||||
|
||||
|
||||
class HTML:
|
||||
def __init__(self, **kwargs):
|
||||
|
|
@ -74,64 +76,73 @@ class HTML:
|
|||
header = header.replace("{{description}}", DESCRIPTION)
|
||||
header = header.replace("{{published_date}}", TODAY)
|
||||
header = header.replace("{{modified_date}}", TODAY)
|
||||
header = header.replace("{{canonical_URL}}", CANONICALURL)
|
||||
header = header.replace("{{canonical_url}}", CANONICALURL)
|
||||
return header
|
||||
|
||||
def writeIndex(self, indir, odir, title, info=None) -> None:
|
||||
def writeIndex(self, odir, meta) -> None:
|
||||
try:
|
||||
title=meta['title']
|
||||
desc=meta['description']
|
||||
buf = self.headermeta(title)
|
||||
buf += self.title(title)
|
||||
if len(desc) > 0:
|
||||
buf += self.ul()
|
||||
for line in desc:
|
||||
buf += self.li(line)
|
||||
buf += self.li(f"© {AUTHOR}, {LICENCE}")
|
||||
buf += self.endUl()
|
||||
buf += self.div("row")
|
||||
#imglist = glob.glob(str(odir) + "/.thumbnails/*")
|
||||
imglist =[]
|
||||
for img in Path.iterdir(odir / ".thumbnails"):
|
||||
imglist.append(img)
|
||||
for n in range(0, 3):
|
||||
buf += self.div("column")
|
||||
breakpoint()
|
||||
for i in range(n, len(imglist), 3):
|
||||
buf += self.aimg(
|
||||
".thumbnails/" + imglist[i].name,
|
||||
imglist[i].name)
|
||||
buf += self.endDiv()
|
||||
buf += self.endDiv()
|
||||
buf += self.footer
|
||||
with open(f"{odir}/index.html", "w", encoding="utf-8") as file:
|
||||
file.write(self.headermeta(title))
|
||||
file.write(self.title(title))
|
||||
if info is not None:
|
||||
file.write(self.ul())
|
||||
for line in info:
|
||||
file.write(self.li(line))
|
||||
file.write(self.endUl())
|
||||
file.write(self.div("row"))
|
||||
imglist = glob.glob(str(odir) + "/.thumbnails/*")
|
||||
for n in range(0,3):
|
||||
file.write(self.div("column"))
|
||||
for i in range(n, len(imglist),3):
|
||||
file.write(
|
||||
self.aimg(
|
||||
imglist[i].removeprefix(str(odir) + "/"),
|
||||
imglist[i].removeprefix(str(odir) + "/.thumbnails/"),
|
||||
)
|
||||
)
|
||||
file.write(self.endDiv())
|
||||
file.write(self.endDiv())
|
||||
file.write(self.footer)
|
||||
file.write(buf)
|
||||
except:
|
||||
pass
|
||||
|
||||
def writeDetail(self, img, previmg, nextimg):
|
||||
buf+= self.headermeta(title)
|
||||
buf+= self.title(title)
|
||||
buf+= self.img(image)
|
||||
buf+= self.footer
|
||||
buf = self.headermeta(title)
|
||||
buf += self.title(title)
|
||||
buf += self.img(image)
|
||||
buf += self.footer
|
||||
with open(f"build/{self.outfolder}/index.html", "w", encoding="utf-8") as file:
|
||||
file.write(buf)
|
||||
|
||||
def writeMain(self):
|
||||
def writeMain(self, titles):
|
||||
with open(f"{str(BUILD_DIR)}/index.html", "w", encoding="utf-8") as file:
|
||||
title="Chrissys random Imagelibrary"
|
||||
title = "Chrissys random Imagelibrary"
|
||||
file.write(self.headermeta(title))
|
||||
file.write(self.title(title))
|
||||
file.write(self.div("row"))
|
||||
dirs = list(filter(lambda x: x.is_dir(),os.scandir(BUILD_DIR)))
|
||||
#dirs[:] = list(filter(lambda x: not x in exclude, dirs))
|
||||
for n in range(0,3):
|
||||
dirs = list(
|
||||
filter(lambda x: x.is_dir() and x not in exclude, os.scandir(BUILD_DIR))
|
||||
)
|
||||
for n in range(0, 3):
|
||||
file.write(self.div("column"))
|
||||
for i in range(n, len(dirs),3):
|
||||
thumbs = os.listdir(str(BUILD_DIR)+"/"+dirs[i].name+"/.thumbnails")
|
||||
for i in range(n, len(dirs), 3):
|
||||
thumbs = os.listdir(
|
||||
str(BUILD_DIR) + "/" + dirs[i].name + "/.thumbnails"
|
||||
)
|
||||
file.write(self.div("desc"))
|
||||
file.write("EH23")
|
||||
file.write(titles[dirs[i].name])
|
||||
file.write(self.endDiv())
|
||||
file.write(
|
||||
self.aimg(
|
||||
str(dirs[i].name)+"/.thumbnails/"+thumbs[0],
|
||||
str(dirs[i].name)+"/"),
|
||||
)
|
||||
self.aimg(
|
||||
str(dirs[i].name) + "/.thumbnails/" + thumbs[0],
|
||||
str(dirs[i].name) + "/",
|
||||
),
|
||||
)
|
||||
file.write(self.endDiv())
|
||||
file.write(self.endDiv())
|
||||
file.write(self.footer)
|
||||
|
|
@ -163,42 +174,49 @@ def processImage(img, odir):
|
|||
|
||||
|
||||
def generateDir(path):
|
||||
Path(BUILD_DIR / path.name).mkdir(parents=True, exist_ok=True)
|
||||
Path(BUILD_DIR / path.name / ".thumbnails").mkdir(parents=True, exist_ok=True)
|
||||
return Path(BUILD_DIR / path.name), Path(BUILD_DIR / path.name / ".thumbnails")
|
||||
odir = BUILD_DIR / path.name
|
||||
thumbdir = BUILD_DIR / path.name / ".thumbnails"
|
||||
Path.mkdir(odir, parents=True, exist_ok=True)
|
||||
Path.mkdir(thumbdir, parents=True, exist_ok=True)
|
||||
return odir, thumbdir
|
||||
|
||||
def parseIni(file):
|
||||
title = ""
|
||||
desc=[]
|
||||
files = []
|
||||
meta = {"title": None, "category": None, "description": [], "files": []}
|
||||
try:
|
||||
with open(file, 'r') as f:
|
||||
with open(file, "r") as f:
|
||||
for line in f:
|
||||
if line.startswith("desc = "):
|
||||
desc.append(line.removeprefix("desc = ").strip())
|
||||
meta["description"].append(line.removeprefix("desc = ").strip())
|
||||
elif line.endswith(".jpg\n" or ".png\n" or ".jpeg\n"):
|
||||
files.append(line.strip())
|
||||
meta["files"].append(line.strip())
|
||||
elif line.startswith("title = "):
|
||||
title=line.removeprefix("title = ").strip()
|
||||
meta["title"] = line.removeprefix("title = ").strip()
|
||||
elif line.startswith("category = "):
|
||||
meta["category"] = line.removeprefix("category = ").strip()
|
||||
else:
|
||||
next
|
||||
except:
|
||||
pass
|
||||
return files, desc, title
|
||||
return meta
|
||||
|
||||
|
||||
def processDir(path):
|
||||
try:
|
||||
if Path(path/".purrpic.ini").is_file():
|
||||
files, desc, title = parseIni(Path(args.inpath/".purrpic.ini"))
|
||||
odir, thumbdir = generateDir(args.inpath)
|
||||
for img in files:
|
||||
createThumb(Path(args.inpath/img), thumbdir)
|
||||
processImage(Path(args.inpath/img), odir)
|
||||
html = HTML()
|
||||
html.writeIndex(thumbdir, odir, title, desc)
|
||||
if Path.is_file(path /".purrpic.ini"):
|
||||
breakpoint()
|
||||
meta = parseIni(path / ".purrpic.ini")
|
||||
odir, thumbdir = generateDir(path)
|
||||
for img in meta["files"]:
|
||||
createThumb(path / img, thumbdir)
|
||||
processImage(path / img, odir)
|
||||
return odir, thumbdir, meta
|
||||
except:
|
||||
pass
|
||||
|
||||
def writeIndex(odir, meta):
|
||||
html = HTML()
|
||||
html.writeIndex(odir, meta)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
|
|
@ -208,13 +226,13 @@ if __name__ == "__main__":
|
|||
)
|
||||
parser.add_argument(
|
||||
"--inpath",
|
||||
type=lambda p: Path(p),
|
||||
type=lambda p: Path(p).resolve(),
|
||||
help="",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--outpath",
|
||||
type=lambda p: Path(p),
|
||||
type=lambda p: Path(p).resvolve(),
|
||||
help="",
|
||||
)
|
||||
parser.add_argument(
|
||||
|
|
@ -224,8 +242,19 @@ if __name__ == "__main__":
|
|||
help="",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
processDir(args.inpath)
|
||||
breakpoint()
|
||||
if args.outpath:
|
||||
BUILD_DIR = args.outpath
|
||||
|
||||
html=HTML()
|
||||
html.writeMain()
|
||||
metadata = {}
|
||||
for d in args.inpath.iterdir():
|
||||
if d.is_dir() and d.name not in exclude:
|
||||
# processDir(d.name)
|
||||
try:
|
||||
odir, thumbdir, meta = processDir(d)
|
||||
metadata[d.name] = meta
|
||||
writeIndex(odir, meta)
|
||||
except:
|
||||
next
|
||||
# html = HTML()
|
||||
# html.writeMain(metadata)
|
||||
|
|
|
|||
Loading…
Reference in New Issue