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
commander-stdout
sammyette 2022-12-20 01:38:19 -04:00
parent 78c95de784
commit b46bd0059e
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
6 changed files with 21 additions and 15 deletions

View File

@ -5,3 +5,4 @@ weight: -50
menu: docs
---
Hello!

View File

@ -0,0 +1 @@
hello!

View File

@ -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/<mod>/<mod>.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)
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
if subdocName == '_index' then
funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ')
end
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+: (.-)$'
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()