Skip to content

Commit

Permalink
Merge pull request #1 from ChristosT/add-fonts-as-assets
Browse files Browse the repository at this point in the history
fix(assets): Download fonts as offline assets
  • Loading branch information
jourdain authored May 14, 2024
2 parents 3b5e0a6 + 7bae114 commit 394d09a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .generator/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
),
],
"styles": [
"https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons",
"fonts.css",
"https://cdn.jsdelivr.net/npm/quasar@2.12.4/dist/quasar.prod.css",
],
"vue_use": ["Quasar"],
Expand Down
23 changes: 23 additions & 0 deletions .generator/get_fonts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# search "./.download/fonts_with_urls.css" for remote assets and download them
# produce a new file with "./generator/fonts.css" local paths instead of remote
# this script should run on the top-level directory of the project

import re
from pathlib import Path
from urllib.request import urlretrieve
from urllib.parse import urlparse

ROOT = Path(__file__).parent.parent.absolute()

pattern = re.compile("http[^)]*") # capture from http until a parenthesis ')'
with open(ROOT / ".download/fonts_with_urls.css", "r") as fonts:
lines = fonts.read()
new_lines = lines
for url in pattern.finditer(lines):
parsed_url = urlparse(url[0]).path
destination = Path(parsed_url).name
urlretrieve(url[0], str(ROOT / ".generator" / destination))
new_lines = re.sub(url[0], f'"{destination}"', new_lines)

with open(ROOT / ".generator/fonts.css", "w") as out:
out.write(new_lines)
7 changes: 6 additions & 1 deletion .generator/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
QUASAR_URL=https://registry.npmjs.org/quasar/-/quasar-2.12.4.tgz
FONTS_URL="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
mkdir -p .download && cd .download && curl -L $QUASAR_URL | tar --strip-components=1 -xzv
cd ..
python ./.generator/generate.py
python -m trame.tools.widgets --config ./.generator/config.yaml --output ./
curl -o ./.download/fonts_with_urls.css "$FONTS_URL"
python ./.generator/get_fonts.py

python -m trame.tools.widgets --config ./.generator/config.yaml --output ./
mv ./.generator/*.ttf ./trame_quasar/module/quasar/vue3/

0 comments on commit 394d09a

Please sign in to comment.