From d7785d9d75ed6923b9f2f22f41e24db9cea3c720 Mon Sep 17 00:00:00 2001
From: Daniel Barlow <dan@telent.net>
Date: Sat, 12 Aug 2023 20:49:16 +0100
Subject: [PATCH] if no preamble, print module pathname as headline

this was supposed to work already but was broken
---
 doc/parse-options.fnl | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/doc/parse-options.fnl b/doc/parse-options.fnl
index 40c8aca..076c43d 100644
--- a/doc/parse-options.fnl
+++ b/doc/parse-options.fnl
@@ -3,10 +3,9 @@
 (local { : view } (require :fennel))
 
 (fn headline [name]
-  (let [(_ _ basename) (string.find name ".*/([^/].*)")
+  (let [(_ _ basename) (string.find name ".*/([^/].*).nix")
         len (basename:len)]
-    (print basename)
-    (print (string.rep "=" len))))
+    (.. basename "\n" (string.rep "=" len))))
 
 (fn read-preamble [pathname]
   (if (= (pathname:sub 1 1) "/")
@@ -14,10 +13,10 @@
                          pathname
                          (.. pathname "/default.nix"))]
         (with-open [f (assert (io.open pathname :r))]
-          (accumulate [lines ""
+          (accumulate [lines nil
                        l (f:lines)
                        :until (not (= (string.sub l 1 2) "##"))]
-            (.. lines (string.gsub l "^## *" "") "\n"))))))
+            (.. (or lines "") (string.gsub l "^## *" "") "\n"))))))
 
 (fn strip-newlines [text]
   (-> text