|
| 1 | +#!/bin/bash -e |
| 2 | +# This script publishes the GraphQL specification document to the web. |
| 3 | + |
| 4 | +# Determine if this is a tagged release |
| 5 | +GITTAG=$(git tag --points-at HEAD) |
| 6 | + |
| 7 | +# Build the specification draft document |
| 8 | +echo "Building spec draft" |
| 9 | +mkdir -p public/draft |
| 10 | +spec-md --metadata spec/metadata.json --githubSource "https://github.com/graphql/graphql-over-http/blame/main/" spec/GraphQLOverHTTP.md > public/draft/index.html |
| 11 | + |
| 12 | +# If this is a tagged commit, also build the release document |
| 13 | +if [ -n "$GITTAG" ]; then |
| 14 | + echo "Building spec release $GITTAG" |
| 15 | + mkdir -p "public/$GITTAG" |
| 16 | + spec-md --metadata spec/metadata.json --githubSource "https://github.com/graphql/graphql-over-http/blame/$GITTAG/" spec/GraphQLOverHTTP.md > "public/$GITTAG/index.html" |
| 17 | +fi |
| 18 | + |
| 19 | +# Create the index file |
| 20 | +echo "Rebuilding: / (index)" |
| 21 | +HTML="<html> |
| 22 | + <head> |
| 23 | + <title>GraphQL over HTTP Specification Versions</title> |
| 24 | + <style> |
| 25 | + body { |
| 26 | + color: #333333; |
| 27 | + font: 13pt/18pt Cambria, 'Palatino Linotype', Palatino, 'Liberation Serif', serif; |
| 28 | + margin: 6rem auto 3rem; |
| 29 | + max-width: 780px; |
| 30 | + } |
| 31 | + @media (min-width: 1240px) { |
| 32 | + body { |
| 33 | + padding-right: 300px; |
| 34 | + } |
| 35 | + } |
| 36 | + a { |
| 37 | + color: #3B5998; |
| 38 | + text-decoration: none; |
| 39 | + } |
| 40 | + a:hover { |
| 41 | + text-decoration: underline; |
| 42 | + } |
| 43 | + h1 { |
| 44 | + font-size: 1.5em; |
| 45 | + margin: 8rem 0 2em; |
| 46 | + } |
| 47 | + td { |
| 48 | + padding-bottom: 5px; |
| 49 | + } |
| 50 | + td + td { |
| 51 | + padding-left: 2ch; |
| 52 | + } |
| 53 | + </style> |
| 54 | + </head> |
| 55 | + <body> |
| 56 | + <h1>GraphQL over HTTP</h1> |
| 57 | + <table>" |
| 58 | + |
| 59 | +# Include latest draft |
| 60 | +GITDATE=$(git show -s --format=%cd --date=format:"%a, %b %-d, %Y" HEAD) |
| 61 | +HTML="$HTML |
| 62 | + <tr> |
| 63 | + <td><em>Prerelease</em></td> |
| 64 | + <td><a href=\"./draft\" keep-hash>Working Draft</a></td> |
| 65 | + <td>$GITDATE</td> |
| 66 | + <td></td> |
| 67 | + </tr>" |
| 68 | + |
| 69 | +GITHUB_RELEASES="https://github.com/graphql/graphql-over-http/releases/tag" |
| 70 | +for GITTAG in $(git tag -l --sort='-*committerdate') ; do |
| 71 | + VERSIONYEAR=${GITTAG: -4} |
| 72 | + TAGTITLE="${GITTAG%$VERSIONYEAR} $VERSIONYEAR" |
| 73 | + TAGGEDCOMMIT=$(git rev-list -1 "$GITTAG") |
| 74 | + GITDATE=$(git show -s --format=%cd --date=format:"%a, %b %-d, %Y" $TAGGEDCOMMIT) |
| 75 | + |
| 76 | + HTML="$HTML |
| 77 | + <tr>" |
| 78 | + |
| 79 | + [ -z $HAS_LATEST_RELEASE ] && HTML="$HTML |
| 80 | + <td><em>Latest Release</em></td>" || HTML="$HTML |
| 81 | + <td></td>" |
| 82 | + HAS_LATEST_RELEASE=1 |
| 83 | + |
| 84 | + HTML="$HTML |
| 85 | + <td><a href=\"./$GITTAG\" keep-hash>$TAGTITLE</a></td> |
| 86 | + <td>$GITDATE</td> |
| 87 | + <td><a href=\"$GITHUB_RELEASES/$GITTAG\">Release Notes</a></td> |
| 88 | + </tr>" |
| 89 | +done |
| 90 | + |
| 91 | +HTML="$HTML |
| 92 | + </table> |
| 93 | + <script> |
| 94 | + var links = document.getElementsByTagName('a'); |
| 95 | + for (var i = 0; i < links.length; i++) { |
| 96 | + if (links[i].hasAttribute('keep-hash')) { |
| 97 | + links[i].href += location.hash; |
| 98 | + links[i].removeAttribute('keep-hash'); |
| 99 | + } |
| 100 | + } |
| 101 | + </script> |
| 102 | + </body> |
| 103 | +</html>" |
| 104 | + |
| 105 | +echo $HTML > "public/index.html" |
0 commit comments