Permalink
Browse files

Have buildNotesList.py walk the directory tree, adding md files in su…

…bdirectories.
  • Loading branch information...
1 parent d01c7d4 commit db361359b8ed329c0f781b7bf7f024e4f701ed2c @drdrang committed Feb 10, 2010
Showing with 118 additions and 25 deletions.
  1. +9 −0 Lab/testing1.md
  2. +59 −0 aa-overview.html
  3. +47 −25 buildNotesList.py
  4. +3 −0 notesList.js
View
@@ -0,0 +1,9 @@
+# January 1, 2010 tests #
+
+Just a simple list:
+
+* Did this
+* Did that
+* Did something else
+
+And there'd probably be some conclusions.
View
@@ -0,0 +1,59 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+ <title>Project Name (9999)</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" type="text/css" media="all" href="notes.css" />
+ <link rel="stylesheet" type="text/css" media="print" href="notes-print.css" />
+ <script type="text/javascript" src="file:///Users/drang/Library/JavaScript/jsMath/easy/load.js"></script>
+ <script type="text/javascript" src="styleLineNumbers.js"></script>
+ <script type="text/javascript" src="notesList.js"></script>
+</head>
+<body onload="styleLN()">
+ <div id="container">
+ <div id="title">
+ <h1 class="left">Project Name</h1>
+ <h1 class="right">9999</h1>
+ </div> <!-- title -->
+ <div id="sidebar">
+ <h1>Project notes:</h1>
+ <ul>
+ <script type="text/javascript">showNotesList()</script>
+ </ul>
+ <hr />
+ <h1>Contacts:</h1>
+ <ul>
+ <li><a href="addressbook://A1A2AA41-FA30-40AE-9925-FD6DB270B0A5%3AABPerson">Apple</a></li>
+ </ul>
+ <hr />
+ <h1>Source:</h1>
+ <ul>
+ <li><a href="txmt://open?url=file:///Users/mark/notes/aa-overview.md">Edit in TextMate</a></li>
+ <li>Last modified<br />
+ &nbsp;June 25, 2008<br />
+ &nbsp;at 9:27 AM</li>
+ </ul>
+ <hr />
+ <ul>
+ <li><a href="txmt://open?url=file:///Users/mark/notes/project.info">Edit project info</a></li>
+ </ul>
+ </div> <!-- sidebar -->
+
+ <div id="note"><h1 id="overview">Overview</h1>
+
+<h2 id="background">Background</h2>
+
+<p>This is where I describe the project.</p>
+
+<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
+<hr />
+<p class="info">
+ Source: <a href="txmt://open?url=file:///Users/mark/notes/aa-overview.md">/Users/mark/notes/aa-overview.md</a><br />
+ Last modified: June 25, 2008 at 9:27 AM<br />
+ <!-- This page built: $buildtime -->
+</p>
+</div> <!-- note -->
+</div> <!-- container -->
+</body>
+</html>
View
@@ -4,32 +4,54 @@
# Get the titles of all the notes files in the directory. The
# title is assumed to be the first line of the file. Truncate
-# the title at a word boundary if it's longer than maxlength.
-# Print out a JavaScript function that will write an HTML list
-# of the notes files.
+# the title at a word boundary if it's longer than maxlength,
+# and turn it into a link in a list item.
+def nameList(dir):
+ fileLI = []
+ maxlength = 35
+ allFiles = os.listdir(dir)
+ baseNames = [ f[:-3] for f in allFiles if f[-3:] == '.md' ]
+ # print baseNames
+ for fn in baseNames:
+ f = file(os.path.join(d, fn + '.md'))
+ top = f.readline()
+ title = top.strip('# \n')
+ if len(title) > maxlength:
+ words = title.split()
+ twords = []
+ count = 0
+ for w in words:
+ if count + len(w) > maxlength:
+ break
+ else:
+ twords.append(w)
+ count += len(w) + 1
+ title = ' '.join(twords) + "&#8230;"
+ f.close()
+ fileLI.append('<li><a href="%s.html">%s</a></li>' % (os.path.join(d, fn),title))
+ return fileLI
-fileLI = []
-maxlength = 35
-allFiles = os.listdir('.')
-baseNames = [ f[:-3] for f in allFiles if f[-3:] == '.md' ]
-for fn in baseNames:
- f = file(fn + '.md')
- top = f.readline()
- title = top.strip('# \n')
- if len(title) > maxlength:
- words = title.split()
- twords = []
- count = 0
- for w in words:
- if count + len(w) > maxlength:
- break
- else:
- twords.append(w)
- count += len(w) + 1
- title = ' '.join(twords) + "&#8230;"
- fileLI.append('<li><a href="%s.html">%s</a></li>' % (fn,title))
- f.close()
+# Find all the directories that have md files.
+mdDirs = []
+for root, dirs, files in os.walk('.'):
+ for f in files:
+ if f[-3:] == '.md':
+ mdDirs.append(root)
+ break
+
+# Go through the directories and generate the list of links.
+linkList = []
+for d in mdDirs:
+ if d == '.':
+ linkList += nameList(d)
+ # print linkList
+ else:
+ linkList += ['<li>%s' % d[2:], '<ul>']
+ # print linkList
+ linkList += nameList(d)
+ # print linkList
+ linkList += ['</ul>', '</li>']
print '''function showNotesList(){
document.write('%s')
-}''' % ' '.join(fileLI)
+}''' % ''.join(linkList)
View
@@ -0,0 +1,3 @@
+function showNotesList(){
+ document.write('<li><a href="./aa-overview.html">Overview</a></li><li>Lab<ul><li><a href="./Lab/testing1.html">January 1, 2010 tests</a></li></ul></li>')
+}

0 comments on commit db36135

Please sign in to comment.