#!/bin/bash # 插入关联链接,减少文档非核心内容 input_file="$1" insert_content='


GitHub Gitee Gitcode
' # Edit this Page # Stack Overflow ' pattern='
' line_number=$(grep -n "$pattern" "$input_file" | cut -d: -f1) line_number=$((line_number - 2)) echo 'find targetLin=' $line_number ' in ' $input_file sed "${line_number} i\\$insert_content" "$input_file" > "$input_file.tmp" && mv "$input_file.tmp" "$input_file" # SEO canonical # 找到 $canonical_url canonical_url=$(perl -ne 'if (/

canonical=(.*?)<\/p>/) {print $1; exit}' $input_file) # 组装 html canonical_code="\n\\n" # 组装添加命令 canonical_command="sed -i 's## $canonical_code #g' $input_file" # 执行添加命令 eval $canonical_command # 删除多余的提示部分 sed -i '/canonical=/d' "$input_file"