Skip to content

Commit

Permalink
doc: add index for Lib
Browse files Browse the repository at this point in the history
  • Loading branch information
litlighilit committed Jun 22, 2024
1 parent 6a172cf commit 2828dcb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pylib/Lib/index.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ./private/doc_utils/genIndex
##[
# Lib
Python standard libraries
porting in nimpylib
]##
genIndexHere()
25 changes: 25 additions & 0 deletions src/pylib/Lib/private/doc_utils/genIndex.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import std/macros
import std/strutils
import std/os

proc nimpylibLibFilter*(t: tuple[kind: PathComponent, path: string]): bool =
t.kind != pcDir and t.kind != pcLinkToDir and
t.path != "index.nim" and
not t.path.endsWith"_impl" and
not t.path.startsWith"n_"

type PathFilter* = typeof nimpylibLibFilter ## path is relative

proc indexAsMdStr*(dir: string, filter=nimpylibLibFilter): string =
for t in dir.walkDir(relative=true):
if filter(t):
let
fn = t.path
libn = fn.changeFileExt("")
url = fn.changeFileExt("html")
result.add "- [$#]($#)\n".format(libn, url)


macro genIndexHere*(filter: static[PathFilter] = nimpylibLibFilter) =
newCommentStmtNode indexAsMdStr(getProjectPath(), filter)

0 comments on commit 2828dcb

Please sign in to comment.