Skip to content

Commit

Permalink
feat(docs): update documentation generation script and titles
Browse files Browse the repository at this point in the history
The documentation generation script now accepts language as an input
parameter and defaults the output directory to the current directory if
not specified. The script also handles different link remapping based on
the language. Additionally, the titles of FAQ and configuration pages
have been updated for better clarity.
  • Loading branch information
wangl-cc committed Apr 21, 2024
1 parent dede363 commit 6d5b136
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion maa-cli/docs/en-US/faq.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FAQ
# FAQs for maa-cli

## 1. How to use `$HOME/.config/maa` as the configuration directory on macOS?

Expand Down
65 changes: 34 additions & 31 deletions maa-cli/docs/gen_docs.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash
# generate documentation used in main repo of MAA

# output to the specified directory
output_dir=$1
# language of the documentation
lang=$1
# output to the specified directory, default is the current directory
output_dir=${2:-"."}
# the original directory of docs is at the same directory as this script
original_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)

original_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)

files=(
intro.md
Expand All @@ -16,37 +17,39 @@ files=(
)

icons=(
material-symbols:summarize
material-symbols:toc
material-symbols:download
material-symbols:format_list_bulleted
material-symbols:summarize
material-symbols:settings
ph:question-fill
)

# walk through all subdirectories of each language
for lang in "$original_dir"/zh-CN; do
echo "Generating documentation for $lang"
order=0
for filename in "${files[@]}"; do
echo "-> Generating documentation for $filename"
file="$lang/$filename"
index=$order
order=$((order+1))
out_file="$output_dir/cli-$filename"
# insert metadata of markdown file to the beginning of the file
{
echo "---"
echo "order: $order"
echo "icon: ${icons[$index]}"
echo "---"
echo
cat "$file"
} > "$out_file"
# remap some links to the original repo
sed -I '' -E 's|\.\./\.\./|https://github.com/MaaAssistantArknights/maa-cli/blob/main/maa-cli/|g' "$out_file"
sed -I '' -E 's|https://maa\.plus/docs/(.+)\.html|../../\1.md|g' "$out_file"
for filename_md in "${files[@]}"; do
sed -i '' -E "s|$filename_md|cli-$filename_md|g" "$out_file"
done
echo "Generating documentation for $lang"
order=0
for filename in "${files[@]}"; do
echo "-> Generating documentation for $filename"
file="$original_dir/$lang/$filename"
index=$order
order=$((order+1))
out_file="$output_dir/cli-$filename"
# insert metadata of markdown file to the beginning of the file
{
echo "---"
echo "order: $order"
echo "icon: ${icons[$index]}"
echo "---"
echo
cat "$file"
} > "$out_file"
# remap some links to the original repo
sed -I '' -E 's|\.\./\.\./|https://github.com/MaaAssistantArknights/maa-cli/blob/main/maa-cli/|g' "$out_file"

if [[ $lang == "zh-CN" ]]; then
sed -i '' -E 's|https://maa\.plus/docs/(.+)\.html|../../\1.html|g' "$out_file"
elif [[ $lang == "en-US" ]]; then
sed -I '' -E 's|https://maa\.plus/docs/[^/]+/(.+)\.html|../\1.md|g' "$out_file"
fi
for filename_md in "${files[@]}"; do
sed -i '' -E "s|$filename_md|cli-$filename_md|g" "$out_file"
done
done
2 changes: 1 addition & 1 deletion maa-cli/docs/zh-CN/config.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 配置 CLI
# 配置 maa-cli

## 配置目录

Expand Down
2 changes: 1 addition & 1 deletion maa-cli/docs/zh-CN/faq.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 常见问题
# maa-cli 常见问题

## 1. 如何在 macOS 上使用 `$HOME/.config/maa` 作为配置文件目录?

Expand Down

0 comments on commit 6d5b136

Please sign in to comment.