diff --git a/homepage/homepage b/homepage/homepage index 65f5142..40935d6 100644 --- a/homepage/homepage +++ b/homepage/homepage @@ -1,34 +1,82 @@ #!/bin/sh #llllmmmm11234567892123456789312345678941234567895123456789612345678971234567890 set -ex -<"$0" python3 -c " +<"$0" python3 -c ' import os, sys -cleanupsh = '#!/bin/sh\n' -for day in sys.stdin.read().split('\n\n\n'): - f = day.split('\n')[0] - if '\t' in f: - fa = f.split('\t')[1].split(',') - f = f.split('\t')[0] - else: - fa = [''] - if f[0] != '/': - continue - f = '.' + f - if os.path.isfile(f): - continue - d = '/'.join(f.split('/')[:-1]) - if '/' in f and not(os.path.isdir(d)) and not(d == ''): - os.makedirs(d) - cleanupsh += 'rm -r -- ' + d + '\n' - with open(f,'w') as fd: - fd.write(day) - if cleanupsh == '': - cleanupsh = '#!/bin/sh\n' - cleanupsh += 'rm -- ' + f + '\n' -if len(cleanupsh.split('\n')) > 2: - with open('cleanup.sh', 'w') as fd: - fd.write(cleanupsh) -" +class File: + attributes = [ # last in order wins in conflict, list must have both + "literally", "figuratively", + "append", "replace", + "verbatim", "stub" + ] + content = "" + def __init__(self, **kwargs): + if "attributes" in kwargs: + self.attributes += kwargs["attributes"] + del(kwargs["attributes"]) + for key in kwargs: + if key == "attributes": self.attributes+=kwargs["key"] + else: setattr(self, key, kwargs[key]) +files = {"./cleanup.sh": File(attributes=["verbatim"], content="#!/bin/sh\n")} +for part in sys.stdin.read().split("\n\n\n").reverse(): + name = part.split("\n")[0] + substitutions = dict() + if "\t" in "." + name: + attributes = name.split("\t")[1].split(",") + name = name.split("\t")[0] + else: attributes = default_attributes + if len(name) > 1 and name[1] != "/": continue + for s in part[len(name)+1:].split("\n\n")[0].split("\n"): + s = s.split("\t") + if len(s) == 2: substitutions[s[0]] = s[1] + content = part[len(substitutions)+2:] + if attributes.index("append") > attributes.index("replace"): + if not(name in files): + sys.stderr.write(sys.argv[0] + ": " + name + ": " + + "appending to nothing\n") + else: + content = files[name].content + content + files += {name: File(attributes = attributes, content = content, + substitutions = substitutions)} +for name in files: + if name == "./cleanup.sh": continue + attributes = files[name].attributes + directory = "/".join(name.split("/")[:-1]) + if attributes.index("stub") > attributes.index("verbatim"): + prefix = "" + suffix = "" + for d in directory.split("/"): + if d + "/Prefix" in files.keys(): + prefix = files[d + "/Prefix"].content + if d + "/Suffix" in files.keys(): + suffix = files[d + "/Suffix"].content + files[name].content = prefix + files[name].content + suffix + if attributes.index("figuratively") > attributes.index("literally"): + content = files[name].content + for s in files[name].substitutions: + instances = [] + i = 0 + while True: + instance = content.find(s, i) + if instance == -1: break + intances += [instance] + i = instance + len(s) + if len(instances) == 0: continue + for i in intances.reverse(): + content = (content[:i] + substitutions[s] + + content[i+len(s):]) + files[name].content = content + if not(os.path.isdir(directory)): + os.makedirs(directory) + files["./cleanup.sh"].content += "rm -r -- " + directory + "\n" + else if directory == ".": + files["./cleanup.sh"].content += "rm -- " + name + "\n" + with open(name, "w") as fd: + fd.write(f) +if len(files["./cleanup.sh"].content.split("\n")) > 2: + with open("./cleanup.sh", "w") as fd: + fd.write(files["./cleanup.sh"].content) +' test -f homepage.local \ && exec ./homepage.local \ || exit 0 @@ -63,8 +111,8 @@ For more information, please refer to /homepage.html -$! __TITLE__ "homepage" documentation -$! __DESCRIPTION one file, one website +$!TITLE "homepage" documentation +$!DESCRIPTION one file, one website

"homepage" documentation

the forest

@@ -109,14 +157,62 @@ appended. The "stub" attribute indicates the opposite, though its behavior is default.

-The "literal" attribute indicates that the file should not be subject to -macro expansion despite any other directives. The "figurative" attribute +The "literally" attribute indicates that the file should not be subject to +macro expansion despite any other directives. The "figuratively" attribute indicates the opposite, though its behavior is default.

+/praise/index.html append,literally + +
  • [] Doctor Eli Selig !!JQHA6kqyl91: >Maid Phone user / >mfw / ["Heart hands.jpg"]
  • + + +/praise/Prefix + + + + + + + + + + + + + +