github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/misc/gendocs/gendocs.sh (about)

     1  #!/bin/bash
     2  # Heavily modified version of the following script:
     3  # https://gist.github.com/Kegsay/84ce060f237cb9ab4e0d2d321a91d920
     4  set -u
     5  
     6  DOC_DIR=godoc
     7  PKG=github.com/gnolang/gno
     8  # Used to load /static content
     9  STATIC_PREFIX=/gno
    10  
    11  # Run a pkgsite server which we will scrape. Use env to run it from our repo's root directory.
    12  env -C ../.. pkgsite &
    13  DOC_PID=$!
    14  
    15  # Wait for the server to init
    16  while :
    17  do
    18      curl -s "http://localhost:8080" > /dev/null
    19      if [ $? -eq 0 ] # exit code is 0 if we connected
    20      then
    21          break
    22      fi
    23  done
    24  
    25  # Scrape the pkg directory for the API docs. Scrap lib for the CSS/JS. Ignore everything else.
    26  wget \
    27  	--verbose \
    28  	--recursive \
    29  	--mirror \
    30  	--convert-links \
    31  	--adjust-extension \
    32  	--page-requisites \
    33  	-erobots=off \
    34  	--accept-regex='8080/((search|license-policy|about|)$|(static|images)/|github.com/gnolang/)' \
    35  	http://localhost:8080/ \
    36  	http://localhost:8080/static/frontend/frontend.js \
    37  	http://localhost:8080/static/frontend/unit/unit.js \
    38  	http://localhost:8080/static/frontend/unit/main/main.js \
    39  	http://localhost:8080/third_party/dialog-polyfill/dialog-polyfill.js
    40  
    41  # Stop the pkgsite server
    42  kill -9 $DOC_PID
    43  
    44  # Delete the old directory or else mv will put the localhost dir into
    45  # the DOC_DIR if it already exists.
    46  rm -rf $DOC_DIR
    47  mv localhost\:8080 $DOC_DIR
    48  
    49  # Perform various replacements to fix broken links/UI.
    50  # /files/ will point to their github counterparts; we make links to importedby/version go nowhere;
    51  # any other link will point to pkg.go.dev, and fix the /files/... text when viewing a pkg.
    52  find godoc -type f -exec sed -ri 's#http://localhost:8080/files/[^"]*/github.com/gnolang/([^/"]+)/([^"]*)#https://github.com/gnolang/\1/blob/master/\2#g
    53  s#http://localhost:8080/[^"?]*\?tab=(importedby|versions)#\##g
    54  s#http://localhost:8080([^")]*)#https://pkg.go.dev\1#g
    55  s#/files/[^" ]*/(github.com/[^" ]*)/#\1#g
    56  s#s\.src = src;#s.src = "'"$STATIC_PREFIX"'" + src;#g' {} +
    57  
    58  echo "Docs can be found in $DOC_DIR"