From c1db9bb5f434240ee47e30ac65189ed9f59807c2 Mon Sep 17 00:00:00 2001 From: relt-1 Date: Sat, 23 Sep 2023 18:33:53 +0200 Subject: [PATCH] Tree view --- __main__.py | 37 +++++++++++-- dst/QScript/Introduction.html | 88 ++++++++++++++++++++++++++++++ dst/QScript/Lua/Classes.html | 88 ++++++++++++++++++++++++++++++ dst/QScript/Lua/Exports.html | 88 ++++++++++++++++++++++++++++++ dst/QScript/Lua/Imports.html | 88 ++++++++++++++++++++++++++++++ dst/QScript/Lua/Intro.html | 88 ++++++++++++++++++++++++++++++ dst/QScript/Lua/Objects.html | 88 ++++++++++++++++++++++++++++++ dst/QScript/Tutorial/Chapter1.html | 88 ++++++++++++++++++++++++++++++ dst/index.html | 88 ++++++++++++++++++++++++++++++ template.html | 60 ++++++++++++++++++++ 10 files changed, 796 insertions(+), 5 deletions(-) diff --git a/__main__.py b/__main__.py index 7619eec..d1cbf57 100644 --- a/__main__.py +++ b/__main__.py @@ -6,25 +6,52 @@ import shutil mark = markdown2.Markdown() -src = os.path.dirname(os.path.realpath(__file__))+"/src/" -dst = os.path.dirname(os.path.realpath(__file__))+"/dst/" +rootpath = os.path.dirname(os.path.realpath(__file__)) +src = rootpath+"/src/" +lensrc = len(src) +dst = rootpath+"/dst/" +assets = rootpath+"/assets/" shutil.rmtree(dst) -os.mkdir(dst) +shutil.copytree(assets,dst) with open("template.html","r") as f: template = f.read() documentlist = [] namelist = [] +filetreedict = {} +filetree = "" for root, subdirs, files in os.walk(src): + p = filetreedict + if root[lensrc:]: + for x in root[lensrc:].replace("\\","/").split("/"): + p = p.setdefault(x, {}) + p[''] = [] for file in files: fpath = os.path.join(root, file) with open(fpath,"r") as f: rawmarkdown = f.read() if(rawmarkdown[0:2] != "# "): raise SyntaxError(".md file must begin with a # marked title!") + name = rawmarkdown[2:].split("\n",1)[0] + p[''].append([os.path.join(root[lensrc:],file.replace(".md","")).replace("\\","/"),name]) documentlist.append("/wiki/"+fpath[len(src):].replace(".md",".html").replace("\\","/")) - namelist.append(rawmarkdown[2:].split("\n",1)[0]) + namelist.append(name) + +def IterateFileTree(filedict): + global filetree + for key, value in filedict.items(): + if isinstance(value, dict): + filetree += f"
  • {key}\n\n
  • \n" + else: + for file in value: + filetree += f"
  • {file[1]}
  • \n" + +IterateFileTree(filetreedict) +print(filetree) + template = template.replace("@DOCUMENTLIST",str(documentlist)).replace("@NAMELIST",str(namelist)) for root, subdirs, files in os.walk(src): if(not os.path.exists(dst+root[len(src):])): @@ -48,4 +75,4 @@ for root, subdirs, files in os.walk(src): name = link[1:].split("]",1)[0] href = link[1:].split("[",1)[1].split("]",1)[0] converted = converted.replace(link, ""+name+"") - r.write(template.replace("@CONTENT",converted)) \ No newline at end of file + r.write(template.replace("@CONTENT",converted).replace("@FILETREE",filetree)) \ No newline at end of file diff --git a/dst/QScript/Introduction.html b/dst/QScript/Introduction.html index 56c3f5c..db057e3 100644 --- a/dst/QScript/Introduction.html +++ b/dst/QScript/Introduction.html @@ -1,15 +1,29 @@ +SourceBox Wiki