crieur 1.3.2__py3-none-any.whl → 1.5.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 CHANGED
@@ -1,4 +1,4 @@
1
1
  from pathlib import Path
2
2
 
3
- VERSION = "1.3.2"
3
+ VERSION = "1.5.0"
4
4
  ROOT_DIR = Path(__file__).parent
crieur/cli.py CHANGED
@@ -9,7 +9,7 @@ import httpx
9
9
  from minicli import cli, run
10
10
 
11
11
  from . import VERSION
12
- from .generator import generate_html
12
+ from .generator import generate_feed, generate_html
13
13
  from .models import collect_authors, collect_keywords, configure_numero
14
14
  from .utils import each_file_from, each_folder_from
15
15
 
@@ -29,6 +29,7 @@ def generate(
29
29
  source_path: Path = Path() / "sources",
30
30
  templates_path: Path = Path(__file__).parent / "templates",
31
31
  without_statics: bool = False,
32
+ feed_limit: int = 10,
32
33
  ):
33
34
  """Generate a new revue website.
34
35
 
@@ -39,6 +40,7 @@ def generate(
39
40
  :source_path: Path where stylo source were downloaded (default: /sources/).
40
41
  :template_path: Path where templates are located (default: @crieur/templates/).
41
42
  :without_statics: Do not copy statics if True (default: False).
43
+ :feed_limit: Number of max items in the feed (default: 10).
42
44
  """
43
45
  numeros = []
44
46
  for numero in each_folder_from(source_path):
@@ -58,6 +60,7 @@ def generate(
58
60
  target_path,
59
61
  templates_path,
60
62
  )
63
+ generate_feed(title, base_url, numeros, extra_vars, target_path, number=feed_limit)
61
64
 
62
65
  if not without_statics:
63
66
  static_path_local = Path(__file__).parent / "statics"
crieur/generator.py CHANGED
@@ -1,8 +1,10 @@
1
1
  import json
2
2
  import locale
3
3
  import shutil
4
+ from datetime import datetime, timedelta, timezone
4
5
 
5
6
  import mistune
7
+ from feedgen.feed import FeedGenerator
6
8
  from jinja2 import Environment as Env
7
9
  from jinja2 import FileSystemLoader
8
10
  from slugify import slugify
