crieur 1.5.0__tar.gz → 1.6.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.

Potentially problematic release.


This version of crieur might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: crieur
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: A Static Revue Generator.
5
5
  Project-URL: Homepage, https://gitlab.huma-num.fr/ecrinum/crieur
6
6
  Project-URL: Issues, https://gitlab.huma-num.fr/ecrinum/crieur/-/issues
@@ -689,6 +689,7 @@ Requires-Dist: httpx
689
689
  Requires-Dist: jinja2
690
690
  Requires-Dist: minicli
691
691
  Requires-Dist: mistune
692
+ Requires-Dist: pillow
692
693
  Requires-Dist: python-slugify
693
694
  Requires-Dist: pytz>=2025.2
694
695
  Requires-Dist: pyyaml>=6.0.2
@@ -1,4 +1,4 @@
1
1
  from pathlib import Path
2
2
 
3
- VERSION = "1.5.0"
3
+ VERSION = "1.6.0"
4
4
  ROOT_DIR = Path(__file__).parent
@@ -45,7 +45,7 @@ def generate(
45
45
  numeros = []
46
46
  for numero in each_folder_from(source_path):
47
47
  for corpus_yaml in each_file_from(numero, pattern="*.yaml"):
48
- numero = configure_numero(corpus_yaml)
48
+ numero = configure_numero(corpus_yaml, base_url)
49
49
  numeros.append(numero)
50
50
 
51
51
  keywords = collect_keywords(numeros)
@@ -113,7 +113,7 @@ def generate_feed(title, base_url, numeros, extra_vars, target_path, number, lan
113
113
  )
114
114
  for author in article.authors:
115
115
  feed_entry.author(name=str(author))
116
- feed_entry.summary(summary=md(article.content_md), type="html")
116
+ feed_entry.summary(summary=article.content_html, type="html")
117
117
  if article.keywords:
118
118
  for keyword in article.keywords:
119
119
  feed_entry.category(term=keyword.name)
@@ -1,13 +1,67 @@
1
1
  from dataclasses import dataclass
2
2
  from datetime import datetime
3
+ from textwrap import dedent
3
4
  from typing import Optional
4
5
 
6
+ import mistune
5
7
  from dataclass_wizard import DatePattern, DumpMeta, YAMLWizard
6
8
  from dataclass_wizard import errors as dw_errors
9
+ from PIL import Image, UnidentifiedImageError
7
10
  from slugify import slugify
8
11
  from yaml.composer import ComposerError
9
12
 
10
13
 
14
+ class ImgsWithSizesRenderer(mistune.HTMLRenderer):
15
+ """Renders images as <figure>s and add sizes."""
16
+
17
+ def __init__(
18
+ self,
19
+ escape=True,
20
+ allow_harmful_protocols=None,
21
+ base_url=None,
22
+ article=None,
23
+ ):
24
+ super().__init__()
25
+ self._base_url = base_url
26
+ self._article = article
27
+
28
+ def paragraph(self, text):
29
+ # In case of a figure, we do not want the (non-standard) paragraph.
30
+ if text.strip().startswith("<figure>"):
31
+ return text
32
+ return super().paragraph(text)
33
+
34
+ def image(self, alt, url):
35
+ if self._article.images_path is None:
36
+ print(f"Image with URL `{url}` is discarded.")
37
+ return ""
38
+ full_path = self._article.images_path.resolve().parent / url
39
+ try:
40
+ image = Image.open(full_path)
41
+ except (IsADirectoryError, FileNotFoundError, UnidentifiedImageError):
42
+ print(f"`{full_path}` is not a valid image.")
43
+ return ""
44
+ width, height = image.size
45
+ caption = f"<figcaption>{alt}</figcaption>" if alt else ""
46
+ full_url = f"{self._base_url}{self._article.url}{url}"
47
+ return dedent(
48
+ f"""\
49
+ <figure>
50
+ <a href="{full_url}"
51
+ title="Cliquer pour une version haute résolution">
52
+ <img
53
+ src="{full_url}"
54
+ width="{width}" height="{height}"
55
+ loading="lazy"
56
+ decoding="async"
57
+ alt="{alt}">
58
+ </a>
59
+ {caption}
60
+ </figure>
61
+ """
62
+ )
63
+
64
+
11
65
  @dataclass
12
66
  class Numero(YAMLWizard):
13
67
  _id: str
@@ -19,7 +73,7 @@ class Numero(YAMLWizard):
19
73
  def __post_init__(self):
20
74
  self.slug = slugify(self.name)
21
75
 
22
- def configure_articles(self, yaml_path):
76
+ def configure_articles(self, yaml_path, base_url):
23
77
  # Preserves abstract_fr key (vs. abstract-fr) when converting to_yaml()
24
78
  DumpMeta(key_transform="SNAKE").bind_to(Article)
25
79
 
@@ -61,6 +115,15 @@ class Numero(YAMLWizard):
61
115
  else None
62
116
  )
63
117
  loaded_article.numero = self
118
+ md = mistune.create_markdown(
119
+ renderer=ImgsWithSizesRenderer(
120
+ escape=False,
121
+ base_url=base_url,
122
+ article=loaded_article,
123
+ ),
124
+ plugins=["footnotes", "superscript"],
125
+ )
126
+ loaded_article.content_html = md(loaded_article.content_md)
64
127
  loaded_articles.append(loaded_article)
65
128
  self.articles = sorted(loaded_articles, reverse=True)
66
129
 
@@ -94,7 +157,7 @@ class Article(YAMLWizard):
94
157
  return f"numero/{self.numero.slug}/article/{self.id}/"
95
158
 
96
159
 
97
- def configure_numero(yaml_path):
160
+ def configure_numero(yaml_path, base_url):
98
161
  # Preserves abstract_fr key (vs. abstract-fr) when converting to_yaml()
99
162
  DumpMeta(key_transform="SNAKE").bind_to(Numero)
100
163
 
@@ -103,7 +166,7 @@ def configure_numero(yaml_path):
103
166
  except ComposerError:
104
167
  numero = Numero.from_yaml(yaml_path.read_text().split("---")[1])
105
168
 
106
- numero.configure_articles(yaml_path)
169
+ numero.configure_articles(yaml_path, base_url)
107
170
  return numero
108
171
 
109
172
 
@@ -34,7 +34,7 @@
34
34
  {% endfor %}
35
35
  {% endif %}
36
36
 
37
- {{ article.content_md|markdown }}
37
+ {{ article.content_html }}
38
38
  </div>
39
39
  </article>
40
40
  {% endblock content %}
@@ -16,6 +16,7 @@ dependencies = [
16
16
  "Jinja2",
17
17
  "minicli",
18
18
  "mistune",
19
+ "pillow",
19
20
  "python-slugify",
20
21
  "unidecode",
21
22
  "tzdata>=2025.2",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes