blurry-cli 0.6.2__tar.gz → 0.7.0__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.
Files changed (28) hide show
  1. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/PKG-INFO +2 -1
  2. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/__init__.py +10 -1
  3. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/markdown/__init__.py +1 -1
  4. blurry_cli-0.7.0/blurry/schema_validation.py +61 -0
  5. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/pyproject.toml +3 -2
  6. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/LICENSE +0 -0
  7. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/README.md +0 -0
  8. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/__main__.py +0 -0
  9. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/async_typer.py +0 -0
  10. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/cli.py +0 -0
  11. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/constants.py +0 -0
  12. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/images.py +0 -0
  13. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/markdown/front_matter.py +0 -0
  14. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/markdown/renderer_functions/__init__.py +0 -0
  15. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/markdown/renderer_functions/render_video.py +0 -0
  16. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/open_graph.py +0 -0
  17. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/plugins/__init__.py +0 -0
  18. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/plugins/html_plugins/__init__.py +0 -0
  19. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/plugins/html_plugins/minify_html_plugin.py +0 -0
  20. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/plugins/markdown_plugins/__init__.py +0 -0
  21. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/plugins/markdown_plugins/container_plugin.py +0 -0
  22. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/plugins/markdown_plugins/punctuation_plugin.py +0 -0
  23. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/plugins/markdown_plugins/python_code_plugin.py +0 -0
  24. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/py.typed +0 -0
  25. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/settings.py +0 -0
  26. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/sitemap.py +0 -0
  27. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/types.py +0 -0
  28. {blurry_cli-0.6.2 → blurry_cli-0.7.0}/blurry/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blurry-cli
3
- Version: 0.6.2
3
+ Version: 0.7.0
4
4
  Summary: A Mistune-based static site generator for Python
5
5
  Home-page: https://github.com/blurry-dev/blurry
6
6
  License: MIT
@@ -27,6 +27,7 @@ Requires-Dist: ffmpeg-python (>=0.2.0,<0.3.0)
27
27
  Requires-Dist: htmlmin2 (>=0.1.13,<0.2.0)
28
28
  Requires-Dist: livereload (>=2.6.3,<3.0.0)
29
29
  Requires-Dist: mistune (>=3.0.0rc5,<4.0.0)
30
+ Requires-Dist: pydantic2-schemaorg (>=0.1.1,<0.2.0)
30
31
  Requires-Dist: rich (>=13.3.3,<14.0.0)
31
32
  Requires-Dist: selectolax (>=0.3.6,<0.4.0)
32
33
  Requires-Dist: toml (>=0.10.2,<0.11.0)
@@ -15,6 +15,7 @@ from jinja2 import FileSystemLoader
15
15
  from jinja2 import select_autoescape
16
16
  from livereload import Server
17
17
  from rich import print
18
+ from rich.console import Console
18
19
 
19
20
  from blurry.async_typer import AsyncTyper
20
21
  from blurry.cli import print_blurry_name
@@ -25,6 +26,7 @@ from blurry.markdown import convert_markdown_file_to_html
25
26
  from blurry.open_graph import open_graph_meta_tags
26
27
  from blurry.plugins import discovered_html_plugins
27
28
  from blurry.plugins import discovered_jinja_filter_plugins
29
+ from blurry.schema_validation import validate_front_matter_as_schema
28
30
  from blurry.settings import get_build_directory
29
31
  from blurry.settings import get_content_directory
30
32
  from blurry.settings import get_templates_directory
@@ -46,6 +48,8 @@ def json_converter_with_dates(item: Any) -> None | str:
46
48
  return item.strftime("%Y-%M-%D")
47
49
 
48
50
 
51
+ warning_console = Console(stderr=True, style="bold yellow")
52
+
49
53
  print_blurry_name()
50
54
  print_plugin_table()
51
55
 
@@ -147,6 +151,9 @@ async def write_html_file(
147
151
  format_schema_data(schema_variables),
148
152
  default=json_converter_with_dates,
149
153
  )
154
+
155
+ validate_front_matter_as_schema(file_data.path, front_matter, warning_console)
156
+
150
157
  schema_type_tag = f'<script type="application/ld+json">{schema_data}</script>'
151
158
 
