Bug 272054 - [NEW PORT] sysutils/gh-md-toc: Easy TOC creation for GitHub README.md
Summary: [NEW PORT] sysutils/gh-md-toc: Easy TOC creation for GitHub README.md
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Robert Clausecker
URL: https://github.com/ekalinin/github-ma...
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-17 23:49 UTC by Jesús Daniel Colmenares Oviedo
Modified: 2023-07-06 06:53 UTC (History)
1 user (show)

See Also:


Attachments
gh-md-toc-0.8.0.patch (2.72 KB, patch)
2023-06-17 23:49 UTC, Jesús Daniel Colmenares Oviedo
DtxdF: maintainer-approval+
Details | Diff
gh-md-toc-0.8.0.patch (5.99 KB, patch)
2023-06-30 20:58 UTC, Jesús Daniel Colmenares Oviedo
DtxdF: maintainer-approval+
Details | Diff
gh-md-toc-0.8.0.patch (5.95 KB, patch)
2023-07-03 15:29 UTC, Jesús Daniel Colmenares Oviedo
DtxdF: maintainer-approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesús Daniel Colmenares Oviedo 2023-06-17 23:49:49 UTC
Created attachment 242850 [details]
gh-md-toc-0.8.0.patch

Description:

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/

QA:

* portlint: OK (looks fine.)
* testport: OK (poudriere: 13.2-RELEASE, amd64, CURL DOCS WGET tested)
Comment 1 Robert Clausecker freebsd_committer freebsd_triage 2023-06-25 17:26:36 UTC
Thank you for your submission.  Here are some comments:

 - does this script run with /bin/sh?  If yes, we could eliminate the bash dependency.
 - could you patch the script to use fetch(1) instead of wget(1) or curl(1)?
   This would permit elimination of these dependencies.
 - please only use ${PORTNAME} if the makefile would still work was PORTNAME
   changed.  In this case, if the port is renamed, the do-install target no
   longer works, so perhaps you shouldn't use PORTNAME there.
 - using ${PORTDOCS[0]} to get the name of a known file is fragile programming
   style.  What if PORTDOCS has multiple entries and someone sorts it so README
   is no longer the first entry?  Try to avoid such dependencies on element order
   in lists.  Just hardcode README as the file you want to install.
 - WWW does not need a trailing slash.

Will proceed with a build test once these issues have been addressed.
Comment 2 Jesús Daniel Colmenares Oviedo 2023-06-30 20:58:12 UTC
Created attachment 243084 [details]
gh-md-toc-0.8.0.patch

Thanks for reviewing my patch and sorry for taking so long to respond.

---

> does this script run with /bin/sh?  If yes, we could eliminate the bash dependency.

Not by default, but I have patched gh-md-toc to work seamlessly with sh(1).

> could you patch the script to use fetch(1) instead of wget(1) or curl(1)? This would permit elimination of these dependencies.

Unfortunately, fetch(1) doesn't allow you to set the headers that the Github needs to set the token, but I've read gh-md-toc carefully and I think ftp/wget doesn't make sense as the README says.

```
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
}
```

The above code only makes sense if wget or curl is used depending on the user's preferences in the following code.

```
    OUTPUT=$(curl -s \
        --user-agent "$gh_user_agent" \
        --data-binary @"$gh_tmp_file_md" \
        -H "Content-Type:text/plain" \
        -H "$AUTHORIZATION" \
        "$URL")
```

The above code creates a dependency so the user must install ftp/curl and the gh_toc_load() will match curl first, so ftp/wget makes no sense. I simply remove it to have less dependencies.

---

All other mentioned problems have been fixed and I have also patched gh-md-toc in some parts that may create new problems, such as:

```
gh-md-toc --version
0.8.0

os:     FreeBSD 13.2-RELEASE
kernel: 1302001
shell:  /bin/csh

grep : grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
awk  : awk version 20210215
sed  : sed (BSD sed)
fetch: fetch (BSD fetch)
```
Comment 3 Robert Clausecker freebsd_committer freebsd_triage 2023-07-01 11:08:47 UTC
Thank you for the update.  I will be able to commit this patch with small changes:

 - DOCS does not need to be placed in OPTIONS_DEFAULT.  It is always on by default.
Comment 4 Jesús Daniel Colmenares Oviedo 2023-07-03 15:29:20 UTC
Created attachment 243186 [details]
gh-md-toc-0.8.0.patch

I had forgotten, thank you!
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-07-05 17:26:23 UTC
A commit in branch main references this bug:

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 (new)              | 33 +++++++++
 sysutils/gh-md-toc/distinfo (new)              |  3 +
 sysutils/gh-md-toc/files/patch-gh-md-toc (new) | 94 ++++++++++++++++++++++++++
 sysutils/gh-md-toc/pkg-descr (new)             |  3 +
 5 files changed, 134 insertions(+)
Comment 6 Robert Clausecker freebsd_committer freebsd_triage 2023-07-06 06:53:09 UTC
Thank you for your contribution.