fontlab-www-toolkit 1.0.5.dev3__tar.gz → 1.0.6.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/PKG-INFO +1 -1
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/src/fontlab_www_toolkit/__version__.py +2 -2
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/src/fontlab_www_toolkit/builder.py +70 -5
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/tests/test_builder.py +118 -13
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/.gitignore +0 -0
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/LICENSE +0 -0
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/README.md +0 -0
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/pyproject.toml +0 -0
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/src/fontlab_www_toolkit/__init__.py +0 -0
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/src/fontlab_www_toolkit/__main__.py +0 -0
- {fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/src/fontlab_www_toolkit/deploy.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fontlab-www-toolkit
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.6.dev1
|
|
4
4
|
Summary: Shared ProperDocs + MaterialX site builder and deploy helpers for FontLab web properties.
|
|
5
5
|
Project-URL: Homepage, https://github.com/Fontlab/fontlab-www-toolkit
|
|
6
6
|
Project-URL: Issues, https://github.com/Fontlab/fontlab-www-toolkit/issues
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '1.0.
|
|
22
|
-
__version_tuple__ = version_tuple = (1, 0,
|
|
21
|
+
__version__ = version = '1.0.6.dev1'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 0, 6, 'dev1')
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
{fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/src/fontlab_www_toolkit/builder.py
RENAMED
|
@@ -181,6 +181,16 @@ class SiteBuilder:
|
|
|
181
181
|
if cloudinary_conf:
|
|
182
182
|
html = self.process_html_cloudinary(html, cloudinary_conf)
|
|
183
183
|
|
|
184
|
+
# 6. Opt every executable <script> out of Cloudflare Rocket Loader.
|
|
185
|
+
# Rocket Loader (enabled on the deployed zone) rewrites script types
|
|
186
|
+
# to defer/reorder execution and cannot run ES modules, which breaks
|
|
187
|
+
# scroll interactions and module web components on the live site even
|
|
188
|
+
# though the no-Cloudflare staging host runs the same HTML fine.
|
|
189
|
+
# data-cfasync="false" restores native, in-order execution. Harmless
|
|
190
|
+
# no-op where Rocket Loader is disabled.
|
|
191
|
+
if effective_config.get("rocket_loader_optout", True):
|
|
192
|
+
html = exempt_scripts_from_rocket_loader(html)
|
|
193
|
+
|
|
184
194
|
return html
|
|
185
195
|
|
|
186
196
|
def process_html_cloudinary(self, html: str, cloudinary_conf: dict) -> str:
|
|
@@ -308,9 +318,7 @@ class SiteBuilder:
|
|
|
308
318
|
# only ever touches img.cld-responsive, so omitting the class
|
|
309
319
|
# is the compliant way to exclude an image.
|
|
310
320
|
is_svg = is_svg_url(src_val)
|
|
311
|
-
opt_out = (
|
|
312
|
-
str(tag.get("data-cld-responsive", "")).strip().lower() == "false"
|
|
313
|
-
)
|
|
321
|
+
opt_out = str(tag.get("data-cld-responsive", "")).strip().lower() == "false"
|
|
314
322
|
if is_svg or opt_out or not cl_responsive_enabled:
|
|
315
323
|
static_trans = (
|
|
316
324
|
cl_trans_svg
|
|
@@ -367,7 +375,11 @@ class SiteBuilder:
|
|
|
367
375
|
for prefix, map_val in cl_map.items():
|
|
368
376
|
if prefix in new_val:
|
|
369
377
|
new_val = replace_urls_in_text(
|
|
370
|
-
new_val,
|
|
378
|
+
new_val,
|
|
379
|
+
prefix,
|
|
380
|
+
map_val,
|
|
381
|
+
cl_cloud,
|
|
382
|
+
effective_cl_trans,
|
|
371
383
|
svg_trans=cl_trans_svg,
|
|
372
384
|
)
|
|
373
385
|
tag[attr] = new_val
|
|
@@ -378,7 +390,11 @@ class SiteBuilder:
|
|
|
378
390
|
for prefix, map_val in cl_map.items():
|
|
379
391
|
if prefix in new_css:
|
|
380
392
|
new_css = replace_urls_in_text(
|
|
381
|
-
new_css,
|
|
393
|
+
new_css,
|
|
394
|
+
prefix,
|
|
395
|
+
map_val,
|
|
396
|
+
cl_cloud,
|
|
397
|
+
effective_cl_trans,
|
|
382
398
|
svg_trans=cl_trans_svg,
|
|
383
399
|
)
|
|
384
400
|
tag.string = new_css
|
|
@@ -959,6 +975,55 @@ def split_google_fonts_links(html: str) -> str:
|
|
|
959
975
|
return str(soup) if targets else html
|
|
960
976
|
|
|
961
977
|
|
|
978
|
+
# Script ``type`` values Cloudflare Rocket Loader rewrites to defer/reorder
|
|
979
|
+
# execution (an empty string == no ``type`` attribute, i.e. a classic script).
|
|
980
|
+
# Data scripts (application/json, ld+json, import maps, …) are ignored by Rocket
|
|
981
|
+
# Loader, so they are intentionally absent here and left untouched.
|
|
982
|
+
ROCKET_LOADER_SCRIPT_TYPES: frozenset[str] = frozenset(
|
|
983
|
+
{
|
|
984
|
+
"",
|
|
985
|
+
"text/javascript",
|
|
986
|
+
"application/javascript",
|
|
987
|
+
"text/ecmascript",
|
|
988
|
+
"application/ecmascript",
|
|
989
|
+
"module",
|
|
990
|
+
}
|
|
991
|
+
)
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
def exempt_scripts_from_rocket_loader(html: str) -> str:
|
|
995
|
+
"""Add ``data-cfasync="false"`` to every executable ``<script>`` tag.
|
|
996
|
+
|
|
997
|
+
Cloudflare Rocket Loader (a zone-level optimisation enabled on the deployed
|
|
998
|
+
host) rewrites each executable script's ``type`` to a private token so it
|
|
999
|
+
can defer and reorder execution. It cannot run ES modules and changes the
|
|
1000
|
+
order of classic scripts, which breaks scroll-driven interactions and module
|
|
1001
|
+
web components on the live site — while the staging webflow.io host, with no
|
|
1002
|
+
Cloudflare in front, runs the identical HTML correctly. The documented
|
|
1003
|
+
opt-out is ``data-cfasync="false"``: Rocket Loader leaves such scripts alone
|
|
1004
|
+
and the browser executes them natively, in document order (the staging
|
|
1005
|
+
behaviour).
|
|
1006
|
+
|
|
1007
|
+
Only scripts Rocket Loader would otherwise mangle are touched — inline or
|
|
1008
|
+
external JavaScript and ``type="module"``. Data blocks (JSON, LD+JSON,
|
|
1009
|
+
import maps, …) are left unchanged. Idempotent: a script that already
|
|
1010
|
+
carries ``data-cfasync`` is skipped. Returns the input string unchanged when
|
|
1011
|
+
nothing needs adding, avoiding a needless re-serialisation.
|
|
1012
|
+
"""
|
|
1013
|
+
if "<script" not in html:
|
|
1014
|
+
return html
|
|
1015
|
+
soup = BeautifulSoup(html, "html.parser")
|
|
1016
|
+
changed = False
|
|
1017
|
+
for tag in soup.find_all("script"):
|
|
1018
|
+
if tag.has_attr("data-cfasync"):
|
|
1019
|
+
continue
|
|
1020
|
+
if (tag.get("type") or "").strip().lower() not in ROCKET_LOADER_SCRIPT_TYPES:
|
|
1021
|
+
continue
|
|
1022
|
+
tag["data-cfasync"] = "false"
|
|
1023
|
+
changed = True
|
|
1024
|
+
return str(soup) if changed else html
|
|
1025
|
+
|
|
1026
|
+
|
|
962
1027
|
def strip_extraction_noise(html: str) -> str:
|
|
963
1028
|
"""Remove non-prose nodes before Markdown extraction.
|
|
964
1029
|
|
|
@@ -16,6 +16,7 @@ from fontlab_www_toolkit.builder import (
|
|
|
16
16
|
WebflowPage,
|
|
17
17
|
clean_webflow_html,
|
|
18
18
|
convert_old_html,
|
|
19
|
+
exempt_scripts_from_rocket_loader,
|
|
19
20
|
extract_markdown_via_url22md,
|
|
20
21
|
extract_old_page_content,
|
|
21
22
|
find_uv,
|
|
@@ -282,8 +283,13 @@ def test_cloudinary_url_mapping_and_replacement() -> None:
|
|
|
282
283
|
def _cloudinary_builder() -> SiteBuilder:
|
|
283
284
|
return SiteBuilder(
|
|
284
285
|
BuildPaths(
|
|
285
|
-
root=Path("."),
|
|
286
|
-
|
|
286
|
+
root=Path("."),
|
|
287
|
+
src_docs=Path("."),
|
|
288
|
+
markdown=Path("."),
|
|
289
|
+
static_docs=Path("."),
|
|
290
|
+
webflow_cache=Path("."),
|
|
291
|
+
build_docs=Path("."),
|
|
292
|
+
public=Path("."),
|
|
287
293
|
old_pages_config=Path("."),
|
|
288
294
|
)
|
|
289
295
|
)
|
|
@@ -291,11 +297,11 @@ def _cloudinary_builder() -> SiteBuilder:
|
|
|
291
297
|
|
|
292
298
|
def test_cloudinary_svg_uses_simple_static_url() -> None:
|
|
293
299
|
html = (
|
|
294
|
-
|
|
300
|
+
"<html><body>"
|
|
295
301
|
'<img id="svg" src="https://cdn.prod.website-files.com/67c7070e70765599c7796390/x.svg">'
|
|
296
302
|
'<img id="png" src="https://cdn.prod.website-files.com/67c7070e70765599c7796390/y.png">'
|
|
297
303
|
'<div style="background-image:url(https://cdn.prod.website-files.com/67c7070e70765599c7796390/bg.svg)"></div>'
|
|
298
|
-
|
|
304
|
+
"</body></html>"
|
|
299
305
|
)
|
|
300
306
|
conf = {
|
|
301
307
|
"cl_cloud": "fontlab",
|
|
@@ -308,9 +314,7 @@ def test_cloudinary_svg_uses_simple_static_url() -> None:
|
|
|
308
314
|
|
|
309
315
|
svg = soup.find(id="svg")
|
|
310
316
|
# SVG: simple f_svg,q_auto URL, no responsive class/script participation.
|
|
311
|
-
assert svg["src"] == (
|
|
312
|
-
"https://res.cloudinary.com/fontlab/image/upload/f_svg,q_auto/vw/x.svg"
|
|
313
|
-
)
|
|
317
|
+
assert svg["src"] == ("https://res.cloudinary.com/fontlab/image/upload/f_svg,q_auto/vw/x.svg")
|
|
314
318
|
assert svg.get("class") is None
|
|
315
319
|
assert svg.get("data-src") is None
|
|
316
320
|
|
|
@@ -320,18 +324,15 @@ def test_cloudinary_svg_uses_simple_static_url() -> None:
|
|
|
320
324
|
assert "w_auto" in png["data-src"]
|
|
321
325
|
|
|
322
326
|
# SVG referenced from CSS is simplified too.
|
|
323
|
-
assert (
|
|
324
|
-
"url(https://res.cloudinary.com/fontlab/image/upload/f_svg,q_auto/vw/bg.svg)"
|
|
325
|
-
in out
|
|
326
|
-
)
|
|
327
|
+
assert "url(https://res.cloudinary.com/fontlab/image/upload/f_svg,q_auto/vw/bg.svg)" in out
|
|
327
328
|
|
|
328
329
|
|
|
329
330
|
def test_cloudinary_opt_out_attribute_skips_responsive() -> None:
|
|
330
331
|
html = (
|
|
331
|
-
|
|
332
|
+
"<html><body>"
|
|
332
333
|
'<img id="out" data-cld-responsive="false" '
|
|
333
334
|
'src="https://cdn.prod.website-files.com/67c7070e70765599c7796390/logo.png">'
|
|
334
|
-
|
|
335
|
+
"</body></html>"
|
|
335
336
|
)
|
|
336
337
|
conf = {
|
|
337
338
|
"cl_cloud": "fontlab",
|
|
@@ -915,3 +916,107 @@ def test_extract_markdown_via_url22md_when_real_binary_then_returns_markdown(
|
|
|
915
916
|
)
|
|
916
917
|
markdown = extract_markdown_via_url22md(cache, tool=3, timeout=30)
|
|
917
918
|
assert "Hello" in markdown
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
# ---------------------------------------------------------------------------
|
|
922
|
+
# exempt_scripts_from_rocket_loader unit tests
|
|
923
|
+
# ---------------------------------------------------------------------------
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
def _make_builder() -> SiteBuilder:
|
|
927
|
+
"""Minimal SiteBuilder with no config (no cloudinary, etc.)."""
|
|
928
|
+
paths = BuildPaths(
|
|
929
|
+
root=Path("."),
|
|
930
|
+
src_docs=Path("."),
|
|
931
|
+
markdown=Path("."),
|
|
932
|
+
static_docs=Path("."),
|
|
933
|
+
webflow_cache=Path("."),
|
|
934
|
+
build_docs=Path("."),
|
|
935
|
+
public=Path("."),
|
|
936
|
+
old_pages_config=Path("."),
|
|
937
|
+
)
|
|
938
|
+
return SiteBuilder(paths)
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
def test_exempt_scripts_classic_inline_gets_cfasync() -> None:
|
|
942
|
+
html = "<script>console.log('x')</script>"
|
|
943
|
+
out = exempt_scripts_from_rocket_loader(html)
|
|
944
|
+
assert 'data-cfasync="false"' in out
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
def test_exempt_scripts_module_gets_cfasync() -> None:
|
|
948
|
+
html = '<script type="module" src="/a.js"></script>'
|
|
949
|
+
out = exempt_scripts_from_rocket_loader(html)
|
|
950
|
+
assert 'data-cfasync="false"' in out
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
def test_exempt_scripts_text_javascript_gets_cfasync() -> None:
|
|
954
|
+
html = '<script type="text/javascript" src="/a.js"></script>'
|
|
955
|
+
out = exempt_scripts_from_rocket_loader(html)
|
|
956
|
+
assert 'data-cfasync="false"' in out
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
def test_exempt_scripts_application_json_untouched() -> None:
|
|
960
|
+
html = '<script type="application/json">{"a":1}</script>'
|
|
961
|
+
out = exempt_scripts_from_rocket_loader(html)
|
|
962
|
+
assert "data-cfasync" not in out
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
def test_exempt_scripts_ld_json_untouched() -> None:
|
|
966
|
+
html = '<script type="application/ld+json">{}</script>'
|
|
967
|
+
out = exempt_scripts_from_rocket_loader(html)
|
|
968
|
+
assert "data-cfasync" not in out
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
def test_exempt_scripts_idempotent_when_already_has_attr() -> None:
|
|
972
|
+
html = '<script data-cfasync="false" src="/a.js"></script>'
|
|
973
|
+
out = exempt_scripts_from_rocket_loader(html)
|
|
974
|
+
assert out.count("data-cfasync") == 1
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
def test_exempt_scripts_no_scripts_returns_same_object() -> None:
|
|
978
|
+
h = "<p>hi</p>"
|
|
979
|
+
assert exempt_scripts_from_rocket_loader(h) is h
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
def test_exempt_scripts_mixed_counts_correctly() -> None:
|
|
983
|
+
html = (
|
|
984
|
+
"<script>a()</script>"
|
|
985
|
+
'<script type="module">b()</script>'
|
|
986
|
+
'<script type="application/json">{}</script>'
|
|
987
|
+
)
|
|
988
|
+
out = exempt_scripts_from_rocket_loader(html)
|
|
989
|
+
assert out.count('data-cfasync="false"') == 2
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
# ---------------------------------------------------------------------------
|
|
993
|
+
# Integration tests through SiteBuilder.process_page_html
|
|
994
|
+
# ---------------------------------------------------------------------------
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
def test_process_page_html_rocket_loader_default_on() -> None:
|
|
998
|
+
"""Default config (rocket_loader_optout not set) must inject data-cfasync."""
|
|
999
|
+
builder = _make_builder()
|
|
1000
|
+
html = '<html><head></head><body><script type="module">x()</script></body></html>'
|
|
1001
|
+
out = builder.process_page_html(html)
|
|
1002
|
+
assert 'data-cfasync="false"' in out
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
def test_process_page_html_rocket_loader_optout_false_skips_injection() -> None:
|
|
1006
|
+
"""rocket_loader_optout=False must leave scripts untouched."""
|
|
1007
|
+
paths = BuildPaths(
|
|
1008
|
+
root=Path("."),
|
|
1009
|
+
src_docs=Path("."),
|
|
1010
|
+
markdown=Path("."),
|
|
1011
|
+
static_docs=Path("."),
|
|
1012
|
+
webflow_cache=Path("."),
|
|
1013
|
+
build_docs=Path("."),
|
|
1014
|
+
public=Path("."),
|
|
1015
|
+
old_pages_config=Path("."),
|
|
1016
|
+
)
|
|
1017
|
+
builder = SiteBuilder(paths)
|
|
1018
|
+
# Inject config directly (no file path needed for this test)
|
|
1019
|
+
builder.config = {"rocket_loader_optout": False}
|
|
1020
|
+
html = '<html><head></head><body><script type="module">x()</script></body></html>'
|
|
1021
|
+
out = builder.process_page_html(html)
|
|
1022
|
+
assert "data-cfasync" not in out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fontlab_www_toolkit-1.0.5.dev3 → fontlab_www_toolkit-1.0.6.dev1}/src/fontlab_www_toolkit/deploy.py
RENAMED
|
File without changes
|