From b46bd0059e241e4896a4f22fb020189eeaf3cc29 Mon Sep 17 00:00:00 2001 From: sammyette Date: Tue, 20 Dec 2022 01:38:19 -0400 Subject: [PATCH] fix: fixes for doc command - get docs properly for hilbish module and its interfaces - deal with negative numbers causing yaml metadata parsing to fail - change from index to _index to match hugo --- docs/api/_index.md | 1 + docs/api/index.md | 1 + docs/hooks/{index.md => _index.md} | 0 docs/nature/{index.md => _index.md} | 0 docs/vim-mode/{index.md => _index.md} | 0 nature/commands/doc.lua | 34 +++++++++++++++------------ 6 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 docs/api/index.md rename docs/hooks/{index.md => _index.md} (100%) rename docs/nature/{index.md => _index.md} (100%) rename docs/vim-mode/{index.md => _index.md} (100%) diff --git a/docs/api/_index.md b/docs/api/_index.md index 5c8b722..26f47ac 100644 --- a/docs/api/_index.md +++ b/docs/api/_index.md @@ -5,3 +5,4 @@ weight: -50 menu: docs --- +Hello! diff --git a/docs/api/index.md b/docs/api/index.md new file mode 100644 index 0000000..4effa19 --- /dev/null +++ b/docs/api/index.md @@ -0,0 +1 @@ +hello! diff --git a/docs/hooks/index.md b/docs/hooks/_index.md similarity index 100% rename from docs/hooks/index.md rename to docs/hooks/_index.md diff --git a/docs/nature/index.md b/docs/nature/_index.md similarity index 100% rename from docs/nature/index.md rename to docs/nature/_index.md diff --git a/docs/vim-mode/index.md b/docs/vim-mode/_index.md similarity index 100% rename from docs/vim-mode/index.md rename to docs/vim-mode/_index.md diff --git a/nature/commands/doc.lua b/nature/commands/doc.lua index bc16dfe..6ec91e5 100644 --- a/nature/commands/doc.lua +++ b/nature/commands/doc.lua @@ -15,32 +15,34 @@ commander.register('doc', function(args) local f = io.open(moddocPath .. mod .. '.md', 'rb') local funcdocs = nil + local subdocName = args[2] if not f then -- assume subdir -- dataDir/docs//.md moddocPath = moddocPath .. mod .. '/' - local subdocName = args[2] if not subdocName then - subdocName = 'index' + subdocName = '_index' end f = io.open(moddocPath .. subdocName .. '.md', 'rb') + if not f then + moddocPath = moddocPath .. subdocName .. '/' + local subsubDocName = args[3] or '_index' + f = io.open(moddocPath .. subsubDocName .. '.md', 'rb') + end if not f then print('No documentation found for ' .. mod .. '.') return end - funcdocs = f:read '*a' - local moddocs = table.filter(fs.readdir(moddocPath), function(f) return f ~= 'index.md' end) - local subdocs = table.map(moddocs, function(fname) - return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.md', ''))) - end) - if subdocName == 'index' then - funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ') - end + end + funcdocs = f:read '*a':gsub('-([%d]+)', '%1') + local moddocs = table.filter(fs.readdir(moddocPath), function(f) return f ~= '_index.md' end) + local subdocs = table.map(moddocs, function(fname) + return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.md', ''))) + end) + if subdocName == '_index' then + funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ') end - if not funcdocs then - funcdocs = f:read '*a' - end local valsStr = funcdocs:match '%-%-%-\n([^%-%-%-]+)\n' local vals = {} if valsStr then @@ -53,11 +55,13 @@ commander.register('doc', function(args) local key = line:match '(%w+): ' local val = line:match '^%w+: (.-)$' - vals[key] = val + if key then + vals[key] = val + end end end if mod == 'api' then - funcdocs = string.format(apidocHeader, vals.name, vals.description) .. funcdocs + funcdocs = string.format(apidocHeader, vals.title, vals.description or 'no description.') .. funcdocs end local backtickOccurence = 0 local formattedFuncs = lunacolors.format(funcdocs:sub(1, #funcdocs - 1):gsub('`', function()