diff --git a/gamewiki/parser.py b/gamewiki/parser.py index d19b33a..599c7a5 100644 --- a/gamewiki/parser.py +++ b/gamewiki/parser.py @@ -26,7 +26,7 @@ class WikiArticle: with open(filename, 'r') as f: content = f.readlines() - self.content = [c.strip() for c in content] + self.content = [c for c in content] self.title = title(content) self.tags = tags(content) self.filename = filename @@ -38,9 +38,9 @@ class WikiArticle: for line in content: if line == self.header: break else: yield line - yield self.header + yield self.header + '\n' for w in linked_articles: - yield f'- [[../{w.filename}][{w.title}]]' + yield f'- [[../{w.filename}][{w.title}]]\n' return rep() def __repr__(self): @@ -62,7 +62,7 @@ class MetaPage(WikiArticle): raise Exception(f'Multiple tags in metapage: {self.filename}') self.meta = self.tags[0] - correct_section = list(filter(lambda l: l == self.header, self.content)) + correct_section = list(filter(lambda l: l.strip() == self.header, self.content)) if len(correct_section) != 1: raise Exception(f'Invalid meta section in {filename}') @@ -106,7 +106,7 @@ def links(article: ContentArticle): def writetodisk(m: WikiArticle, content: list[str]): with open(m.filename, 'w') as f: - f.writelines(map(lambda l: l+'\n', content)) + f.writelines(content) if __name__ == '__main__': files_ = [ContentArticle(f) for f in files()] @@ -122,5 +122,6 @@ if __name__ == '__main__': for f in files_: related = set(links(f)) - newcontent = f.enrich(map(lambda f: byfilename[f], related)) - writetodisk(f, newcontent) + if related: + newcontent = f.enrich(map(lambda f: byfilename[f], related)) + writetodisk(f, newcontent)