(arne)
2012-06-04: added css ids to all elements for easier styling. added css ids to all elements for easier styling.
diff --git a/site.py b/site.py --- a/site.py +++ b/site.py @@ -42,7 +42,7 @@ templates = { <title>{title}</title> </head> <body> -<h1>{reponame}</h1> +<h1 id="maintitle">{reponame}</h1> """, "srchead": """<!DOCTYPE html> <html><head> @@ -83,11 +83,14 @@ def contentequals(filepath, content): except IOError: return False # file does not exist. Empty != not existing. # TODO: check: return True if content is None? -def parsereadme(filepath): +def parsereadme(filepath, truncated=False): """Parse the readme file""" with open(filepath) as r: - return "<pre>" + r.read() + "</pre>" - + readme = r.read() + if truncated: + return "<pre>" + "\n".join(readme.splitlines()[:5]) + "</pre>" + else: + return "<pre>" + readme + "</pre>" def overviewlogstring(ui, repo, revs, template=templates["commitlog"]): """Get the string for a log of the given revisions for the overview page.""" @@ -103,20 +106,24 @@ def overviewlogstring(ui, repo, revs, te def writeoverview(ui, repo, target, name): """Create the overview page""" overview = "" + # get the title overview += templates["head"].replace("{reponame}", name).replace("{title}", name) # add a short identifier from the first line of the readme, if it # exists # TODO: Parse different types of readme files readme = name for f in os.listdir(repo.root): if f.lower().startswith("readme"): - readme = parsereadme(f) - overview += "\n".join(readme.splitlines()[:5]) + readme = parsereadme(join(repo.root, f)) + readme_intro = parsereadme(join(repo.root, f), truncated=True) + overview += "<div id='intro'>" + overview += readme_intro + overview += "</div>" break # now the links to the log and the files. - overview += "</pre>\n<p><a href='commits'>changelog</a> | <a href='src/" + repo["tip"].hex() + "/'>files</a></p>" + overview += "\n<p id='nav'><a href='commits'>changelog</a> | <a href='src/" + repo["tip"].hex() + "/'>files</a></p>" # now add the 5 most recent log entries # divert all following ui output to a string, so we can just use standard functions - overview += "\n<h2>Changes (<a href='commits'>full changelog</a>)</h2>\n" + overview += "\n<div id='shortlog'><h2>Changes (<a href='commits'>full changelog</a>)</h2>\n" ui.pushbuffer() t = cmdutil.changeset_templater(ui, repo, patch=False, diffopts=None, mapfile=None, buffered=False) t.use_template(templates["commitlog"].replace("{relativepath}", "")) @@ -124,6 +131,7 @@ def writeoverview(ui, repo, target, name ctx = repo.changectx(str(-c)) t.show(ctx) overview += ui.popbuffer() + overview += "</div>" # Add branch, bookmark and tag information, if they exist. branches = [] @@ -140,7 +148,7 @@ def writeoverview(ui, repo, target, name except AttributeError: bookmarks = [] if branches: # add branches - overview += "\n<h2>Branches</h2>\n" + overview += "\n<div id='branches'><h2>Branches</h2>\n" overview += overviewlogstring(ui, repo, branches, template=templates["commitlog"].replace( "{branches}", "XXXXX").replace( @@ -149,24 +157,27 @@ def writeoverview(ui, repo, target, name "{tags}", "XXXXX").replace( "{date|shortdate}", "{tags}").replace( "XXXXX", "{date|shortdate}")) + overview += "</div>" if len(tags) > 1: - overview += "\n<h2>Tags</h2>\n" + overview += "\n<div id='tags'><h2>Tags</h2>\n" overview += overviewlogstring(ui, repo, [tags[t] for t in tags if t != "tip"], template=templates["commitlog"].replace( "{tags}", "XXXXX").replace( "{date|shortdate}", "{tags}").replace( "XXXXX", "{date|shortdate}")) + overview += "</div>" if len(bookmarks): - overview += "\n<h2>Bookmarks</h2>\n" + overview += "\n<div id='bookmarks'><h2>Bookmarks</h2>\n" overview += overviewlogstring(ui, repo, bookmarks.values(), template=templates["commitlog"].replace( "{bookmarks}", "XXXXX").replace( "{date|shortdate}", "{bookmarks}").replace( "XXXXX", "{date|shortdate}")) - + overview += "</div>" # add the full readme - overview += "<h2>"+_("Readme")+"</h2>\n" + overview += "<div id='readme'><h2>"+_("Readme")+"</h2>\n" overview += readme + overview += "</div>" # finish the overview overview += templates["foot"]