-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Book: add links to commands #810
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this meticulous work! That really levels up the documentation!
Co-authored-by: Stefan Holderbach <[email protected]>
It was just a simple Python script + cleaning up (reverting the non-related changes). Although at its current state, it is hard to maintain. I suggest using a simple preprocessor step. In the source documentation use
and while building the documentation replace it wit
I can write the script in Python, if you are willing to port it to Rust or whatever you like to use. (I do not know Rust.) Also, I can convert the existing documentation to use this format if it helps you. |
I wonder if this type of cleanup 1) is available via the CI, or 2) should be done in nushell vs any other language? |
The preprocess step can be do, yes. I try to write it in Nushell if it is an available option. (You can run Nushell script in CI) The cleaning step for the existing documentation is manual work. I added the link to every |
(Update: unfortunately Nushell does not support closure for |
Let's run with this. Thanks! |
FYI: as an exercise, I wrote a preprocessor PoC (fully functional, not production-grade quality). def escape [] {(
$in
| str replace --all '🏀' '🏀0'
| str replace --all '🥎' '🏀1'
| str replace --all '⚽' '🏀2'
)}
def unescape [] {(
$in
| str replace --all '🏀2' '⚽'
| str replace --all '🏀1' '🥎'
| str replace --all '🏀0' '🏀'
)}
def handle-part [closure, part] {
let type = ($part | str substring '0,1')
let text = ($part | str substring '1,')
if $type == '1' { do $closure ($text | split row '⚽' | unescape) | escape} else { $text }
}
def 'str replace-closure' [pattern, closure] {(
'2' + $in
| escape
| str replace --all $pattern '🥎1$0⚽$1⚽$2⚽$3⚽$4⚽$5⚽$6⚽$7⚽$8⚽$9🥎2'
| split row '🥎'
| reduce --fold '' { |it, acc| $acc + (handle-part $closure $it) }
| unescape
)}
##########################################################################
let add_link = { |match|
let command = ($match.1 | str trim)
let filename = ($command | str replace --all ' ' '_') + '.md'
'[`' + $command + '`](/commands/docs/' + $filename + ')'
}
def preprocess_chapter [filepath] {
let filename = ($filepath | path basename)
echo $"Processing ($filename)"
open $filepath | str replace-closure '`command:(.*?)`' $add_link | save -f $"book-COMPILED/($filename)"
}
rm -rf book-COMPILED
mkdir book-COMPILED
ls book/*.md | get name | each { |it| preprocess_chapter $it } |
Discovered during 0.92.0 release
No description provided.