2 个版本
0.1.1 | 2024年2月5日 |
---|---|
0.1.0 | 2023年12月18日 |
#329 in 文件系统
235KB
278 行
mdbook-tools
mdbook-tools
是一个灵活的命令行工具,用于组织文件和创建 mdBooks。结合 mdbook-tools
和 mdbook
允许您将文档直接嵌入到项目结构中,或维护一组完全独立的文档或笔记。结果是您可以生成和维护简洁的书籍。
使用 mdbook-tools 维护笔记的示例
对于类似以下的目录结构
...
├── python
│ ├── 01_venv.md
│ ├── 02_pip_vs_python_-m_pip.md
│ ├── 03_venv.md
│ ...
│ └── README.md
├── rust
│ ├── 01_borrowing_and_ownership.md
│ ├── 02_references_and_pointers.md
│ ├── 03_lifetimes.md
│ ├── 04_cargo.md
│ ├── 05_print_and_format.md
│ ├── 06_pinning,_moving_(&_memory),_copying.md
│ ├── 07_tokio.md
│ ├── 08_tower.md
│ ...
│ └── README.md
...
运行
mdbook-tools summary --include-unnumbered-directories
mdbook serve
将给出:
命令行预览
mdbook tools for organizing books.
Usage: mdbook-tools <COMMAND>
Commands:
summary
The 'summary' command automates the generation of a structured summary file.
It sequentially reads numbered md files and directories (e.g., "0001_") to define their order in the summary.
If any md files or directories do not have a number, they are ignored by default.
Directories use their 'README.md' file to define their content in the summary. As such, directories without a 'README.md' are ignored,
but the descendants are still searched.
Numbering resets for each directory, reflecting their hierarchical structure in the summary.
'README.md' files are exempt from numbering.
Section headers are created by removing underscores and capitalizing the first letter of each word.
Section names exclude numeric prefixes.
mv
The 'mv' command facilitates reorganizing md files or directories within the book's structure.
It allows moving a file or directory to a specified position (index) in a different directory.
The index numbering starts at 1, with 'README.md' is exempt.
When a file is moved to an occupied index, the existing file or directory, and those following it,
are automatically shifted down to accommodate the new file or directory, and the original directory is updated as well.
Summary is not updated.
re-order
Re-orders all the existing files in the path. Any gaps in the current order are collapsed and the new level is applied.
e.g. ["001_..", "003_.."] for level 2 becomes ["01_", "02_"].
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
迁移到 mdtools-tools 的有用 Bash 命令
将文件和目录(包括子目录)名称中的所有空格替换为下划线
find . -depth -name '* *' -execdir bash -c 'mv "$1" "${1// /_}"' bash {} \;
递归地将每个文件和目录重命名为其小写等效项
find . -depth -exec bash -c '
for item; do
dir=$(dirname "$item")
base=$(basename "$item")
lower=$(echo "$base" | tr '[:upper:]' '[:lower:]')
if [ "$base" != "$lower" ]; then
mv -T "$item" "$dir/$lower"
fi
done
' bash {} +
依赖关系
~1.3–2MB
~37K SLoC