aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-05-20 15:43:38 +0000
committerNick Mathewson <nickm@torproject.org>2003-05-20 15:43:38 +0000
commit023a13db0f872156b098cff9e6005875ea368e3d (patch)
treea6b95d006a96815439232ddc934d87490f6ecd05
parentd7d3bf8a3a7413b71d39a12c357d07a47144d7e2 (diff)
downloadanonbib-023a13db0f872156b098cff9e6005875ea368e3d.tar.gz
Add BibTeX file, by-author listing
svn:r11
-rw-r--r--BibTeX.py107
-rw-r--r--_template_.html125
-rw-r--r--css/main.css6
-rw-r--r--css/pubs.css21
-rw-r--r--writeHTML.py81
5 files changed, 171 insertions, 169 deletions
diff --git a/BibTeX.py b/BibTeX.py
index 9b0d38c..f30e4ce 100644
--- a/BibTeX.py
+++ b/BibTeX.py
@@ -14,7 +14,14 @@ __all__ = ( 'ParseError', 'BibTeX', 'BibTeXEntry', 'htmlize',
MONTHS = [ None,
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]
-
+
+def url_untranslate(s):
+ s = s.replace(" ", "+")
+ s = re.sub(r'([%<>])',
+ lambda m: "%%%02x"%ord(m.group(1)),
+ s)
+ return s
+
class ParseError(Exception):
pass
@@ -84,6 +91,29 @@ def sortEntriesBy(entries, field, default):
tmp.sort()
return [ t[1] for t in tmp ]
+def splitEntriesByAuthor(entries):
+ entries = sortEntriesByDate(entries)
+ result = {} # Name in sorting order -> entries
+ htmlResult = {} # name in sorting order -> Full name
+ url_map = {} # Full name -> Url
+ for ent in entries:
+ for a in ent.parsedAuthor:
+ sortkey = txtize(" ".join(a.von+a.last+a.first+a.jr))
+ secname = " ".join(a.first+a.von+a.last)
+ if a.jr:
+ secname += ", "+a.jr
+ secname = htmlize(secname)
+ url = author_url(secname)
+ if url:
+ url_map[secname] = url
+
+ htmlResult[sortkey] = secname
+ result.setdefault(sortkey, []).append(ent)
+ sortnames = result.keys()
+ sortnames.sort()
+ sections = [ (htmlResult[n], result[n]) for n in sortnames ]
+ return sections, url_map
+
def sortEntriesByAuthor(entries):
tmp = []
for ent in entries:
@@ -131,7 +161,7 @@ class BibTeXEntry:
self.entries[k] = v
def __str__(self):
return self.format(70,1)
- def format(self, width=70,v=0):
+ def format(self, width=70, indent=8, v=0):
d = ["@%s{%s,\n" % (self.type, self.key)]
if v:
df = DISPLAYED_FIELDS[:]
@@ -145,8 +175,8 @@ class BibTeXEntry:
continue
v = self.entries[f]
d.append(" ")
- s = "%s = {%s}\n" % (f, v)
- d.append(_split(s,width))
+ s = "%s = {%s},\n" % (f, v)
+ d.append(_split(s,width,indent))
d.append("}\n")
return "".join(d)
def resolve(self):
@@ -259,10 +289,11 @@ class BibTeXEntry:
res[0:0] = ["<span class='biblio'>"]
res.append("</span>")
-
- res.append(" <span class='availability'>"
- "(<a href='__'>BibTeX&nbsp;entry</a>)"
- "</span>")
+
+ bibtexurl = "./bibtex.html#%s"%url_untranslate(self.key)
+ res.append((" <span class='availability'>"
+ "(<a href='%s'>BibTeX&nbsp;entry</a>)"
+ "</span>") %bibtexurl)
return htmlize("".join(res))
def to_html(self):
@@ -285,21 +316,8 @@ class BibTeXEntry:
res.append("<br><span class='author'>by ")
#res.append("\n<!-- %r -->\n" % self.parsedAuthor)
- htmlAuthors = []
- for author in self.parsedAuthor:
- f,v,l,j = author.first,author.von,author.last,author.jr
- a = " ".join(f+v+l)
- if j:
- a = "%s, %s" %(a,j)
- a = htmlize(a)
- htmlAuthor = None
- for pat, url in config.AUTHOR_RE_LIST:
- if pat.search(a):
- htmlAuthor = '<a href="%s">%s</a>' % (url, a)
- break
- if not htmlAuthor:
- htmlAuthor = a
- htmlAuthors.append(htmlAuthor)
+ htmlAuthors = [ htmlize_author(a) for a in self.parsedAuthor ]
+
if len(htmlAuthors) == 1:
res.append(htmlAuthors[0])
elif len(htmlAuthors) == 2:
@@ -319,8 +337,12 @@ class BibTeXEntry:
RE_LONE_AMP = re.compile(r'&([^a-z0-9])')
RE_LONE_I = re.compile(r'\\i([^a-z0-9])')
RE_ACCENT = re.compile(r'\\([\'`~^"])(.)')
-ACCENT_MAP = { "'": 'acute', "`" : 'grave', "~": 'tilde',
- "^": 'circ', '"' : 'uml' }
+ACCENT_MAP = { "'" : 'acute',
+ "`" : 'grave',
+ "~" : 'tilde',
+ "^" : 'circ',
+ '"' : 'uml',
+ }
RE_TEX_CMD = re.compile(r"(?:\\[a-zA-Z@]+|\\.)")
RE_PAGE_SPAN = re.compile(r"(\d)--(\d)")
def htmlize(s):
@@ -334,6 +356,25 @@ def htmlize(s):
s = RE_PAGE_SPAN.sub(lambda m: "%s-%s"%(m.groups()), s)
return s
+def htmlize_author(author):
+ f,v,l,j = author.first,author.von,author.last,author.jr
+ a = " ".join(f+v+l)
+ if j:
+ a = "%s, %s" %(a,j)
+ a = htmlize(a)
+ u = author_url(a)
+ if u:
+ return "<a href='%s'>%s</a>"%(u,a)
+ else:
+ return a
+ return a
+
+def author_url(author):
+ for pat, url in config.AUTHOR_RE_LIST:
+ if pat.search(author):
+ return url
+ return None
+
def txtize(s):
s = RE_LONE_I.sub(lambda m: "%s" % m.group(1), s)
s = RE_ACCENT.sub(lambda m: "%s" % m.group(2), s)
@@ -359,19 +400,25 @@ class ParsedAuthor:
def __str__(self):
return " ".join(self.first+self.von+self.last+self.jr)
-def _split(s,w=79):
+def _split(s,w=79,indent=8):
r = []
- s = s.replace("\n", " ")
+ s = re.sub(r"\s+", " ", s)
+ first = 1
+ indentation = ""
while len(s) > w:
for i in xrange(w-1, 0, -1):
if s[i] == ' ':
- r.append(s[:i])
+ r.append(indentation+s[:i])
s = s[i+1:]
break
else:
- r.append(s[:w])
+ r.append(indentation+s[:w])
s = s[w:]
- r.append(s)
+ if first:
+ first = 0
+ w -= indent
+ indentation = " "*indent
+ r.append(indentation+s)
r.append("")
return "\n".join(r)
diff --git a/_template_.html b/_template_.html
index ae9b05e..473fe4c 100644
--- a/_template_.html
+++ b/_template_.html
@@ -4,7 +4,7 @@
<meta http-equiv="Content-Style-Type" content="text/css">
<!-- *** I AM MACHINE GENERATED! DO NOT EDIT ME!
- -- *** EDIT THE .bib FILE INSTEAD!
+ -- *** EDIT THE .bib FILE or _template_.html INSTEAD!
--
-- Generated by `%(command_line)s'
-- (c) Eddie Kohler 1999-2000, Nick Mathewson 2003 -->
@@ -18,122 +18,26 @@
<body bgcolor="#ffffff" text="#000000" link="#bb0000" vlink="#990099"
alink="#ff9900" marginheight="0" marginwidth="0">
-<table cellspacing="0" cellpadding="0" border="0" align="center">
-
-<!--
-<tr valign="top">
-<td rowspan="5" width="134"><div align="right"><a href="/"><img
-src="/img/pdostab.gif" width="134" height="61" border="0"
-alt="PDOS Home"></a></div></td>
-<td rowspan="5" width="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
-width="1" height="1" alt=""></td>
-<td bgcolor="#ffffcc"><p><br></p></td>
-<td bgcolor="#ffffcc"><p><br></p></td>
-<td bgcolor="#ffffcc"><p><br></p></td>
-<td rowspan="3" width="8" bgcolor="#ffffcc"><img src="/img/emptydot.gif"
-width="8" height="1" alt=""></td>
-<td rowspan="3" width="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
-width="1" height="1" alt=""></td>
-</tr>
-
-<tr valign="top">
-<td bgcolor="#ffffcc"><p>&nbsp;&nbsp;<a href="http://web.mit.edu/">MIT</a>&nbsp;&gt;&nbsp;<a href="http://www.lcs.mit.edu/">LCS</a>&nbsp;&gt;&nbsp;<a href="/">PDOS&nbsp;Home</a>&nbsp;&gt;&nbsp;</p></td>
-<td bgcolor="#ffffcc"><p><b>Publications</b>&nbsp;&gt;&nbsp;</p></td>
-<td bgcolor="#ffffcc"><p><b>By&nbsp;subject</b></p></td>
-</tr>
-
-<tr valign="top">
-<td bgcolor="#ffffcc"><p><br></p></td>
-<td bgcolor="#ffffcc"><p class="crumbbreadth">
-<a href="projects.html">Projects</a><br>
-<a href="people.html">People</a><br>
-<a href="software.html">Software</a></p></td>
-<td bgcolor="#ffffcc"><p class="crumbbreadth">
-<a href="/cgi-bin/pubs-date.cgi">By date</a></p></td>
-</tr>
-
-<tr valign="top">
-<td colspan="2" height="8" bgcolor="#ffffcc"><img src="/img/emptydot.gif"
-width="1" height="8" alt=""></td>
-<td colspan="1" height="8" bgcolor="#ffffcc"><img src="/img/emptydot.gif"
-width="100" height="8" alt=""></td>
-<td colspan="2" rowspan="2" width="9" height="9" bgcolor="#ffffcc"><img
-src="/img/whitecorner.gif" width="9" height="9" alt=""></td>
-</tr>
-
-<tr valign="top">
-<td colspan="3" height="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
-width="1" height="1" alt=""></td>
-</tr>
-
-</table>
--->
-
<h1 align="center">Anonymity bibliography</h1>
<p align="center">%(choices)s</p>
-<table cellspacing="0" cellpadding="0" border="0" width="100">
-
-<tr valign="top">
-<td width="10%%" height="24"><br></td>
-</tr>
-
-<tr valign="top">
-<td><div align="right">
-<table cellspacing="0" cellpadding="0" border="0" width="161">
-
-<tr valign="top">
-<td rowspan="6" width="8"><img src="/img/emptydot.gif"
-width="8" height="1" alt=""></td>
-<td colspan="4" height="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
-width="1" height="1" alt=""></td>
-</tr>
-
-<tr valign="top">
-<td rowspan="5" width="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
-width="1" height="1" alt=""></td>
-
-<td width="8" bgcolor="#ccffff"><img src="/img/emptydot.gif"
-width="8" height="1" alt=""></td>
-<td rowspan="3" width="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
-width="1" height="1" alt=""></td>
-<td rowspan="3" width="12"><img src="/img/emptydot.gif"
-width="12" height="1" alt=""></td>
-</tr>
-
-<tr valign="top">
-<td colspan="2" height="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
-width="1" height="1" alt=""></td>
-</tr>
-
+<!-- Table 1: contains the sidebar and the body. -->
+<table cellspacing="3" cellpadding="0" border="0" align="center" width="100%%">
<tr valign="top">
-<td bgcolor="#ccffff"><p class="l1"><br><form action="/cgi-bin/pubs-date.cgi"
-method="get"><strong>%(sectiontypes)s:</strong><br>
+<td>
+<!-- Table 2: The sidebar-->
+<table align="right" cellspacing="0" cellpadding="5" width="100"
+ class="sidebar">
+<tr valign="top"><td><p
+class="l1"><strong>%(sectiontypes)s:</strong><br>
%(sections)s
-
</p></td>
-<td width="8" bgcolor="#ccffff"><img src="/img/emptydot.gif"
-width="8" height="1" alt=""></td>
-</tr>
-
-<tr valign="top">
-<td height="8" bgcolor="#ccffff"><img src="/img/emptydot.gif"
-width="1" height="8" alt=""></td>
-<td colspan="2" rowspan="2" width="9" height="9" bgcolor="#ccffff"><img
-src="/img/whitecorner.gif" width="9" height="9" alt=""></td>
-</tr>
-
-<tr valign="top">
-<td height="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
-width="1" height="1" alt=""></td>
-</tr>
-
-</table>
-</div></td>
+</table><!-- End of table 2 -->
+</td>
-<td width="75%%">
+<td width="85%%">
<h2>Publications by %(field)s</h2>
@@ -143,11 +47,10 @@ width="1" height="1" alt=""></td>
</td>
-<td width="15%%"><br></td>
+<td width="5%%"><br></td>
</tr>
-</table>
+</table><!-- End of table 1 -->
</body>
</html>
-
diff --git a/css/main.css b/css/main.css
index e874ca4..8b336c9 100644
--- a/css/main.css
+++ b/css/main.css
@@ -77,9 +77,13 @@ H1 A, H2 A, H3 A, H4 A, H5 A, H6 A {
}
H1 {
- color: #338;
+ color: #00B;
}
H2 {
color: #006;
}
+
+H3 {
+ color: #006;
+}
diff --git a/css/pubs.css b/css/pubs.css
index 7281a1d..971616e 100644
--- a/css/pubs.css
+++ b/css/pubs.css
@@ -41,3 +41,24 @@ P.l2 {
margin-top: 0.3em;
margin-bottom: 0.3em;
}
+
+TABLE.sidebar {
+ border-width: 2;
+ border-color: black;
+ border-style: solid;
+ background-color: #CFF;
+}
+
+TD.bibtex {
+ font-family: lucidatypewriter, "Lucida Typewriter", Monaco, "Lucida Sans Unicode", monospace;
+ border-width: 2;
+ font-weight: normal;
+ border-color: black;
+ border-style: solid;
+ background-color: #DFF;
+}
+
+PRE.bibtex {
+ font-family: lucidatypewriter, "Lucida Typewriter", Monaco, "Lucida Sans Unicode", monospace;
+ font-size: smaller;
+}
diff --git a/writeHTML.py b/writeHTML.py
index 8037abd..2ffd7c7 100644
--- a/writeHTML.py
+++ b/writeHTML.py
@@ -5,36 +5,30 @@ import re
import BibTeX
import config
-TEMPLATE_S, TEMPLATE_E = None, None
+def getTemplate(name):
+ f = open(name+".html")
+ template = f.read()
+ f.close()
+ template_s, template_e = template.split("%(entries)s")
+ return template_s, template_e
-def getTemplate():
- global TEMPLATE_S
- global TEMPLATE_E
- if not TEMPLATE_S:
- f = open("_template_.html")
- template = f.read()
- f.close()
- TEMPLATE_S, TEMPLATE_E = template.split("%(entries)s")
- return TEMPLATE_S, TEMPLATE_E
-
-def url_untranslate(s):
- s = s.replace(" ", "+")
- s = re.sub(r'([%<>])',
- lambda m: "%%%02x"%ord(m.group(1)),
- s)
- return s
-
-def writeBody(f, sections):
+def writeBody(f, sections, section_urls):
'''f: an open file
sections: list of (sectionname, [list of BibTeXEntry])'''
for s, entries in sections:
- print >>f, ('<h2><a name="%s">%s</a></h2>'%(url_untranslate(s),s))
+ u = section_urls.get(s)
+ if u:
+ print >>f, ('<h3><a name="%s"><a href="%s">%s</a></a></h3>'%(
+ u, BibTeX.url_untranslate(s),s))
+ else:
+ print >>f, ('<h3><a name="%s">%s</a></h3>'%(
+ BibTeX.url_untranslate(s),s))
print >>f, "<ul class='expand'>"
for e in entries:
print >>f, e.to_html()
print >>f, "</ul>"
-def writeHTML(f, sections, sectionType, fieldName, choices):
+def writeHTML(f, sections, sectionType, fieldName, choices, section_urls={}):
"""sections: list of (sectionname, [list of BibTeXEntry])'''
sectionType: str
fieldName: str
@@ -43,7 +37,7 @@ def writeHTML(f, sections, sectionType, fieldName, choices):
secStr = []
for s, _ in sections:
secStr.append("<p class='l2'><a href='#%s'>%s</a></p>\n"%
- ((url_untranslate(s),s)))
+ ((BibTeX.url_untranslate(s),s)))
secStr = "".join(secStr)
#
@@ -63,9 +57,9 @@ def writeHTML(f, sections, sectionType, fieldName, choices):
'sections' : secStr,
}
- header, footer = getTemplate()
+ header, footer = getTemplate("_template_")
print >>f, header%fields
- writeBody(f, sections)
+ writeBody(f, sections, section_urls)
print >>f, footer%fields
bib = BibTeX.parseFile(config.MASTER_BIB)
@@ -86,7 +80,9 @@ entries = [ (s, BibTeX.sortEntriesByAuthor(ents))
f = open("topic.html", 'w')
writeHTML(f, entries, "Topics", "topic",
(("By topic", None),
- ("By date", "./date.html")))
+ ("By date", "./date.html"),
+ ("By author", "./author.html")
+ ))
f.close()
## By date.
@@ -107,7 +103,38 @@ if entries[-1][0] == 'Unknown':
f = open("date.html", 'w')
writeHTML(f, entries, "Years", "date",
(("By topic", "./topic.html"),
- ("By date", None)))
+ ("By date", None),
+ ("By author", "./author.html")
+ ))
+f.close()
+
+## By author
+entries, url_map = BibTeX.splitEntriesByAuthor(bib.entries)
+
+f = open("author.html", 'w')
+writeHTML(f, entries, "Authors", "author",
+ (("By topic", "./topic.html"),
+ ("By date", "./date.html"),
+ ("By author", None),
+ ),
+ url_map)
+f.close()
+
+## The big BibTeX file
+
+entries = bib.entries[:]
+entries = [ (ent.key, ent) for ent in entries ]
+entries.sort()
+entries = [ ent[1] for ent in entries ]
+header,footer = getTemplate("_template_bibtex")
+f = open("bibtex.html", 'w')
+print >>f, header % { 'command_line' : "" }
+for ent in entries:
+ print >>f, (
+ ("<tr><td class='bibtex'><a name='%s'>%s</a>"
+ "<pre class='bibtex'>%s</pre></td></tr>")
+ %(BibTeX.url_untranslate(ent.key), ent.key, ent.format(90,8,1)))
+ ##print >>f, "<p><pre>%s</pre></p>" % ent.format(80,1)
+print >>f, footer
f.close()
-## The big BibTeX