crieur 1.5.0__py3-none-any.whl → 1.7.0__py3-none-any.whl
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.
- crieur/__init__.py +1 -1
- crieur/cli.py +4 -3
- crieur/generator.py +7 -2
- crieur/models.py +66 -3
- crieur/templates/article.html +1 -1
- {crieur-1.5.0.dist-info → crieur-1.7.0.dist-info}/METADATA +6 -1
- {crieur-1.5.0.dist-info → crieur-1.7.0.dist-info}/RECORD +10 -10
- {crieur-1.5.0.dist-info → crieur-1.7.0.dist-info}/WHEEL +0 -0
- {crieur-1.5.0.dist-info → crieur-1.7.0.dist-info}/entry_points.txt +0 -0
- {crieur-1.5.0.dist-info → crieur-1.7.0.dist-info}/licenses/LICENSE +0 -0
crieur/__init__.py
CHANGED
crieur/cli.py
CHANGED
|
@@ -27,6 +27,7 @@ def generate(
|
|
|
27
27
|
extra_vars: str = "",
|
|
28
28
|
target_path: Path = Path() / "public",
|
|
29
29
|
source_path: Path = Path() / "sources",
|
|
30
|
+
statics_path: Path = Path(__file__).parent / "statics",
|
|
30
31
|
templates_path: Path = Path(__file__).parent / "templates",
|
|
31
32
|
without_statics: bool = False,
|
|
32
33
|
feed_limit: int = 10,
|
|
@@ -38,6 +39,7 @@ def generate(
|
|
|
38
39
|
:extra_vars: stringified JSON extra vars passed to the templates.
|
|
39
40
|
:target_path: Path where site is built (default: /public/).
|
|
40
41
|
:source_path: Path where stylo source were downloaded (default: /sources/).
|
|
42
|
+
:statics_path: Path where statics are located (default: @crieur/statics/).
|
|
41
43
|
:template_path: Path where templates are located (default: @crieur/templates/).
|
|
42
44
|
:without_statics: Do not copy statics if True (default: False).
|
|
43
45
|
:feed_limit: Number of max items in the feed (default: 10).
|
|
@@ -45,7 +47,7 @@ def generate(
|
|
|
45
47
|
numeros = []
|
|
46
48
|
for numero in each_folder_from(source_path):
|
|
47
49
|
for corpus_yaml in each_file_from(numero, pattern="*.yaml"):
|
|
48
|
-
numero = configure_numero(corpus_yaml)
|
|
50
|
+
numero = configure_numero(corpus_yaml, base_url)
|
|
49
51
|
numeros.append(numero)
|
|
50
52
|
|
|
51
53
|
keywords = collect_keywords(numeros)
|
|
@@ -63,8 +65,7 @@ def generate(
|
|
|
63
65
|
generate_feed(title, base_url, numeros, extra_vars, target_path, number=feed_limit)
|
|
64
66
|
|
|
65
67
|
if not without_statics:
|
|
66
|
-
|
|
67
|
-
shutil.copytree(static_path_local, target_path / "statics", dirs_exist_ok=True)
|
|
68
|
+
shutil.copytree(statics_path, target_path / "statics", dirs_exist_ok=True)
|
|
68
69
|
|
|
69
70
|
|
|
70
71
|
@cli
|
crieur/generator.py
CHANGED
|
@@ -2,6 +2,7 @@ import json
|
|
|
2
2
|
import locale
|
|
3
3
|
import shutil
|
|
4
4
|
from datetime import datetime, timedelta, timezone
|
|
5
|
+
from pathlib import Path
|
|
5
6
|
|
|
6
7
|
import mistune
|
|
7
8
|
from feedgen.feed import FeedGenerator
|
|
@@ -27,7 +28,11 @@ def markdown(value):
|
|
|
27
28
|
def generate_html(
|
|
28
29
|
title, base_url, numeros, keywords, authors, extra_vars, target_path, templates_path
|
|
29
30
|
):
|
|
30
|
-
environment = Env(
|
|
31
|
+
environment = Env(
|
|
32
|
+
loader=FileSystemLoader(
|
|
33
|
+
[str(templates_path), str(Path(__file__).parent / "templates")]
|
|
34
|
+
)
|
|
35
|
+
)
|
|
31
36
|
environment.filters["slugify"] = slugify_
|
|
32
37
|
environment.filters["markdown"] = markdown
|
|
33
38
|
|
|
@@ -113,7 +118,7 @@ def generate_feed(title, base_url, numeros, extra_vars, target_path, number, lan
|
|
|
113
118
|
)
|
|
114
119
|
for author in article.authors:
|
|
115
120
|
feed_entry.author(name=str(author))
|
|
116
|
-
feed_entry.summary(summary=
|
|
121
|
+
feed_entry.summary(summary=article.content_html, type="html")
|
|
117
122
|
if article.keywords:
|
|
118
123
|
for keyword in article.keywords:
|
|
119
124
|
feed_entry.category(term=keyword.name)
|
crieur/models.py
CHANGED
|
@@ -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
|
|
crieur/templates/article.html
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: crieur
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.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
|
|
@@ -753,6 +754,7 @@ cog.out(f"```\n{help}\n```")
|
|
|
753
754
|
```
|
|
754
755
|
[--extra-vars EXTRA_VARS] [--target-path TARGET_PATH]
|
|
755
756
|
[--source-path SOURCE_PATH]
|
|
757
|
+
[--statics-path STATICS_PATH]
|
|
756
758
|
[--templates-path TEMPLATES_PATH] [--without-statics]
|
|
757
759
|
[--feed-limit FEED_LIMIT]
|
|
758
760
|
|
|
@@ -767,6 +769,9 @@ options:
|
|
|
767
769
|
--source-path SOURCE_PATH
|
|
768
770
|
Path where stylo source were downloaded (default:
|
|
769
771
|
/sources/).
|
|
772
|
+
--statics-path STATICS_PATH
|
|
773
|
+
Path where statics are located (default:
|
|
774
|
+
@crieur/statics/).
|
|
770
775
|
--templates-path TEMPLATES_PATH
|
|
771
776
|
--without-statics Do not copy statics if True (default: False).
|
|
772
777
|
--feed-limit FEED_LIMIT
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
crieur/__init__.py,sha256=
|
|
1
|
+
crieur/__init__.py,sha256=I-oN_DJHUd7dkTJ8uqE26Pn84CyxcOXovlL7I7N4yNE,77
|
|
2
2
|
crieur/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
|
|
3
|
-
crieur/cli.py,sha256=
|
|
4
|
-
crieur/generator.py,sha256=
|
|
5
|
-
crieur/models.py,sha256=
|
|
3
|
+
crieur/cli.py,sha256=trYYSwcYsyPoWluZSVLoSA-8w86uQy3Wnw_w6724g8k,5809
|
|
4
|
+
crieur/generator.py,sha256=WeDqYNnAhkauBrY4R5zNXfWfYdDS73HdSeFcLEKmZU0,4491
|
|
5
|
+
crieur/models.py,sha256=KrW6gy7z0RzDBdUAd2VgwzcNkMOpdRPnu9JxvkNGZ8c,8727
|
|
6
6
|
crieur/utils.py,sha256=kIdxpd5LgVv13Lx2aEXzjQttBDtcppRlwNsH0vwX8f0,1566
|
|
7
7
|
crieur/statics/pico.css,sha256=VdrimW9PLcEIzqJ__s062OrwBj_Jb6jZIwbtdqOtM-w,93407
|
|
8
|
-
crieur/templates/article.html,sha256=
|
|
8
|
+
crieur/templates/article.html,sha256=AgqMIM0HG9IDFZ8tArsCLgbLmx86oY-HC6Jj2lgzUMg,1281
|
|
9
9
|
crieur/templates/author.html,sha256=1VHZi6Wld1gWYPfeW3cEJ2ULOKrp9xoCVRhDjPUDdHg,420
|
|
10
10
|
crieur/templates/base.html,sha256=4ZOLAnmle0_m8Y3lWT6wcH8f-_7SymxEDeIUzDQNnks,1626
|
|
11
11
|
crieur/templates/homepage.html,sha256=7YG7kA4AFuyrSuqWeFAVj09ogwsybE7w0-NKMLWms5s,2994
|
|
12
12
|
crieur/templates/keyword.html,sha256=Hv3Ep3R6oN5pBw14gfQT-aeqEiuFiatmVZLWn5hR1e4,428
|
|
13
13
|
crieur/templates/numero.html,sha256=F7hCaAHJ1WRWxD_zfhJzyLaiwXblJWJF7DUTy41Mnu8,1849
|
|
14
|
-
crieur-1.
|
|
15
|
-
crieur-1.
|
|
16
|
-
crieur-1.
|
|
17
|
-
crieur-1.
|
|
18
|
-
crieur-1.
|
|
14
|
+
crieur-1.7.0.dist-info/METADATA,sha256=pRi6qHf6g3NveR_--Or1AuMCMEOfTXL0pay7A_PyqEc,45237
|
|
15
|
+
crieur-1.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
16
|
+
crieur-1.7.0.dist-info/entry_points.txt,sha256=edmbmPxs9QXyvSMpPJBDPGw3vZOJEKqXJhysYNx3QSM,43
|
|
17
|
+
crieur-1.7.0.dist-info/licenses/LICENSE,sha256=F5acw9_laHeyi4wPmQyf_ttyz81VqCIwScwO8C1FhXU,34519
|
|
18
|
+
crieur-1.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|