From 41cf2d5113b18160f17df2575509808ea4cd09a8 Mon Sep 17 00:00:00 2001 From: Zoom Date: Sat, 3 Jun 2023 01:56:11 +0500 Subject: [PATCH] Hide the `scripts` dir from the project's site --- {scripts => .scripts}/directory.nim | 11 +++++------ config.nims | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) rename {scripts => .scripts}/directory.nim (90%) diff --git a/scripts/directory.nim b/.scripts/directory.nim similarity index 90% rename from scripts/directory.nim rename to .scripts/directory.nim index a6572e3b..a6e344c5 100644 --- a/scripts/directory.nim +++ b/.scripts/directory.nim @@ -2,12 +2,12 @@ ## ## # Usage: ## * Navigate to repo's root directory -## * Execute and save the output: `nim r scripts/directory.nim > DIRECTORY.md` +## * Execute and save the output: `nim r .scripts/directory.nim > DIRECTORY.md` ## * Check the changes: `git diff directory.md` ## ## # Overview: ## - Walks the current directory for subdirectories. -## - Each directory is treated as a category. +## - Each subdirectory (but not the root) is treated as a category. ## - The title of the category is inferred from the subdir's name. ## - Walks .nim source files in each subdirectory, non-recursively. ## - Looks for algorithms's title on the first line of the file when it's a @@ -24,7 +24,6 @@ const WhitespaceUC = toRunes("_\t\n\x0b\x0c\r\x1c\x1d\x1e\x1f \x85\xa0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000") Warning = "\n" Header = "# The Algorithms — Nim: Directory Hierarchy\n" - IgnoreSubDirs = ["scripts"] type ## TODO: Allow nested structure with variant type [Directory | CritBitTree[string]] @@ -49,7 +48,7 @@ proc extractTitle(s, fpath: string): Option[string] = if s.len > 0: some(s) else: none(string) else: - stderr.writeLine(&"\u26A0: \"{fpath}\". First line is not a doc comment! Deriving title from a file name.") + stderr.writeLine(&"\u26A0: \"{fpath}\". First line is not a doc comment! Deriving title from the file name.") none(string) proc readLn(fpath: string): Option[string] = @@ -68,7 +67,7 @@ proc collectDirectory(dir = ""): Directory = ## Walks the subdirectories of `dir` non-recursively, collects `.nim` files ## and their titles into a sorted structure. Dotfiles are skipped. for (pc, path) in walkDir(dir, relative = true): - if pc == pcDir and path[0] != '.' and path notin IgnoreSubDirs: + if pc == pcDir and path[0] != '.': var categoryDir: CritBitTree[string] for (pc, fname) in walkDir(path, relative = true): if pc == pcFile and fname[0] != '.': @@ -76,7 +75,7 @@ proc collectDirectory(dir = ""): Directory = let fpath = path / fname if ext == ".nim": # if can't read the title from the source, derive from the file name - let title = readLn(fpath).get(name.changeFileExt("").canonicalize()) + let title = readLn(fpath).get(name.canonicalize()) categoryDir[title] = fname if categoryDir.len > 0: result[path] = categoryDir diff --git a/config.nims b/config.nims index 4cec23c5..f5e70776 100644 --- a/config.nims +++ b/config.nims @@ -15,7 +15,7 @@ import std/[os, sequtils] from std/strutils import startsWith, endsWith from std/strformat import `&` -const IgnorePathPrefixes = [".", "scripts"] +const IgnorePathPrefixes = ["."] func isIgnored(path: string): bool = IgnorePathPrefixes.mapIt(path.startsWith(it)).anyIt(it)