mirror of https://github.com/Hilbis/Hilbish
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 hugocommander-stdout
parent
78c95de784
commit
b46bd0059e
|
@ -5,3 +5,4 @@ weight: -50
|
||||||
menu: docs
|
menu: docs
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Hello!
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
hello!
|
|
@ -15,32 +15,34 @@ commander.register('doc', function(args)
|
||||||
|
|
||||||
local f = io.open(moddocPath .. mod .. '.md', 'rb')
|
local f = io.open(moddocPath .. mod .. '.md', 'rb')
|
||||||
local funcdocs = nil
|
local funcdocs = nil
|
||||||
|
local subdocName = args[2]
|
||||||
if not f then
|
if not f then
|
||||||
-- assume subdir
|
-- assume subdir
|
||||||
-- dataDir/docs/<mod>/<mod>.md
|
-- dataDir/docs/<mod>/<mod>.md
|
||||||
moddocPath = moddocPath .. mod .. '/'
|
moddocPath = moddocPath .. mod .. '/'
|
||||||
local subdocName = args[2]
|
|
||||||
if not subdocName then
|
if not subdocName then
|
||||||
subdocName = 'index'
|
subdocName = '_index'
|
||||||
end
|
end
|
||||||
f = io.open(moddocPath .. subdocName .. '.md', 'rb')
|
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
|
if not f then
|
||||||
print('No documentation found for ' .. mod .. '.')
|
print('No documentation found for ' .. mod .. '.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
funcdocs = f:read '*a'
|
end
|
||||||
local moddocs = table.filter(fs.readdir(moddocPath), function(f) return f ~= 'index.md' end)
|
funcdocs = f:read '*a':gsub('-([%d]+)', '%1')
|
||||||
local subdocs = table.map(moddocs, function(fname)
|
local moddocs = table.filter(fs.readdir(moddocPath), function(f) return f ~= '_index.md' end)
|
||||||
return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.md', '')))
|
local subdocs = table.map(moddocs, function(fname)
|
||||||
end)
|
return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.md', '')))
|
||||||
if subdocName == 'index' then
|
end)
|
||||||
funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ')
|
if subdocName == '_index' then
|
||||||
end
|
funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ')
|
||||||
end
|
end
|
||||||
|
|
||||||
if not funcdocs then
|
|
||||||
funcdocs = f:read '*a'
|
|
||||||
end
|
|
||||||
local valsStr = funcdocs:match '%-%-%-\n([^%-%-%-]+)\n'
|
local valsStr = funcdocs:match '%-%-%-\n([^%-%-%-]+)\n'
|
||||||
local vals = {}
|
local vals = {}
|
||||||
if valsStr then
|
if valsStr then
|
||||||
|
@ -53,11 +55,13 @@ commander.register('doc', function(args)
|
||||||
local key = line:match '(%w+): '
|
local key = line:match '(%w+): '
|
||||||
local val = line:match '^%w+: (.-)$'
|
local val = line:match '^%w+: (.-)$'
|
||||||
|
|
||||||
vals[key] = val
|
if key then
|
||||||
|
vals[key] = val
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if mod == 'api' then
|
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
|
end
|
||||||
local backtickOccurence = 0
|
local backtickOccurence = 0
|
||||||
local formattedFuncs = lunacolors.format(funcdocs:sub(1, #funcdocs - 1):gsub('`', function()
|
local formattedFuncs = lunacolors.format(funcdocs:sub(1, #funcdocs - 1):gsub('`', function()
|
||||||
|
|
Loading…
Reference in New Issue