github.com/Kintar/etxt@v0.0.0-20221224033739-2fc69f000137/run_docsgen.sh (about)

     1  #!/bin/bash
     2  
     3  # Generates docs/reference_pkg.html files for each package, slightly nicer
     4  # than what godoc generates by default. Requires having godoc installed.
     5  
     6  # You can open the results after running the script with:
     7  # >> xdg-open docs/reference_etxt.html
     8  
     9  pkgname="etxt"
    10  pkgurl="github.com/Kintar/$pkgname"
    11  subpkgs="emask efixed esizer ecache eglyr"
    12  docsfolder="docs/"
    13  docsprefix="reference_"
    14  
    15  # download css and js files if necessary. they will be placed on docs/
    16  # and you may remove them at any time in order to refresh them.
    17  cssurl="https://raw.githubusercontent.com/golang/tools/master/godoc/static/style.css"
    18  jsurl="https://raw.githubusercontent.com/golang/tools/master/godoc/static/godocs.js"
    19  jqueryurl="https://raw.githubusercontent.com/golang/tools/master/godoc/static/jquery.js"
    20  cssfile=reference_style.css
    21  jsfile=reference_js.js
    22  jqueryfile=reference_jquery.js
    23  
    24  if [ ! -f "./docs/$cssfile" ]; then
    25  	echo "downloading godoc css..."
    26  	curl -sS $cssurl --output ./docs/$cssfile
    27  fi
    28  if [ ! -f "./docs/$jsfile" ]; then
    29  	echo "downloading godoc js..."
    30  	curl -sS $jsurl --output ./docs/$jsfile
    31  fi
    32  if [ ! -f "./docs/$jqueryfile" ]; then
    33  	echo "downloading jquery..."
    34  	curl -sS $jqueryurl --output ./docs/$jqueryfile
    35  fi
    36  
    37  headhtml="<!DOCTYPE html><html><head><title>$pkgurl/godoc</title><link href=\"$cssfile\" rel=\"stylesheet\"><style>body { max-width: 900px; margin: 20px auto; font-size: 16px; text-align: left; }</style><script src=\"$jqueryfile\"></script><script src=\"$jsfile\"></script></head><body>"
    38  tailhtml="</body></html>"
    39  echo "$headhtml" > tmp_doc_head
    40  echo "$tailhtml" > tmp_doc_tail
    41  
    42  # main package docs
    43  echo "generating docs for $pkgurl..."
    44  godoc -url pkg/$pkgurl | tail -n +44 > tmp_doc_body
    45  cat tmp_doc_head tmp_doc_body tmp_doc_tail > $docsfolder$docsprefix$pkgname.html
    46  for pkg in $subpkgs; do
    47  	sed -i "s|/pkg/$pkgurl/$pkg/|./$docsprefix$pkg.html|g" "$docsfolder$docsprefix$pkgname.html"
    48  	sed -i "s|/pkg/golang.org/|https://pkg.go.dev/golang.org/|g" "$docsfolder$docsprefix$pkgname.html"
    49  done
    50  
    51  # subpackage docs
    52  for pkg in $subpkgs; do
    53  	echo "generating docs for subpackage $pkg..."
    54  	godoc -url pkg/$pkgurl/$pkg | tail -n +44 > tmp_doc_body
    55  	cat tmp_doc_head tmp_doc_body tmp_doc_tail > "$docsfolder$docsprefix$pkg.html"
    56  	for pkg in $packages; do
    57  		sed -i "s|/pkg/$pkgurl/$pkg/|./$docsprefix$pkg.html|g" "$docsfolder$docsprefix$pkg.html"
    58  		sed -i "s|/pkg/golang.org/|https://pkg.go.dev/golang.org/|g" "$docsfolder$docsprefix$pkg.html"
    59  	done
    60  done
    61  
    62  # clear temp files
    63  rm tmp_doc_head tmp_doc_body tmp_doc_tail