git: 8c453856c7ac - main - sysutils/gh-md-toc: New port: Easy TOC creation for GitHub README.md

From: Robert Clausecker <fuz_at_FreeBSD.org>
Date: Wed, 05 Jul 2023 17:25:30 UTC
The branch main has been updated by fuz:

URL: https://cgit.FreeBSD.org/ports/commit/?id=8c453856c7ac0ffbb162a6187c019703781f6588

commit 8c453856c7ac0ffbb162a6187c019703781f6588
Author:     Jesús Daniel Colmenares Oviedo <DtxdF@disroot.org>
AuthorDate: 2023-06-30 20:41:09 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-07-05 17:21:08 +0000

    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
---
 sysutils/Makefile                        |  1 +
 sysutils/gh-md-toc/Makefile              | 33 +++++++++++
 sysutils/gh-md-toc/distinfo              |  3 +
 sysutils/gh-md-toc/files/patch-gh-md-toc | 94 ++++++++++++++++++++++++++++++++
 sysutils/gh-md-toc/pkg-descr             |  3 +
 5 files changed, 134 insertions(+)

diff --git a/sysutils/Makefile b/sysutils/Makefile
index fad80678bc0e..2b9d74a710e2 100644
--- a/sysutils/Makefile
+++ b/sysutils/Makefile
@@ -485,6 +485,7 @@
     SUBDIR += getdelta
     SUBDIR += geteltorito
     SUBDIR += getssl
+    SUBDIR += gh-md-toc
     SUBDIR += gigolo
     SUBDIR += gitwatch
     SUBDIR += gkfreq
diff --git a/sysutils/gh-md-toc/Makefile b/sysutils/gh-md-toc/Makefile
new file mode 100644
index 000000000000..6c4ba85a795d
--- /dev/null
+++ b/sysutils/gh-md-toc/Makefile
@@ -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>
diff --git a/sysutils/gh-md-toc/distinfo b/sysutils/gh-md-toc/distinfo
new file mode 100644
index 000000000000..16f7fc92da8d
--- /dev/null
+++ b/sysutils/gh-md-toc/distinfo
@@ -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
diff --git a/sysutils/gh-md-toc/files/patch-gh-md-toc b/sysutils/gh-md-toc/files/patch-gh-md-toc
new file mode 100644
index 000000000000..ac4e37045b34
--- /dev/null
+++ b/sysutils/gh-md-toc/files/patch-gh-md-toc
@@ -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
+ 
diff --git a/sysutils/gh-md-toc/pkg-descr b/sysutils/gh-md-toc/pkg-descr
new file mode 100644
index 000000000000..0091fcc641a6
--- /dev/null
+++ b/sysutils/gh-md-toc/pkg-descr
@@ -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.