From 2828dcb6f0c43927ccf5a4c84e91e1a367bfd116 Mon Sep 17 00:00:00 2001 From: litlighilit Date: Sat, 22 Jun 2024 18:59:32 +0800 Subject: [PATCH] doc: add index for Lib --- src/pylib/Lib/index.nim | 9 +++++++ src/pylib/Lib/private/doc_utils/genIndex.nim | 25 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/pylib/Lib/index.nim create mode 100644 src/pylib/Lib/private/doc_utils/genIndex.nim diff --git a/src/pylib/Lib/index.nim b/src/pylib/Lib/index.nim new file mode 100644 index 000000000..423cfd11b --- /dev/null +++ b/src/pylib/Lib/index.nim @@ -0,0 +1,9 @@ +import ./private/doc_utils/genIndex +##[ +# Lib + +Python standard libraries +porting in nimpylib + +]## +genIndexHere() \ No newline at end of file diff --git a/src/pylib/Lib/private/doc_utils/genIndex.nim b/src/pylib/Lib/private/doc_utils/genIndex.nim new file mode 100644 index 000000000..a37aa531a --- /dev/null +++ b/src/pylib/Lib/private/doc_utils/genIndex.nim @@ -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)