More pathlib usage & code cleanup
This commit is contained in:
		
							parent
							
								
									253851b871
								
							
						
					
					
						commit
						78817f4467
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -3,3 +3,4 @@
 | 
				
			|||||||
website-output
 | 
					website-output
 | 
				
			||||||
__pycache__
 | 
					__pycache__
 | 
				
			||||||
coverage.xml
 | 
					coverage.xml
 | 
				
			||||||
 | 
					/gsitegen/*.page
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,7 @@ import markdown
 | 
				
			|||||||
import html
 | 
					import html
 | 
				
			||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#TODO re-think navigation bar. Think of way to add option to display navigation bar entry differently if you're currently on that page.
 | 
				
			||||||
def generateNavigationBar(lines):
 | 
					def generateNavigationBar(lines):
 | 
				
			||||||
  global navbar
 | 
					  global navbar
 | 
				
			||||||
  navbar = E
 | 
					  navbar = E
 | 
				
			||||||
@ -108,14 +109,16 @@ def writePages(homepage):
 | 
				
			|||||||
        os.mkdir("./website-output" + foldername)
 | 
					        os.mkdir("./website-output" + foldername)
 | 
				
			||||||
      except FileExistsError:
 | 
					      except FileExistsError:
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
    filepath = Path("./website-output" + foldername + "/index.html")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if filepath.exists():
 | 
					    filepath = "./website-output" + foldername + "/index.html"
 | 
				
			||||||
      with open("./website-output" + foldername + "/index.html", 'r') as newpage:
 | 
					
 | 
				
			||||||
 | 
					    if Path(filepath).exists():
 | 
				
			||||||
 | 
					      with open(filepath, 'r') as newpage:
 | 
				
			||||||
        if newpage.read() == page:
 | 
					        if newpage.read() == page:
 | 
				
			||||||
          print("Page not changed: " + titles[id])
 | 
					          print("Page not changed: " + titles[id])
 | 
				
			||||||
          continue
 | 
					          continue
 | 
				
			||||||
    with open("./website-output" + foldername + "/index.html", 'w') as newpage:
 | 
					
 | 
				
			||||||
 | 
					    with open(filepath, 'w') as newpage:
 | 
				
			||||||
      newpage.write(page)
 | 
					      newpage.write(page)
 | 
				
			||||||
      print("Written changed page: " + titles[id])
 | 
					      print("Written changed page: " + titles[id])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -124,13 +127,12 @@ def main():
 | 
				
			|||||||
  #if homepage is at Home.page, set homepage to "Home"
 | 
					  #if homepage is at Home.page, set homepage to "Home"
 | 
				
			||||||
  homepage = "Home"
 | 
					  homepage = "Home"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if os.path.exists("./navbar"):
 | 
					  if Path("./navbar").exists():
 | 
				
			||||||
    with open("./navbar", 'r') as navbarfile:
 | 
					    with open("./navbar", 'r') as navbarfile:
 | 
				
			||||||
      generateNavigationBar(navbarfile.readlines())
 | 
					      generateNavigationBar(navbarfile.readlines())
 | 
				
			||||||
  else:
 | 
					  else:
 | 
				
			||||||
    print("No 'navbar' file found, there will be no navigation bar.")
 | 
					    print("No 'navbar' file found, there will be no navigation bar.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #count total amount of pages first
 | 
					 | 
				
			||||||
  pagescount = 0
 | 
					  pagescount = 0
 | 
				
			||||||
  for file in os.listdir("./"):
 | 
					  for file in os.listdir("./"):
 | 
				
			||||||
    if file.endswith(".page"):
 | 
					    if file.endswith(".page"):
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user