123456789101112131415161718192021222324252627 |
- #!/bin/bash
- # 插入关联链接,减少文档非核心内容
- input_file="$1"
- insert_content='<br><br><hr><div class="sectlevel1 expanded"style="margin:0; position:relative;border-radius:8px;"><a target="_blank" href="https://github.com/ChinaLym/shoulder-framework"title="GitHub"style="margin:0; position:relative;border-radius:8px;"><svg xmlns="http://www.w3.org/2000/svg"height="24px"id="Layer_1"version="1.1"viewBox="0 0 512 512"width="24px"style="fill:gray;"><style type="text/css">.st0{fill-rule:evenodd;clip-rule:evenodd}</style><g><path class="st0"d="M256,32C132.3,32,32,134.8,32,261.7c0,101.5,64.2,187.5,153.2,217.9c11.2,2.1,15.3-5,15.3-11.1 c0-5.5-0.2-19.9-0.3-39.1c-62.3,13.9-75.5-30.8-75.5-30.8c-10.2-26.5-24.9-33.6-24.9-33.6c-20.3-14.3,1.5-14,1.5-14 c22.5,1.6,34.3,23.7,34.3,23.7c20,35.1,52.4,25,65.2,19.1c2-14.8,7.8-25,14.2-30.7c-49.7-5.8-102-25.5-102-113.5 c0-25.1,8.7-45.6,23-61.6c-2.3-5.8-10-29.2,2.2-60.8c0,0,18.8-6.2,61.6,23.5c17.9-5.1,37-7.6,56.1-7.7c19,0.1,38.2,2.6,56.1,7.7 c42.8-29.7,61.5-23.5,61.5-23.5c12.2,31.6,4.5,55,2.2,60.8c14.3,16.1,23,36.6,23,61.6c0,88.2-52.4,107.6-102.3,113.3 c8,7.1,15.2,21.1,15.2,42.5c0,30.7-0.3,55.5-0.3,63c0,6.1,4,13.3,15.4,11C415.9,449.1,480,363.1,480,261.7 C480,134.8,379.7,32,256,32z"></path></g></svg> GitHub </a><a target="_blank" href="https://gitee.com/ChinaLym/shoulder-framework"title="Gitee"style="margin:0; position:relative;border-radius:8px;"><svg xmlns="http://www.w3.org/2000/svg" width="24px" height="24px" name="Gitee" viewBox="0 0 2000 2000"style="fill:gray;"><path d="M898 1992q183 0 344-69.5t283-191.5q122-122 191.5-283t69.5-344q0-183-69.5-344T1525 477q-122-122-283-191.5T898 216q-184 0-345 69.5T270 477Q148 599 78.5 760T9 1104q0 183 69.5 344T270 1731q122 122 283 191.5t345 69.5zm199-400H448q-17 0-30.5-14t-13.5-30V932q0-89 43.5-163.5T565 649q74-45 166-45h616q17 0 30.5 14t13.5 31v111q0 16-13.5 30t-30.5 14H731q-54 0-93.5 39.5T598 937v422q0 17 14 30.5t30 13.5h416q55 0 94.5-39.5t39.5-93.5v-22q0-17-14-30.5t-31-13.5H842q-17 0-30.5-14t-13.5-31v-111q0-16 13.5-30t30.5-14h505q17 0 30.5 14t13.5 30v250q0 121-86.5 207.5T1097 1592z"/></svg> Gitee </a><a target="_blank" href="https://gitcode.com/ChinaLym/shoulder-framework"title="Gitcode"style="margin:0; position:relative;border-radius:8px;"><svg xmlns="http://www.w3.org/2000/svg" width="24px" height="24px" name="Gitcode" viewBox="0 0 2000 2000"style="fill:gray;"><path d="M898 1992q183 0 344-69.5t283-191.5q122-122 191.5-283t69.5-344q0-183-69.5-344T1525 477q-122-122-283-191.5T898 216q-184 0-345 69.5T270 477Q148 599 78.5 760T9 1104q0 183 69.5 344T270 1731q122 122 283 191.5t345 69.5zm199-400H448q-17 0-30.5-14t-13.5-30V932q0-89 43.5-163.5T565 649q74-45 166-45h616q17 0 30.5 14t13.5 31v111q0 16-13.5 30t-30.5 14H731q-54 0-93.5 39.5T598 937v422q0 17 14 30.5t30 13.5h416q55 0 94.5-39.5t39.5-93.5v-22q0-17-14-30.5t-31-13.5H842q-17 0-30.5-14t-13.5-31v-111q0-16 13.5-30t30.5-14h505q17 0 30.5 14t13.5 30v250q0 121-86.5 207.5T1097 1592z"/></svg> Gitcode </a></div>'
- # <a target="_blank" href="https://github.com/ChinaLym/shoulder-framework/_waitOpenSource"><svg xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"style="fill:gray;"><path d="m16 2.012 3 3L16.713 7.3l-3-3zM4 14v3h3l8.299-8.287-3-3zm0 6h16v2H4z"></path></svg> Edit this Page </a>
- # <a target="_blank" href="https://stackoverflow.com/tags/shoulder-framework"><svg xmlns="http://www.w3.org/2000/svg"viewBox="0 0 384 512"width="24px"height="24px"style="fill:gray;"><path d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg> Stack Overflow </a></div>'
- pattern='<div id="content">'
- 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 (/<p>canonical=(.*?)<\/p>/) {print $1; exit}' $input_file)
- # 组装 html
- canonical_code="\n<link rel=\"canonical\" href=\"$canonical_url\" />\<meta property=\"og:url\" content=\"$canonical_url\">\n"
- # 组装添加命令
- canonical_command="sed -i 's#<meta name=\"author\" content=\"lym\">#<meta name=\"author\" content=\"lym\"> $canonical_code #g' $input_file"
- # 执行添加命令
- eval $canonical_command
- # 删除多余的提示部分
- sed -i '/canonical=/d' "$input_file"
|