Skip to content

Commit

Permalink
_scripts: reduce toil syncing to cue-by-example
Browse files Browse the repository at this point in the history
This adds a script to help reduce the toil of syncing content from this
repo to cue-labs/cue-by-example. Its results are visible in
cue-labs/cue-by-example#41.

The script is included here (and not in cue-labs/cue-by-example) because
its replacement is likely to be some preprocessor output mode, as
tracked in cue-lang/cue#3543.

Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I58fc2af0d48f011745f936713ce48c417fffae38
Dispatch-Trailer: {"type":"trybot","CL":1203397,"patchset":3,"ref":"refs/changes/97/1203397/3","targetBranch":"master"}
  • Loading branch information
jpluscplusm authored and cueckoo committed Oct 31, 2024
1 parent f4f4bfd commit 439456d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions _scripts/exportCueByExample.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail

# exportCueByExample.bash reads a single page from inside the hugo/ hierarchy,
# performs a few simple transformations, and emits a form that's 80% ready to
# be published at https://github.com/cue-labs/cue-by-example. This should be
# superseded by a solution to https://cuelang.org/issue/3543.

content="$1"

# Line comments, in order (as they can't appear inline):
# awk: delete all content before the first Markdown H1
# sed:
# - any line with a text fenced code block is shell output
# - shell output needs not to have a dollar-space prefix
# - the opening of a code-tabs container isn't needed
# - a text code-tab element is a text file (NB this isn't always correct!)
# - a cue code-tab element is a CUE file
# - the closing of a code-tabs container marks the end of a fenced code block
cat "$content" \
| awk '/^# / { x=1 } ; x {print}' \
| sed 's/^```text.*$/```sh/' \
| sed 's/^\$ //' \
| sed '/^{{< code-tabs >}}$/d' \
| sed 's/^{{< code-tab .*language="txt".*$/```text/' \
| sed 's/^{{< code-tab .*language="cue".*$/```cue/' \
| sed 's@^{{< /code-tab >}}{{< /code-tabs >}}$@```@'

cat <<EOC >&2
NBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNB
The transformation of the source file $content
was successful, but MUST NOT be assumed to be complete. Make sure you audit
its output, paying close attention to:
- shell commands with a prefix marked as "Actual command in CUE-By-Example guide" (or similar)
- anything inside {{< ... >}} blocks, which don't mean anything in GitHub Markdown
- relative URLs inside [markdown](/links), as these won't resolve on GitHub
- fenced code blocks that originally had filetypes other than text might have been changed to "text"
NBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNBNB
EOC

0 comments on commit 439456d

Please sign in to comment.