|
36 | 36 | ("Server", "服务端", "Server", "Java / 数据库 / 中间件 / 运维(规划中)", "🗄️"), |
37 | 37 | ] |
38 | 38 |
|
| 39 | +# 自动发现额外技术域:根目录下未被上面声明、但确实含有 .md 的目录, |
| 40 | +# 会自动补充为一个技术域,这样以后新增 Python/、Rust/ 等顶层目录无需改脚本。 |
| 41 | +_ROOT_SKIP = {"scripts", "docs", "node_modules", "assets"} |
| 42 | +_MANUAL_DOMAINS = list(DOMAINS) |
| 43 | + |
| 44 | + |
| 45 | +def _discover_domains(): |
| 46 | + known = {d[0] for d in _MANUAL_DOMAINS} |
| 47 | + try: |
| 48 | + entries = sorted(os.listdir(ROOT)) |
| 49 | + except OSError: |
| 50 | + return list(_MANUAL_DOMAINS) |
| 51 | + |
| 52 | + found = [] |
| 53 | + for name in entries: |
| 54 | + if name in known or name in _ROOT_SKIP or name.startswith("."): |
| 55 | + continue |
| 56 | + path = os.path.join(ROOT, name) |
| 57 | + if not os.path.isdir(path): |
| 58 | + continue |
| 59 | + if not any(f.endswith(".md") for _, _, fs in os.walk(path) for f in fs): |
| 60 | + continue |
| 61 | + # 用该目录 README.md 的一级标题作为显示名,取不到就退化为目录名 |
| 62 | + label = name |
| 63 | + readme = os.path.join(path, "README.md") |
| 64 | + if os.path.isfile(readme): |
| 65 | + try: |
| 66 | + with open(readme, encoding="utf-8", errors="ignore") as fh: |
| 67 | + for line in fh: |
| 68 | + s = line.strip() |
| 69 | + if s.startswith("# "): |
| 70 | + label = s[2:].strip() or name |
| 71 | + break |
| 72 | + if s and not s.startswith("#"): |
| 73 | + break |
| 74 | + except OSError: |
| 75 | + pass |
| 76 | + found.append((name, label, name, f"{label} 相关笔记", "📄")) |
| 77 | + return list(_MANUAL_DOMAINS) + found |
| 78 | + |
| 79 | + |
| 80 | +DOMAINS = _discover_domains() |
| 81 | + |
39 | 82 | ANDROID_ORDER = [ |
40 | 83 | "BasicKnowledge", "AdavancedPart", "SourceAnalysis", "VideoDevelopment", |
41 | 84 | "Jetpack", "KotlinCourse", "Dagger2", "ImageLoaderLibrary", "RxJavaPart", |
|
0 commit comments