@@ -69,15 +69,15 @@ jobs:
6969
7070 # Rewrite all `require()`s to use jsDelivr links:
7171 find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// {
72- s/(var|let|const)\s+([a-z0-9 ]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
72+ s/(var|let|const)\s+([a-z0-9_ ]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
7373 s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/
7474 s/';/@deno\/mod.js';/
7575 }"
7676
7777 # Remove `installation`, `cli`, and `c` sections:
7878 find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"installation\">[^<]+<\/section>//g;"
79- find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
80- find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
79+ find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)? <section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
80+ find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)? <section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
8181
8282 - name : Publish to deno branch
8383 uses : peaceiris/actions-gh-pages@v3
@@ -107,18 +107,39 @@ jobs:
107107 run : |
108108 npm install || npm install || npm install
109109 timeout-minutes : 15
110+ - name : Extract Alias
111+ id : extract-alias
112+ run : |
113+ alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/')
114+ echo "::set-output name=alias::${alias}"
110115 - name : Create Universal Module Definition (UMD) bundle
111116 id : umd-bundle
112117 uses : stdlib-js/bundle-action@main
113118 with :
114119 target : ' umd'
120+ alias : ${{ steps.extract-alias.outputs.alias }}
115121 - name : Rewrite file contents
116122 run : |
117123
124+ # Replace links to other packages with links to the umd branch:
125+ find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/";
126+
118127 # Remove `installation`, `cli`, and `c` sections:
119128 find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"installation\">[^<]+<\/section>//g;"
120- find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
121- find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
129+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
130+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
131+
132+ # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag:
133+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/bundle.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n<script type=\"text\/javascript\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/bundle.js\"><\/script>\n\`\`\`\n\nIf no recognized module system is present, access bundle contents via the global scope:\n\n\`\`\`html\n<script type=\"text\/javascript\">\n window.\2;\n<\/script>\n\`\`\`/"
134+
135+ # Rewrite examples section to be a HTML file:
136+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\#\# Examples([\s\S]*)\`\`\`javascript([\s\S]+?)\`\`\`/\#\# Examples\1\`\`\`html\n<\!DOCTYPE html>\n<html lang=\"en\">\n<body>\n<script type=\"text\/javascript\">\2\n<\/script>\n<\/body>\n<\/html>\n\`\`\`/"
137+
138+ # Rewrite all `require()`s in the examples section as `script` tags loading the respective UMD bundle:
139+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "1 while s/<script type=\"text\/javascript\">\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);?/<script type=\"text\/javascript\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/bundle.js\"><\/script>\n<script type=\"text\/javascript\">/g"
140+
141+ # Wrap contents of `<script type="text/javascript">` tag contents in an IIFE:
142+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<script type=\"text\/javascript\">([\s\S]+?)<\/script>/<script type=\"text\/javascript\">\n\(function \(\) {\1}\)\(\)\n<\/script>/g"
122143
123144 - name : Publish to umd branch
124145 uses : peaceiris/actions-gh-pages@v3
@@ -175,18 +196,18 @@ jobs:
175196
176197 # Rewrite all `require()`s to use jsDelivr links:
177198 find ./esm -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// {
178- s/(var|let|const)\s+([a-z0-9 ]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
199+ s/(var|let|const)\s+([a-z0-9_ ]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
179200 s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/
180201 s/';/@esm\/index.mjs';/
181202 }"
182203
183204 # Remove `installation`, `cli`, and `c` sections:
184205 find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"installation\">[^<]+<\/section>//g;"
185- find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
186- find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
206+ find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)? <section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
207+ find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)? <section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
187208
188209 # Rewrite examples section to be a HTML file:
189- find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\#\# Examples([\s\S]*)\`\`\`javascript([\s\S]+?)\`\`\`/\#\# Examples\1\`\`\`html\n<\!DOCTYPE html>\n<html lang=\"en\">\n<head >\n<script type=\"module\">\n\2\n<\/script>\n<\/head >\n<\/html>\n\`\`\`/g"
210+ find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\#\# Examples([\s\S]*)\`\`\`javascript([\s\S]+?)\`\`\`/\#\# Examples\1\`\`\`html\n<\!DOCTYPE html>\n<html lang=\"en\">\n<body >\n<script type=\"module\">\n\2\n<\/script>\n<\/body >\n<\/html>\n\`\`\`/g"
190211
191212 - name : Publish to esm branch
192213 uses : peaceiris/actions-gh-pages@v3
0 commit comments