2 Star 1 Fork 0

陈孝松/blog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
course.sh 2.13 KB
一键复制 编辑 原始数据 按行查看 历史
ChenXiaoSong 提交于 2025-03-04 09:41 +08:00 . update harmonyos
. ~/.top-path
MY_ECHO_DEBUG=0
src_path=${MY_CODE_TOP_PATH}/blog
. ${src_path}/src/blog-web/common-lib.sh
# add_common array[@] ${common_file}
add_common() {
local except_array=("${!1}") # 使用间接引用来接收数组
local array=("${!2}") # 使用间接引用来接收数组
local target_path=$3
local common_file=${target_path}/common.md
local element_count="${#array[@]}" # 总个数
local count_per_line=1
for ((index=0; index<${element_count}; index=$((index + ${count_per_line}))))
do
local ifile=${array[${index}]}
if [[ ${ifile} == ${common_file} ]]; then
continue
fi
local src_file=${src_path}/${ifile}
local dst_file=$(comm_tmp_src_path)/${ifile}
local dst_dir="$(dirname "${dst_file}")" # 所在的文件夹
if [ ! -d "${dst_dir}" ]; then
mkdir -p "${dst_dir}" # 文件夹不存在就创建
fi
comm_echo "src_file:${src_file}, dst_file:${dst_file}"
comm_is_in_array except_array[@] ${ifile}
if [[ $? == 0 ]]; then
comm_echo "${ifile} do not add common"
cp "${src_file}" "${dst_file}" # 只复制
continue
fi
cp ${common_file} ${dst_file}
cat ${src_file} >> ${dst_file}
done
}
scan_md() {
local -n array_ref=$1
local target_path=$2
local mid_path=$3
target_path="${target_path%/}/" # 确保目录末尾有 /
# 使用 find 命令查找所有 .md 文件并将结果存储到 array 数组中
while IFS= read -r md_file; do
md_file="${md_file/$target_path}" # 干掉前缀
md_file=$(comm_normalize_path "${mid_path}/${md_file}")
comm_echo "${md_file}"
# 追加到数组中
array+=("${md_file}")
done < <(find "${target_path}" -type f -name "*.md")
}
create_full_course_md() {
local course=$1
local mid_path="course/${course}/"
local target_path=${src_path}/${mid_path}
local except_array=(
course/${course}/${course}.md
course/${course}/video.md
)
local array=()
scan_md array "${target_path}" "${mid_path}"
add_common except_array[@] array[@] "${target_path}"
}
create_full_course_md "kernel"
create_full_course_md "nfs"
create_full_course_md "smb"
create_full_course_md "algorithm"
create_full_course_md "godot"
create_full_course_md "gnu-linux"
create_full_course_md "harmony"
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chenxiaosonggitee/blog.git
git@gitee.com:chenxiaosonggitee/blog.git
chenxiaosonggitee
blog
blog
master

搜索帮助