152
159
  template_context = {
@@ -236,8 +243,10 @@ async def build(release=True):
236
243
  print(f"Blurring {len(markdown_tasks)} Markdown files from: {content_dir_relative}")
237
244
 
238
245
  await asyncio.gather(*markdown_tasks)
246
+ loop = asyncio.new_event_loop()
247
+ asyncio.set_event_loop(loop)
239
248
  for non_markdown_task in non_markdown_tasks:
240
- await asyncio.to_thread(lambda: asyncio.run(non_markdown_task))
249
+ await asyncio.to_thread(lambda: loop.run_until_complete(non_markdown_task))
241
250
 
242
251
  end = datetime.now()
243
252
 
@@ -85,7 +85,7 @@ class BlurryRenderer(mistune.HTMLRenderer):
85
85
  avif_srcset = generate_srcset_string(
86
86
  src.replace(extension, "avif"), image_widths
87
87
  )
88
- source_tag = '<source srcset="{}" sizes="{}" />'.format(
88
+ source_tag = '<source srcset="{}" sizes="{}" type="image/avif" />'.format(
89
89
  avif_srcset, attributes["sizes"]
90
90
  )
91
91
 
@@ -0,0 +1,61 @@
1
+ import importlib
2
+ from collections.abc import MutableMapping
3
+ from pathlib import Path
4
+
5
+ from pydantic.v1 import ValidationError
6
+ from rich.console import Console
7
+
8
+ from blurry.settings import SETTINGS
9
+ from blurry.settings import update_settings
10
+
11
+
12
+ class Config:
13
+ extra = "forbid"
14
+
15
+
16
+ def validate_front_matter_as_schema(
17
+ path: Path, front_matter: MutableMapping, console: Console
18
+ ):
19
+ """
20
+ Validates schema data using pydantic_schemaorg, disallowing extra fields
21
+ """
22
+ update_settings()
23
+
24
+ schema_type = front_matter["@type"]
25
+
26
+ if mapped_schema_type := SETTINGS["TEMPLATE_SCHEMA_TYPES"].get(schema_type):
27
+ schema_type = mapped_schema_type
28
+
29
+ # Import pydantic_schemaorg model
30
+ try:
31
+ pydantic_schemaorg_model_module = importlib.import_module(
32
+ f"pydantic2_schemaorg.{schema_type}"
33
+ )
34
+ except ModuleNotFoundError:
35
+ console.print(
36
+ f"{path}: Could not find Schema type for {schema_type}. Skipping."
37
+ )
38
+ return
39
+
40
+ schema_model = getattr(pydantic_schemaorg_model_module, schema_type)
41
+
42
+ # Create new Pydantic model that forbids extra fields
43
+ class NonExtraSchemaModel(schema_model, extra="forbid"): # type: ignore
44
+ pass
45
+
46
+ # Validate model and print errors
47
+ try:
48
+ non_schema_variable_prefix = SETTINGS["FRONTMATTER_NON_SCHEMA_VARIABLE_PREFIX"]
49
+ schema_front_matter = {
50
+ k: v
51
+ for k, v in front_matter.items()
52
+ if not k.startswith(non_schema_variable_prefix)
53
+ }
54
+ NonExtraSchemaModel(**schema_front_matter)
55
+ except ValidationError as e:
56
+ for error in e.errors():
57
+ msg = error["msg"]
58
+ loc = error["loc"]
59
+ console.print(
60
+ f"{path}: {schema_type} schema validation error: {msg}: {loc}"
61
+ )
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "blurry-cli"
3
- version = "0.6.2"
3
+ version = "0.7.0"
4
4
  description = "A Mistune-based static site generator for Python"
5
5
  authors = ["John Franey <franey@duck.com>"]
6
6
  license = "MIT"
@@ -35,13 +35,14 @@ selectolax = "^0.3.6"
35
35
  toml = "^0.10.2"
36
36
  typer = "^0.6.1"
37
37
  htmlmin2 = "^0.1.13"
38
+ pydantic2-schemaorg = "^0.1.1"
38
39
 
39
40
  [tool.poetry.scripts]
40
41
  blurry = 'blurry:main'
41
42
 
42
43
  [tool.poetry.group.dev.dependencies]
43
44
  black = "^22.10.0"
44
- nox = "^2023.4.22"
45
+ nox = "^2024.03.02"
45
46
  pyright = "^1.1.311"
46
47
  pytest = "^6.2.2"
47
48
  pytest-cov = "^2.11.1"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes