From 3299069528096dbfed6c177d48cd464032f879a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=90=AF=E9=BE=99?= Date: Sun, 6 Jun 2021 19:18:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=AC=AC22=E5=91=A8=E5=91=A8?= =?UTF-8?q?=E5=88=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 146 +++++++++++++++++--- src/gh-md-toc | 361 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 486 insertions(+), 21 deletions(-) create mode 100755 src/gh-md-toc diff --git a/README.md b/README.md index f849a9e..003192d 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,31 @@ 目录 ================= -* [1,前言](#1前言) - * [1,开源项目](#1开源项目) - * [2,优秀文章](#2优秀文章) - * [3,优秀博客](#3优秀博客) -* [2,第18周-5月3–5月9](#2第18周-5月35月9) - * [1,开源项目](#1开源项目-1) - * [2,优秀文章](#2优秀文章-1) - * [3,优秀博客](#3优秀博客-1) -* [3,第19周-5月10–5月16](#3第19周-5月105月16) - * [1,开源项目](#1开源项目-2) - * [2,优秀文章](#2优秀文章-2) - * [3,优秀博客](#3优秀博客-2) -* [4,第20周-5月17–5月23](#4第20周-5月175月23) - * [1,开源项目](#1开源项目-3) - * [2,优秀文章](#2优秀文章-3) - * [3,优秀博客](#3优秀博客-3) -* [5,第21周-5月24–5月30](#5第21周-5月245月30) - * [1,开源项目](#1开源项目-4) - * [2,优秀文章](#2优秀文章-4) - * [3,优秀博客](#3优秀博客-4) +- [目录](#目录) +- [1,前言](#1前言) + - [1,开源项目](#1开源项目) + - [2,优秀文章](#2优秀文章) + - [3,优秀博客](#3优秀博客) +- [2,第18周-5月3–5月9](#2第18周-5月35月9) + - [1,开源项目](#1开源项目-1) + - [2,优秀文章](#2优秀文章-1) + - [3,优秀博客](#3优秀博客-1) +- [3,第19周-5月10–5月16](#3第19周-5月105月16) + - [1,开源项目](#1开源项目-2) + - [2,优秀文章](#2优秀文章-2) + - [3,优秀博客](#3优秀博客-2) +- [4,第20周-5月17–5月23](#4第20周-5月175月23) + - [1,开源项目](#1开源项目-3) + - [2,优秀文章](#2优秀文章-3) + - [3,优秀博客](#3优秀博客-3) +- [5,第21周-5月24–5月30](#5第21周-5月245月30) + - [1,开源项目](#1开源项目-4) + - [2,优秀文章](#2优秀文章-4) + - [3,优秀博客](#3优秀博客-4) +- [6,第22周-5月31–6月6](#6第22周-5月316月6) + - [1,开源项目](#1开源项目-5) + - [2,优秀文章](#2优秀文章-5) + - [3,优秀博客](#3优秀博客-5) # 1,前言 @@ -459,4 +464,103 @@ ----- > - 博客地址:[小弟调调](https://wangchujiang.com/) -> - 简单说明:作者创建了许多高质量的分享 \ No newline at end of file +> - 简单说明:作者创建了许多高质量的分享 + +# 6,第22周-5月31–6月6 + +## 1,开源项目 + +> - 项目地址:[zadig](https://github.com/koderover/zadig) +> - 项目说明:Zadig 是 KodeRover 公司基于 Kubernetes 自主设计、研发的开源分布式持续交付 (Continues Delivery) 产品,为开发者提供云原生运行环境,支持开发者本地联调、微服务并行构建和部署、集成测试等。 +> - 相关文章:[官方文档](https://docs.koderover.com/zadig) + +---- + +> - 项目地址:[github-markdown-toc](https://github.com/ekalinin/github-markdown-toc) +> - 项目说明:给GitHub仓库中README生成TOC目录的工具,支持本地远程 +> - 相关文章:[README](https://github.com/ekalinin/github-markdown-toc/blob/master/README.md) + +---- + +> - 项目地址:[gitalk](https://github.com/gitalk/gitalk) +> - 项目说明:一个基于 GitHub Issue 和 Preact 开发的评论插件,可用于Hugo,docsify等静态博客。 +> - 相关文章:[中文文档](https://github.com/gitalk/gitalk/blob/master/readme-cn.md),[在线示例](https://gitalk.github.io/) + +---- + +> - 项目地址:[shields](https://github.com/badges/shields) +> - 项目说明:markdown中自定义徽标 +> - 相关文章:[在线访问](https://shields.io/category/license) + +---- + +> - 项目地址:[kubectl-debug](https://github.com/aylei/kubectl-debug) +> - 项目说明:便捷地进行 Kubernetes 上的 Pod 排障诊断 +> - 相关文章:[中文说明](https://github.com/aylei/kubectl-debug/blob/master/docs/zh-cn.md) + +---- + +> - 项目地址:[vuepress](https://github.com/vuejs/vuepress) +> - 项目说明:以 Markdown 为中心的项目结构,以最少的配置帮助你专注于写作 +> - 相关文章:[中文官网](https://vuepress.vuejs.org/zh/) + +---- + +> - 项目地址:[awesome-vuepress](https://github.com/vuepress/awesome-vuepress) +> - 项目说明:如名 +> - 相关文章: + +---- + +> - 项目地址:[vuepress-theme-vdoing](https://github.com/xugaoyi/vuepress-theme-vdoing) +> - 项目说明:一款设计非常优秀的vuepress博客主题 +> - 相关文章:[官方文档](https://doc.xugaoyi.com/) + +---- + +> - 项目地址:[vuepress-theme-hope](https://github.com/vuepress-theme-hope/vuepress-theme-hope) +> - 项目说明:又一款不错的vuepress博客主题 +> - 相关文章:[官方文档](https://vuepress-theme-hope.github.io/zh/) + +## 2,优秀文章 + +> - [GitHub与Gitee双向自动同步](https://www.bahuangshanren.tech/github%E4%B8%8Egitee%E5%8F%8C%E5%90%91%E8%87%AA%E5%8A%A8%E5%90%8C%E6%AD%A5/) +> - gitee没有自动同步功能,通过`Github Actions`我们可以实现这个需求 + +---- + +> - [Go 语言优秀资源整理,为项目落地加速](https://cs.leops.cn/#/) +> - 作者收集整理了一大批go语言项目,值得关注,[开源地址](https://github.com/shockerli/go-awesome) + + +## 3,优秀博客 + +> - 博客地址:[团队领袖计划](https://leader.js.cool/) +> - 简单说明:职场经验,人生感悟,内容丰富 + +---- + +> - 博客地址:[Java 全栈知识体系](https://www.pdai.tech/) +> - 简单说明:Java技术栈 + +---- + + +> - 博客地址:[IT外卖小哥](https://clay-wangzhi.com/) +> - 简单说明:博客朋友王植同学的博客,非常有心,内容丰富 + +---- + +> - 博客地址:[awesome-bookmarks](https://panjiachen.github.io/awesome-bookmarks/) +> - 简单说明:作者将自己的网络收藏夹做成了博客形式 + +---- + +> - 博客地址:[前端禅意花园](http://www.yuanchengcheng.vip/) +> - 简单说明:作者虽步入互联网,却颇有一份热爱文学的气息 + +---- + + +> - 博客地址:[全栈直通车](https://www.sofineday.com/) +> - 简单说明:作者很有心,博客标签为:努力做个影响他人滴人 \ No newline at end of file diff --git a/src/gh-md-toc b/src/gh-md-toc new file mode 100755 index 0000000..ef389e7 --- /dev/null +++ b/src/gh-md-toc @@ -0,0 +1,361 @@ +#!/usr/bin/env bash + +# +# Steps: +# +# 1. Download corresponding html file for some README.md: +# curl -s $1 +# +# 2. Discard rows where no substring 'user-content-' (github's markup): +# awk '/user-content-/ { ... +# +# 3.1 Get last number in each row like ' ... sitemap.js.*<\/h/)+2, RLENGTH-5) +# +# 5. Find anchor and insert it inside "(...)": +# substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8) +# + +gh_toc_version="0.7.0" + +gh_user_agent="gh-md-toc v$gh_toc_version" + +# +# Download rendered into html README.md by its url. +# +# +gh_toc_load() { + local gh_url=$1 + + if type curl &>/dev/null; then + curl --user-agent "$gh_user_agent" -s "$gh_url" + elif type wget &>/dev/null; then + wget --user-agent="$gh_user_agent" -qO- "$gh_url" + else + echo "Please, install 'curl' or 'wget' and try again." + exit 1 + fi +} + +# +# Converts local md file into html by GitHub +# +# -> curl -X POST --data '{"text": "Hello world github/linguist#1 **cool**, and #1!"}' https://api.github.com/markdown +#

Hello world github/linguist#1 cool, and #1!

'" +gh_toc_md2html() { + local gh_file_md=$1 + URL=https://api.github.com/markdown/raw + + if [ ! -z "$GH_TOC_TOKEN" ]; then + TOKEN=$GH_TOC_TOKEN + else + TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" + if [ -f "$TOKEN_FILE" ]; then + TOKEN="$(cat $TOKEN_FILE)" + fi + fi + if [ ! -z "${TOKEN}" ]; then + AUTHORIZATION="Authorization: token ${TOKEN}" + fi + + # echo $URL 1>&2 + OUTPUT=$(curl -s \ + --user-agent "$gh_user_agent" \ + --data-binary @"$gh_file_md" \ + -H "Content-Type:text/plain" \ + -H "$AUTHORIZATION" \ + "$URL") + + if [ "$?" != "0" ]; then + echo "XXNetworkErrorXX" + fi + if [ "$(echo "${OUTPUT}" | awk '/API rate limit exceeded/')" != "" ]; then + echo "XXRateLimitXX" + else + echo "${OUTPUT}" + fi +} + + +# +# Is passed string url +# +gh_is_url() { + case $1 in + https* | http*) + echo "yes";; + *) + echo "no";; + esac +} + +# +# TOC generator +# +gh_toc(){ + local gh_src=$1 + local gh_src_copy=$1 + local gh_ttl_docs=$2 + local need_replace=$3 + local no_backup=$4 + local no_footer=$5 + + if [ "$gh_src" = "" ]; then + echo "Please, enter URL or local path for a README.md" + exit 1 + fi + + + # Show "TOC" string only if working with one document + if [ "$gh_ttl_docs" = "1" ]; then + + echo "Table of Contents" + echo "=================" + echo "" + gh_src_copy="" + + fi + + if [ "$(gh_is_url "$gh_src")" == "yes" ]; then + gh_toc_load "$gh_src" | gh_toc_grab "$gh_src_copy" + if [ "${PIPESTATUS[0]}" != "0" ]; then + echo "Could not load remote document." + echo "Please check your url or network connectivity" + exit 1 + fi + if [ "$need_replace" = "yes" ]; then + echo + echo "!! '$gh_src' is not a local file" + echo "!! Can't insert the TOC into it." + echo + fi + else + local rawhtml=$(gh_toc_md2html "$gh_src") + if [ "$rawhtml" == "XXNetworkErrorXX" ]; then + echo "Parsing local markdown file requires access to github API" + echo "Please make sure curl is installed and check your network connectivity" + exit 1 + fi + if [ "$rawhtml" == "XXRateLimitXX" ]; then + echo "Parsing local markdown file requires access to github API" + echo "Error: You exceeded the hourly limit. See: https://developer.github.com/v3/#rate-limiting" + TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" + echo "or place GitHub auth token here: ${TOKEN_FILE}" + exit 1 + fi + local toc=`echo "$rawhtml" | gh_toc_grab "$gh_src_copy"` + echo "$toc" + if [ "$need_replace" = "yes" ]; then + if grep -Fxq "" $gh_src && grep -Fxq "" $gh_src; then + echo "Found markers" + else + echo "You don't have or in your file...exiting" + exit 1 + fi + local ts="<\!--ts-->" + local te="<\!--te-->" + local dt=`date +'%F_%H%M%S'` + local ext=".orig.${dt}" + local toc_path="${gh_src}.toc.${dt}" + local toc_footer="" + # http://fahdshariff.blogspot.ru/2012/12/sed-mutli-line-replacement-between-two.html + # clear old TOC + sed -i${ext} "/${ts}/,/${te}/{//!d;}" "$gh_src" + # create toc file + echo "${toc}" > "${toc_path}" + if [ "${no_footer}" != "yes" ]; then + echo -e "\n${toc_footer}\n" >> "$toc_path" + fi + + # insert toc file + if [[ "`uname`" == "Darwin" ]]; then + sed -i "" "/${ts}/r ${toc_path}" "$gh_src" + else + sed -i "/${ts}/r ${toc_path}" "$gh_src" + fi + echo + if [ "${no_backup}" = "yes" ]; then + rm ${toc_path} ${gh_src}${ext} + fi + echo "!! TOC was added into: '$gh_src'" + if [ -z "${no_backup}" ]; then + echo "!! Origin version of the file: '${gh_src}${ext}'" + echo "!! TOC added into a separate file: '${toc_path}'" + fi + echo + fi + fi +} + +# +# Grabber of the TOC from rendered html +# +# $1 - a source url of document. +# It's need if TOC is generated for multiple documents. +# +gh_toc_grab() { + common_awk_script=' + modified_href = "" + split(href, chars, "") + for (i=1;i <= length(href); i++) { + c = chars[i] + res = "" + if (c == "+") { + res = " " + } else { + if (c == "%") { + res = "\\x" + } else { + res = c "" + } + } + modified_href = modified_href res + } + print sprintf("%*s", (level-1)*3, "") "* [" text "](" gh_url modified_href ")" + ' + if [ `uname -s` == "OS/390" ]; then + grepcmd="pcregrep -o" + echoargs="" + awkscript='{ + level = substr($0, length($0), 1) + text = substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5) + href = substr($0, match($0, "href=\"([^\"]+)?\"")+6, RLENGTH-7) + '"$common_awk_script"' + }' + else + grepcmd="grep -Eo" + echoargs="-e" + awkscript='{ + level = substr($0, length($0), 1) + text = substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5) + href = substr($0, match($0, "href=\"[^\"]+?\"")+6, RLENGTH-7) + '"$common_awk_script"' + }' + fi + href_regex='href=\"[^\"]+?\"' + + # if closed is on the new line, then move it on the prev line + # for example: + # was: The command foo1 + # + # became: The command foo1 + sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' | + + # find strings that corresponds to template + $grepcmd '//g' | sed 's/<\/code>//g' | + + # remove g-emoji + sed 's/]*[^<]*<\/g-emoji> //g' | + + # now all rows are like: + # ... / placeholders" + echo " $app_name - Create TOC for markdown from STDIN" + echo " $app_name --help Show help" + echo " $app_name --version Show version" + return + fi + + if [ "$1" = '--version' ]; then + echo "$gh_toc_version" + echo + echo "os: `lsb_release -d | cut -f 2`" + echo "kernel: `cat /proc/version`" + echo "shell: `$SHELL --version`" + echo + for tool in curl wget grep awk sed; do + printf "%-5s: " $tool + echo `$tool --version | head -n 1` + done + return + fi + + if [ "$1" = "-" ]; then + if [ -z "$TMPDIR" ]; then + TMPDIR="/tmp" + elif [ -n "$TMPDIR" -a ! -d "$TMPDIR" ]; then + mkdir -p "$TMPDIR" + fi + local gh_tmp_md + if [ `uname -s` == "OS/390" ]; then + local timestamp=$(date +%m%d%Y%H%M%S) + gh_tmp_md="$TMPDIR/tmp.$timestamp" + else + gh_tmp_md=$(mktemp $TMPDIR/tmp.XXXXXX) + fi + while read input; do + echo "$input" >> "$gh_tmp_md" + done + gh_toc_md2html "$gh_tmp_md" | gh_toc_grab "" + return + fi + + if [ "$1" = '--insert' ]; then + need_replace="yes" + shift + fi + + if [ "$1" = '--no-backup' ]; then + need_replace="yes" + no_backup="yes" + shift + fi + + if [ "$1" = '--hide-footer' ]; then + need_replace="yes" + no_footer="yes" + shift + fi + + for md in "$@" + do + echo "" + gh_toc "$md" "$#" "$need_replace" "$no_backup" "$no_footer" + done + + echo "" + echo "Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)" +} + +# +# Entry point +# +gh_toc_app "$@" + -- GitLab