new v4 website
This commit is contained in:
parent
c2452dee3a
commit
2f9a256e6e
274 changed files with 6316 additions and 330038 deletions
68
docs/_scripts/build-fontkit.js.sh
Normal file
68
docs/_scripts/build-fontkit.js.sh
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Usage:
|
||||
# sh build-fontkit.js.sh [<outfile>]
|
||||
# <outfile> defaults to ./fontkit-VERSION.js
|
||||
#
|
||||
# This script builds fontkit.js for a web browser as an ES module script.
|
||||
# Use the result like this:
|
||||
# <script type="module">
|
||||
# import fontkit from "./fontkit-2.0.2.js"
|
||||
# let data = await fetch("Inter-Variable.ttf").then(r => r.arrayBuffer())
|
||||
# let font = fontkit.create(new Uint8Array(data))
|
||||
# let instance = font.getVariation({wght: 600, opsz: 28})
|
||||
# console.log({font, instance})
|
||||
# </script>
|
||||
#
|
||||
# We can't use esbuild but have to use parcel since fontkit relies on
|
||||
# parcel-specific features like executing nodejs fs.readFileSync at build time.
|
||||
# So first we build with parcel then use esbuild to minify the results.
|
||||
# There might be ways to streamline the parcel build process, but after 30 minutes
|
||||
# of reading their documentation I couldn't figure it out, thus the sed hacks.
|
||||
#
|
||||
set -e
|
||||
|
||||
rm -rf /tmp/fontkit-build
|
||||
mkdir /tmp/fontkit-build
|
||||
pushd /tmp/fontkit-build >/dev/null
|
||||
|
||||
cat <<EOF > package.json
|
||||
{ "name": "fontkit-build",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"buffer": "^6.0.3",
|
||||
"fontkit": "^2.0.2",
|
||||
"parcel": "^2.9.3",
|
||||
"esbuild": "^0.19.2"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
npm install
|
||||
|
||||
FONTKIT_VERSION=$(node -p 'require("./node_modules/fontkit/package.json").version')
|
||||
|
||||
cat <<EOF > index.html
|
||||
<html lang="en"><script type="module">
|
||||
window.fontkit = require("fontkit")
|
||||
</script></html>
|
||||
EOF
|
||||
|
||||
./node_modules/.bin/parcel build --no-optimize --no-cache index.html
|
||||
|
||||
# strip away HTML
|
||||
sed -E 's/^\s*(:?<html lang="en"><script type="module">|<\/script><\/html>\s*\n*\s*)//' dist/index.html > dist/1.js
|
||||
sed -E 's/window.fontkit =/const fontkit =/' dist/1.js > dist/2.js
|
||||
echo 'export default fontkit' >> dist/2.js
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
OUTPUT_FILE=${1:-$(cd "$(dirname "$0")/.." && pwd)/res/fontkit-$FONTKIT_VERSION.js}
|
||||
/tmp/fontkit-build/node_modules/.bin/esbuild /tmp/fontkit-build/dist/2.js \
|
||||
--minify \
|
||||
--outfile="$OUTPUT_FILE" \
|
||||
--format=esm \
|
||||
--platform=browser \
|
||||
--target=chrome100
|
||||
|
||||
rm -rf /tmp/fontkit-build
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
MISSING_UTILS=()
|
||||
if ! (which svgo >/dev/null); then
|
||||
echo 'svgo not found in $PATH' >&2
|
||||
MISSING_UTILS+=( svgo )
|
||||
fi
|
||||
|
||||
if ! (which pngcrush >/dev/null); then
|
||||
echo 'pngcrush not found in $PATH' >&2
|
||||
MISSING_UTILS+=( pngcrush )
|
||||
fi
|
||||
|
||||
if ! (which convert >/dev/null); then
|
||||
echo 'convert not found in $PATH' >&2
|
||||
MISSING_UTILS+=( imagemagick )
|
||||
fi
|
||||
|
||||
if ! [ -z $MISSING_UTILS ]; then
|
||||
if [[ "$(uname)" = *Darwin* ]]; then
|
||||
echo 'try `brew install '"${MISSING_UTILS[@]}"'` on mac'
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pushd res >/dev/null
|
||||
|
||||
# crunch /docs/res/*.svg
|
||||
for f in *.svg; do
|
||||
svgo --multipass -q "$f" &
|
||||
done
|
||||
|
||||
# crunch /docs/res/icons/*.svg
|
||||
for f in icons/*.svg; do
|
||||
svgo --multipass -q "$f" &
|
||||
done
|
||||
|
||||
# crunch /docs/res/*.png
|
||||
for f in *.png; do
|
||||
TMPNAME=.$f.tmp
|
||||
(pngcrush -q "$f" "$TMPNAME" && mv -f "$TMPNAME" "$f") &
|
||||
done
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
|
||||
pushd samples/img >/dev/null
|
||||
|
||||
# crunch /docs/samples/img/*.png
|
||||
for f in *.png; do
|
||||
TMPNAME=.$f.tmp
|
||||
if (echo "$f" | grep -q 'thumb'); then
|
||||
(convert "$f" -flatten -background white -colors 16 "$TMPNAME" && pngcrush -q "$TMPNAME" "$f") &
|
||||
else
|
||||
(pngcrush -q "$f" "$TMPNAME" && mv -f "$TMPNAME" "$f") &
|
||||
fi
|
||||
done
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
|
||||
|
||||
pushd samples/icons >/dev/null
|
||||
|
||||
# crunch /docs/samples/icons/*.svg
|
||||
for f in *.svg; do
|
||||
svgo --multipass -q "$f" &
|
||||
done
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
# wait for all background processes to exit
|
||||
wait
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
if [ "$1" = "-h" ]; then
|
||||
echo "usage: $0 [<bindaddr>]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BINDADDR=${1:-127.0.0.1}
|
||||
|
||||
if [ ! -s lab/fonts ]; then
|
||||
rm -f lab/fonts
|
||||
ln -fs ../../build/fonts lab/fonts
|
||||
fi
|
||||
|
||||
# need to delete generated content so that jekyll, being a little dumb,
|
||||
# can manage to copy the font files into there again.
|
||||
# Why not a symlink you ask? Jekyll traverses it and copies the content.
|
||||
# In the past we tried to work around this by periodically removing the
|
||||
# copied font files and re-creating the symlink, but it was a frail process.
|
||||
# For live testing with fonts, you'll instead want to use docs/lab/serve.py
|
||||
rm -rf _site
|
||||
|
||||
bundle exec jekyll serve \
|
||||
--watch \
|
||||
--host "$BINDADDR" \
|
||||
--port 3002 \
|
||||
--livereload \
|
||||
--livereload-port 30002
|
||||
Reference in a new issue