Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sysutils/gh-md-toc: New port: Easy TOC creation for GitHub README.md
gh-md-toc (or github-markdown-toc) is a TOC (Table of Content) generator for a README.md or a GitHub wiki page without installing additional software. WWW: https://github.com/ekalinin/github-markdown-toc PR: 272054
- Loading branch information
1 parent
0df7f81
commit 8c45385
Showing
5 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
PORTNAME= gh-md-toc | ||
DISTVERSION= 0.8.0 | ||
CATEGORIES= sysutils | ||
|
||
MAINTAINER= DtxdF@disroot.org | ||
COMMENT= Easy TOC creation for GitHub README.md | ||
WWW= https://github.com/ekalinin/github-markdown-toc | ||
|
||
LICENSE= MIT | ||
LICENSE_FILE= ${WRKSRC}/LICENSE | ||
|
||
RUN_DEPENDS= curl>0:ftp/curl | ||
|
||
USE_GITHUB= yes | ||
GH_ACCOUNT= ekalinin | ||
GH_PROJECT= github-markdown-toc | ||
|
||
NO_BUILD= yes | ||
|
||
PLIST_FILES= bin/gh-md-toc | ||
|
||
PORTDOCS= README.md | ||
|
||
OPTIONS_DEFINE= DOCS | ||
|
||
do-install: | ||
${INSTALL_SCRIPT} ${WRKSRC}/gh-md-toc ${STAGEDIR}${PREFIX}/bin | ||
|
||
do-install-DOCS-on: | ||
@${MKDIR} ${STAGEDIR}${DOCSDIR} | ||
${INSTALL_DATA} ${WRKSRC}/README.md ${STAGEDIR}${DOCSDIR} | ||
|
||
.include <bsd.port.mk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TIMESTAMP = 1687043066 | ||
SHA256 (ekalinin-github-markdown-toc-0.8.0_GH0.tar.gz) = 7f6079026a32c03d6e7254e5921b94f6802c2d52c9d74d85a1f8015d864b58d0 | ||
SIZE (ekalinin-github-markdown-toc-0.8.0_GH0.tar.gz) = 10927 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- gh-md-toc.orig 2023-06-30 18:59:15 UTC | ||
+++ gh-md-toc | ||
@@ -1,4 +1,4 @@ | ||
-#!/usr/bin/env bash | ||
+#!/bin/sh | ||
|
||
# | ||
# Steps: | ||
@@ -34,12 +34,10 @@ gh_user_agent="gh-md-toc v$gh_toc_version" | ||
gh_toc_load() { | ||
local gh_url=$1 | ||
|
||
- if type curl &>/dev/null; then | ||
+ if type curl > /dev/null 2>&1; 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." | ||
+ echo "Please, install 'curl' and try again." | ||
exit 1 | ||
fi | ||
} | ||
@@ -56,7 +54,7 @@ gh_toc_md2html() { | ||
if [ ! -z "$GH_TOC_TOKEN" ]; then | ||
TOKEN=$GH_TOC_TOKEN | ||
else | ||
- TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" | ||
+ TOKEN_FILE="$(cd "$(dirname "$0")" && pwd)/token.txt" | ||
if [ -f "$TOKEN_FILE" ]; then | ||
TOKEN="$(cat $TOKEN_FILE)" | ||
fi | ||
@@ -124,12 +122,14 @@ gh_toc(){ | ||
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 | ||
+ local gh_content | ||
+ gh_content=`gh_toc_load "$gh_src"` | ||
+ if [ $? -ne 0 ]; then | ||
echo "Could not load remote document." | ||
echo "Please check your url or network connectivity" | ||
exit 1 | ||
fi | ||
+ printf "%s\n" "$gh_content" | gh_toc_grab "$gh_src_copy" | ||
if [ "$need_replace" = "yes" ]; then | ||
echo | ||
echo "!! '$gh_src' is not a local file" | ||
@@ -146,7 +146,7 @@ gh_toc(){ | ||
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" | ||
+ TOKEN_FILE="$(cd "$(dirname "$0")" && pwd)/token.txt" | ||
echo "or place GitHub auth token here: ${TOKEN_FILE}" | ||
exit 1 | ||
fi | ||
@@ -175,11 +175,7 @@ gh_toc(){ | ||
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 | ||
+ sed -i "" "/${ts}/r ${toc_path}" "$gh_src" | ||
echo | ||
if [ "${no_backup}" = "yes" ]; then | ||
rm ${toc_path} ${gh_src}${ext} | ||
@@ -296,14 +292,18 @@ gh_toc_app() { | ||
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 "os: `uname -rs`" | ||
+ echo "kernel: `uname -K`" | ||
+ echo "shell: $SHELL" | ||
echo | ||
- for tool in curl wget grep awk sed; do | ||
+ for tool in grep awk; do | ||
printf "%-5s: " $tool | ||
echo `$tool --version | head -n 1` | ||
done | ||
+ printf "%-5s: " sed | ||
+ echo "sed (BSD sed)" | ||
+ printf "%-5s: " fetch | ||
+ echo "fetch (BSD fetch)" | ||
return | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
gh-md-toc (or github-markdown-toc) is a TOC (Table of Content) | ||
generator for a README.md or a GitHub wiki page without installing | ||
additional software. |