@@ -83,3 +85,38 @@ def generate_html(
83
85
  author_folder = target_path / "auteur" / author.slug
84
86
  author_folder.mkdir(parents=True, exist_ok=True)
85
87
  (author_folder / "index.html").write_text(content)
88
+
89
+
90
+ def generate_feed(title, base_url, numeros, extra_vars, target_path, number, lang="fr"):
91
+ feed = FeedGenerator()
92
+ feed.id(base_url)
93
+ feed.title(title)
94
+ feed.link(href=base_url, rel="alternate")
95
+ feed.link(href=f"{base_url}feed.xml", rel="self")
96
+ feed.language(lang)
97
+
98
+ articles = sorted(
99
+ [article for numero in numeros for article in numero.articles], reverse=True
100
+ )
101
+
102
+ for article in articles[:number]:
103
+ feed_entry = feed.add_entry(order="append")
104
+ feed_entry.id(f"{base_url}{article.url}")
105
+ feed_entry.title(article.title_f)
106
+ feed_entry.link(href=f"{base_url}{article.url}")
107
+ feed_entry.updated(
108
+ datetime.combine(
109
+ article.date,
110
+ datetime.min.time(),
111
+ tzinfo=timezone(timedelta(hours=-4), "ET"),
112
+ )
113
+ )
114
+ for author in article.authors:
115
+ feed_entry.author(name=str(author))
116
+ feed_entry.summary(summary=md(article.content_md), type="html")
117
+ if article.keywords:
118
+ for keyword in article.keywords:
119
+ feed_entry.category(term=keyword.name)
120
+
121
+ feed.atom_file(target_path / "feed.xml", pretty=True)
122
+ print(f"Generated meta-feed with {number} items.")
crieur/models.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from dataclasses import dataclass
2
+ from datetime import datetime
2
3
  from typing import Optional
3
4
 
4
5
  from dataclass_wizard import DatePattern, DumpMeta, YAMLWizard
@@ -40,6 +41,15 @@ class Numero(YAMLWizard):
40
41
  print(f"Metadata error in `{article['article']['title']}`:")
41
42
  print(e)
42
43
  exit(1)
44
+ if not loaded_article.date:
45
+ print(f"Article `{loaded_article.title}` skipped (no date).")
46
+ continue
47
+ if loaded_article.date > datetime.today().date():
48
+ print(
49
+ f"Article `{loaded_article.title}` skipped "
50
+ f"(future date: {loaded_article.date})."
51
+ )
52
+ continue
43
53
  if not loaded_article.id:
44
54
  loaded_article.id = article_slug
45
55
  loaded_article.content_md = (
@@ -79,6 +89,10 @@ class Article(YAMLWizard):
79
89
  return NotImplemented
80
90
  return self.date < other.date
81
91
 
92
+ @property
93
+ def url(self):
94
+ return f"numero/{self.numero.slug}/article/{self.id}/"
95
+
82
96
 
83
97
  def configure_numero(yaml_path):
84
98
  # Preserves abstract_fr key (vs. abstract-fr) when converting to_yaml()
@@ -17,6 +17,8 @@
17
17
  <link rel="icon" href="data:;base64,iVBORw0KGgo=" />
18
18
  <link rel="stylesheet"
19
19
  href="{{ base_url }}statics/pico.css" />
20
+ <link rel="alternate" type="application/atom+xml"
21
+ title="Feed" href="{{ base_url }}feed.xml">
20
22
  <style>
21
23
  h1 {
22
24
  text-align: center;
@@ -97,7 +97,7 @@
97
97
  </header>
98
98
  <ul>
99
99
  {% for article in numero.articles %}
100
- <li><a href="{{ base_url }}numero/{{ numero.slug }}/article/{{ article.id }}/">{{ article.title_f }}</a></li>
100
+ <li><a href="{{ base_url }}{{ article.url }}">{{ article.title_f }}</a></li>
101
101
  {% endfor %}
102
102
  </ul>
103
103
  </article>
@@ -59,7 +59,7 @@
59
59
  {% for article in numero.articles %}
60
60
  <article>
61
61
  <header>
62
- <h3><a href="{{ base_url }}numero/{{ numero.slug }}/article/{{ article.id }}/">{{ article.title_f }}</a></h3>
62
+ <h3><a href="{{ base_url }}{{ article.url }}">{{ article.title_f }}</a></h3>
63
63
  </header>
64
64
  {{ article.subtitle_f|markdown }}
65
65
  {% if article.authors %}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: crieur
3
- Version: 1.3.2
3
+ Version: 1.5.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
@@ -684,6 +684,7 @@ Classifier: Topic :: Software Development :: Build Tools
684
684
  Classifier: Topic :: Text Processing :: Markup :: Markdown
685
685
  Requires-Python: >=3.8
686
686
  Requires-Dist: dataclass-wizard
687
+ Requires-Dist: feedgen>=1.0.0
687
688
  Requires-Dist: httpx
688
689
  Requires-Dist: jinja2
689
690
  Requires-Dist: minicli
@@ -753,6 +754,7 @@ cog.out(f"```\n{help}\n```")
753
754
  [--extra-vars EXTRA_VARS] [--target-path TARGET_PATH]
754
755
  [--source-path SOURCE_PATH]
755
756
  [--templates-path TEMPLATES_PATH] [--without-statics]
757
+ [--feed-limit FEED_LIMIT]
756
758
 
757
759
  options:
758
760
  -h, --help show this help message and exit
@@ -767,6 +769,8 @@ options:
767
769
  /sources/).
768
770
  --templates-path TEMPLATES_PATH
769
771
  --without-statics Do not copy statics if True (default: False).
772
+ --feed-limit FEED_LIMIT
773
+ Number of max items in the feed (default: 10).
770
774
 
771
775
  ```
772
776
  <!-- [[[end]]] -->
@@ -0,0 +1,18 @@
1
+ crieur/__init__.py,sha256=E991QFU_-kmyKseQrDTcr_YjRxyBnwSe8uXpcBu-Yw8,77
2
+ crieur/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
3
+ crieur/cli.py,sha256=JASr1HoM6vx7ZRi3vdY6NVKqHxcNerKc0Bklnoex6HU,5727
4
+ crieur/generator.py,sha256=MURqkacHmqj8MpC6loQqrKQOk-lEYrknH-p8rFPCTmw,4388
5
+ crieur/models.py,sha256=Dc7zxYAEFM7MCm5RKu8NdN272FOSWCgwurpZ5rqSKp4,6566
6
+ crieur/utils.py,sha256=kIdxpd5LgVv13Lx2aEXzjQttBDtcppRlwNsH0vwX8f0,1566
7
+ crieur/statics/pico.css,sha256=VdrimW9PLcEIzqJ__s062OrwBj_Jb6jZIwbtdqOtM-w,93407
8
+ crieur/templates/article.html,sha256=4Y1sjBR1nM_ff4yVGgiVlZU1tmnfBMXAjTTSAhqoiA4,1288
9
+ crieur/templates/author.html,sha256=1VHZi6Wld1gWYPfeW3cEJ2ULOKrp9xoCVRhDjPUDdHg,420
10
+ crieur/templates/base.html,sha256=4ZOLAnmle0_m8Y3lWT6wcH8f-_7SymxEDeIUzDQNnks,1626
11
+ crieur/templates/homepage.html,sha256=7YG7kA4AFuyrSuqWeFAVj09ogwsybE7w0-NKMLWms5s,2994
12
+ crieur/templates/keyword.html,sha256=Hv3Ep3R6oN5pBw14gfQT-aeqEiuFiatmVZLWn5hR1e4,428
13
+ crieur/templates/numero.html,sha256=F7hCaAHJ1WRWxD_zfhJzyLaiwXblJWJF7DUTy41Mnu8,1849
14
+ crieur-1.5.0.dist-info/METADATA,sha256=ICGtHO0FWF7N8rdSRTDv5QKCIlxZkoiaNbxpP4VJiqQ,45024
15
+ crieur-1.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
+ crieur-1.5.0.dist-info/entry_points.txt,sha256=edmbmPxs9QXyvSMpPJBDPGw3vZOJEKqXJhysYNx3QSM,43
17
+ crieur-1.5.0.dist-info/licenses/LICENSE,sha256=F5acw9_laHeyi4wPmQyf_ttyz81VqCIwScwO8C1FhXU,34519
18
+ crieur-1.5.0.dist-info/RECORD,,
@@ -1,18 +0,0 @@
1
- crieur/__init__.py,sha256=DJCsh5YCCUnPqMvARcxvMvW9_H2ofVnJ1R5mclHnE5g,77
2
- crieur/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
3
- crieur/cli.py,sha256=YPzrXMG0DzXBWpCVK1SEG5v6A32gezR54D8Kj2DDNYA,5534
4
- crieur/generator.py,sha256=Vc0oOLsQMcKWQLkzHLrJf5f1W_qmoxwYsc_ktHFZjtg,3046
5
- crieur/models.py,sha256=512IUzmQ000z-m9sBojPR9WVfQDpNne6Nq2LaLPS9Z0,6042
6
- crieur/utils.py,sha256=kIdxpd5LgVv13Lx2aEXzjQttBDtcppRlwNsH0vwX8f0,1566
7
- crieur/statics/pico.css,sha256=VdrimW9PLcEIzqJ__s062OrwBj_Jb6jZIwbtdqOtM-w,93407
8
- crieur/templates/article.html,sha256=4Y1sjBR1nM_ff4yVGgiVlZU1tmnfBMXAjTTSAhqoiA4,1288
9
- crieur/templates/author.html,sha256=1VHZi6Wld1gWYPfeW3cEJ2ULOKrp9xoCVRhDjPUDdHg,420
10
- crieur/templates/base.html,sha256=6ih6RryTPXZxR6tqlbRHPpOFUNRu90SPvdfKNLHcRRM,1522
11
- crieur/templates/homepage.html,sha256=IgYc3cyw-52U3HN1oada0drkzT0fPNyFcdiG6Pwcr9o,3027
12
- crieur/templates/keyword.html,sha256=Hv3Ep3R6oN5pBw14gfQT-aeqEiuFiatmVZLWn5hR1e4,428
13
- crieur/templates/numero.html,sha256=b9J6aW_h9ao7XlWA0Xc390ahOH5lHDI8A4iDq6tEZTo,1882
14
- crieur-1.3.2.dist-info/METADATA,sha256=Fpzpq1CXeGyJ1QVw-6jqNjMGbkRvMJMvCBasDOLLL_Y,44848
15
- crieur-1.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- crieur-1.3.2.dist-info/entry_points.txt,sha256=edmbmPxs9QXyvSMpPJBDPGw3vZOJEKqXJhysYNx3QSM,43
17
- crieur-1.3.2.dist-info/licenses/LICENSE,sha256=F5acw9_laHeyi4wPmQyf_ttyz81VqCIwScwO8C1FhXU,34519
18
- crieur-1.3.2.dist-info/RECORD,,
File without changes