Browse Source

added sub-headings to toc for single-page mode

Casey DeLorme 10 years ago
parent
commit
e7788347c7
1 changed files with 10 additions and 0 deletions
  1. 10 0
      staticmd.go

+ 10 - 0
staticmd.go

@@ -211,6 +211,8 @@ func (staticmd *Staticmd) Single() {
 	// prepare a table-of-contents
 	toc := "\n"
 
+	previous_depth := 0
+
 	// iterate and append all files contents
 	for _, p := range staticmd.Pages {
 
@@ -220,6 +222,11 @@ func (staticmd *Staticmd) Single() {
 		// acquire depth
 		depth := strings.Count(shorthand, string(os.PathSeparator))
 
+		// if depth > previous depth then prepend with basename of dir for sub-section-headings
+		if depth > previous_depth {
+			toc = toc + strings.Repeat("\t", depth-1) + "- " + basename(filepath.Dir(p)) + "\n"
+		}
+
 		// prepare anchor text
 		anchor := strings.Replace(shorthand, string(os.PathSeparator), "-", -1)
 
@@ -241,6 +248,9 @@ func (staticmd *Staticmd) Single() {
 
 		// append to content
 		content = append(content, markdown...)
+
+		// update depth
+		previous_depth = depth
 	}
 
 	// prepend toc