|
23 | 23 | # substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8) |
24 | 24 | # |
25 | 25 |
|
26 | | -gh_toc_version="0.6.1" |
| 26 | +gh_toc_version="0.6.2" |
27 | 27 |
|
28 | 28 | gh_user_agent="gh-md-toc v$gh_toc_version" |
29 | 29 |
|
@@ -52,17 +52,23 @@ gh_toc_load() { |
52 | 52 | gh_toc_md2html() { |
53 | 53 | local gh_file_md=$1 |
54 | 54 | URL=https://api.github.com/markdown/raw |
| 55 | + |
55 | 56 | if [ ! -z "$GH_TOC_TOKEN" ]; then |
56 | 57 | TOKEN=$GH_TOC_TOKEN |
57 | 58 | else |
58 | | - TOKEN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" |
| 59 | + TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" |
| 60 | + if [ -f "$TOKEN_FILE" ]; then |
| 61 | + TOKEN="$(cat $TOKEN_FILE)" |
| 62 | + fi |
59 | 63 | fi |
60 | | - if [ -f "$TOKEN" ]; then |
61 | | - AUTH_HEADER=("-H" "Authorization: token $(cat $TOKEN)") |
| 64 | + if [ ! -z "${TOKEN}" ]; then |
| 65 | + AUTHORIZATION="--header \"Authorization: token ${TOKEN}\"" |
62 | 66 | fi |
| 67 | + |
63 | 68 | # echo $URL 1>&2 |
64 | 69 | OUTPUT="$(curl -s --user-agent "$gh_user_agent" \ |
65 | | - --data-binary @"$gh_file_md" -H "Content-Type:text/plain" "${AUTH_HEADER[@]}" \ |
| 70 | + --data-binary @"$gh_file_md" -H "Content-Type:text/plain" \ |
| 71 | + ${AUTHORIZATION} \ |
66 | 72 | $URL)" |
67 | 73 |
|
68 | 74 | if [ "$?" != "0" ]; then |
@@ -136,8 +142,8 @@ gh_toc(){ |
136 | 142 | if [ "$rawhtml" == "XXRateLimitXX" ]; then |
137 | 143 | echo "Parsing local markdown file requires access to github API" |
138 | 144 | echo "Error: You exceeded the hourly limit. See: https://developer.github.com/v3/#rate-limiting" |
139 | | - TOKEN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" |
140 | | - echo "or place github auth token here: $TOKEN" |
| 145 | + TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" |
| 146 | + echo "or place GitHub auth token here: ${TOKEN_FILE}" |
141 | 147 | exit 1 |
142 | 148 | fi |
143 | 149 | local toc=`echo "$rawhtml" | gh_toc_grab "$gh_src_copy"` |
|
0 commit comments