Work with current dir, exit if no pages found

This commit is contained in:
Govindas 2022-02-17 16:31:58 +02:00
parent 71bb1e662a
commit 7d6519c9ad
2 changed files with 10 additions and 7 deletions

View File

@ -143,7 +143,7 @@ def generatePage(title, doc):
if 'titles' not in globals(): if 'titles' not in globals():
titles = [] titles = []
navbarfile = Path(__file__).parent.joinpath('navbar') navbarfile = Path("./").parent.joinpath('navbar')
if navbarfile.exists(): if navbarfile.exists():
with navbarfile.open('r') as navbarfile: with navbarfile.open('r') as navbarfile:
@ -166,6 +166,9 @@ def generatePage(title, doc):
def writePages(): def writePages():
global pages global pages
global titles global titles
if 'pages' not in globals():
print("Error: no page files found")
exit()
#TODO only delete files that aren't present in newest site generation #TODO only delete files that aren't present in newest site generation
#deleting contents of folder without deleting the folder, to increase compatibility with various systems #deleting contents of folder without deleting the folder, to increase compatibility with various systems
#for root, dirs, files in os.walk('./website-output'): #for root, dirs, files in os.walk('./website-output'):
@ -181,7 +184,7 @@ def writePages():
if titles[id] != homepage: if titles[id] != homepage:
foldername = titles[id].replace(" ", "-").lower() foldername = titles[id].replace(" ", "-").lower()
outputpath = Path(__file__).parent.joinpath("website-output") outputpath = Path("./").parent.joinpath("website-output")
dirpath = outputpath.joinpath(foldername) dirpath = outputpath.joinpath(foldername)
@ -200,7 +203,7 @@ def writePages():
print("Written changed page: " + titles[id]) print("Written changed page: " + titles[id])
#resources #resources
respath = Path(__file__).parent.joinpath("resources") respath = Path("./").parent.joinpath("resources")
if respath.exists(): if respath.exists():
#shutil.copytree copies timestamp too #shutil.copytree copies timestamp too
@ -229,7 +232,7 @@ def main():
global homepage global homepage
homepage = "Home" homepage = "Home"
footerfile = Path(__file__).parent.joinpath('footer') footerfile = Path("./").parent.joinpath('footer')
if footerfile.exists(): if footerfile.exists():
with footerfile.open('r') as footerfile: with footerfile.open('r') as footerfile:
@ -239,7 +242,7 @@ def main():
pagescount = 0 pagescount = 0
for file in Path(__file__).parent.iterdir(): for file in Path("./").parent.iterdir():
if file.is_file(): if file.is_file():
if file.suffix == ".page": if file.suffix == ".page":
pagescount += 1 pagescount += 1

View File

@ -1,7 +1,7 @@
from gsitegen.generate import * from gsitegen.generate import *
from html5tagger import E from html5tagger import E
def test_something(): def test_markdown():
doc = E() doc = E()
parseMarkdown(doc, "## Heading 2") doc = parseMarkdown(doc, "## Heading 2")
assert str(doc) == "<h2>Heading 2</h2>" assert str(doc) == "<h2>Heading 2</h2>"