crieur 1.0.5__tar.gz → 1.2.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.0.5
3
+ Version: 1.2.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
@@ -750,17 +750,23 @@ help = output.decode().split("\n", 1)[1] # Remove Pandoc version.
750
750
  cog.out(f"```\n{help}\n```")
751
751
  ]]] -->
752
752
  ```
753
- [--target-path TARGET_PATH] [--source-path SOURCE_PATH]
753
+ [--extra-vars EXTRA_VARS] [--target-path TARGET_PATH]
754
+ [--source-path SOURCE_PATH]
755
+ [--templates-path TEMPLATES_PATH] [--without-statics]
754
756
 
755
757
  options:
756
758
  -h, --help show this help message and exit
757
759
  --title, -t TITLE Title of the website (default: Crieur).
758
760
  --base-url BASE_URL Base URL of the website, ending with / (default: /).
761
+ --extra-vars EXTRA_VARS
762
+ stringified JSON extra vars passed to the templates.
759
763
  --target-path TARGET_PATH
760
764
  Path where site is built (default: /public/).
761
765
  --source-path SOURCE_PATH
762
766
  Path where stylo source were downloaded (default:
763
767
  /sources/).
768
+ --templates-path TEMPLATES_PATH
769
+ --without-statics Do not copy statics if True (default: False).
764
770
 
765
771
  ```
766
772
  <!-- [[[end]]] -->
@@ -46,17 +46,23 @@ help = output.decode().split("\n", 1)[1] # Remove Pandoc version.
46
46
  cog.out(f"```\n{help}\n```")
47
47
  ]]] -->
48
48
  ```
49
- [--target-path TARGET_PATH] [--source-path SOURCE_PATH]
49
+ [--extra-vars EXTRA_VARS] [--target-path TARGET_PATH]
50
+ [--source-path SOURCE_PATH]
51
+ [--templates-path TEMPLATES_PATH] [--without-statics]
50
52
 
51
53
  options:
52
54
  -h, --help show this help message and exit
53
55
  --title, -t TITLE Title of the website (default: Crieur).
54
56
  --base-url BASE_URL Base URL of the website, ending with / (default: /).
57
+ --extra-vars EXTRA_VARS
58
+ stringified JSON extra vars passed to the templates.
55
59
  --target-path TARGET_PATH
56
60
  Path where site is built (default: /public/).
57
61
  --source-path SOURCE_PATH
58
62
  Path where stylo source were downloaded (default:
59
63
  /sources/).
64
+ --templates-path TEMPLATES_PATH
65
+ --without-statics Do not copy statics if True (default: False).
60
66
 
61
67
  ```
62
68
  <!-- [[[end]]] -->
@@ -1,4 +1,4 @@
1
1
  from pathlib import Path
2
2
 
3
- VERSION = "1.0.5"
3
+ VERSION = "1.2.0"
4
4
  ROOT_DIR = Path(__file__).parent
@@ -22,17 +22,23 @@ def version():
22
22
 
23
23
  @cli
24
24
  def generate(
25
- title="Crieur",
26
- base_url="/",
25
+ title: str = "Crieur",
26
+ base_url: str = "/",
27
+ extra_vars: str = "",
27
28
  target_path: Path = Path() / "public",
28
29
  source_path: Path = Path() / "sources",
30
+ templates_path: Path = Path(__file__).parent / "templates",
31
+ without_statics: bool = False,
29
32
  ):
30
33
  """Generate a new revue website.
31
34
 
32
35
  :title: Title of the website (default: Crieur).
33
36
  :base_url: Base URL of the website, ending with / (default: /).
37
+ :extra_vars: stringified JSON extra vars passed to the templates.
34
38
  :target_path: Path where site is built (default: /public/).
35
39
  :source_path: Path where stylo source were downloaded (default: /sources/).
40
+ :template_path: Path where templates are located (default: @crieur/templates/).
41
+ :without_statics: Do not copy statics if True (default: False).
36
42
  """
37
43
  numeros = []
38
44
  for numero in each_folder_from(source_path):
@@ -41,10 +47,13 @@ def generate(
41
47
  numeros.append(numero)
42
48
 
43
49
  keywords = collect_keywords(numeros)
44
- generate_html(title, base_url, numeros, keywords, target_path)
50
+ generate_html(
51
+ title, base_url, numeros, keywords, extra_vars, target_path, templates_path
52
+ )
45
53
 
46
- static_path_local = Path(__file__).parent / "statics"
47
- shutil.copytree(static_path_local, target_path / "statics", dirs_exist_ok=True)
54
+ if not without_statics:
55
+ static_path_local = Path(__file__).parent / "statics"
56
+ shutil.copytree(static_path_local, target_path / "statics", dirs_exist_ok=True)
48
57
 
49
58
 
50
59
  @cli
@@ -1,40 +1,43 @@
1
+ import json
1
2
  import locale
2
3
  import shutil
3
- from pathlib import Path
4
4
 
5
5
  import mistune
6
6
  from jinja2 import Environment as Env
7
7
  from jinja2 import FileSystemLoader
8
8
  from slugify import slugify
9
9
 
10
+ from . import VERSION
10
11
  from .utils import neighborhood
11
12
 
12
13
  locale.setlocale(locale.LC_ALL, "")
13
- environment = Env(loader=FileSystemLoader(str(Path(__file__).parent / "templates")))
14
+ md = mistune.create_markdown(plugins=["footnotes", "superscript"])
14
15
 
15
16
 
16
17
  def slugify_(value):
17
18
  return slugify(value)
18
19
 
19
20
 
20
- environment.filters["slugify"] = slugify_
21
-
22
- md = mistune.create_markdown(plugins=["footnotes", "superscript"])
23
-
24
-
25
21
  def markdown(value):
26
22
  return md(value) if value else ""
27
23
 
28
24
 
29
- environment.filters["markdown"] = markdown
25
+ def generate_html(
26
+ title, base_url, numeros, keywords, extra_vars, target_path, templates_path
27
+ ):
28
+ environment = Env(loader=FileSystemLoader(str(templates_path)))
29
+ environment.filters["slugify"] = slugify_
30
+ environment.filters["markdown"] = markdown
30
31
 
32
+ extra_vars = json.loads(extra_vars) if extra_vars else {}
31
33
 
32
- def generate_html(title, base_url, numeros, keywords, target_path):
33
34
  common_params = {
34
35
  "title": title,
35
36
  "base_url": base_url,
36
37
  "numeros": numeros,
37
38
  "keywords": keywords,
39
+ "crieur_version": VERSION,
40
+ **extra_vars,
38
41
  }
39
42
 
40
43
  template_homepage = environment.get_template("homepage.html")
@@ -45,7 +48,7 @@ def generate_html(title, base_url, numeros, keywords, target_path):
45
48
  for numero in numeros:
46
49
  template_numero = environment.get_template("numero.html")
47
50
  content = template_numero.render(numero=numero, **common_params)
48
- numero_folder = target_path / "numero" / numero.name
51
+ numero_folder = target_path / "numero" / numero.slug
49
52
  numero_folder.mkdir(parents=True, exist_ok=True)
50
53
  (numero_folder / "index.html").write_text(content)
51
54
 
@@ -14,6 +14,9 @@ class Numero(YAMLWizard):
14
14
  metadata: str
15
15
  articles: list
16
16
 
17
+ def __post_init__(self):
18
+ self.slug = slugify(self.name)
19
+
17
20
  def configure_articles(self, yaml_path):
18
21
  # Preserves abstract_fr key (vs. abstract-fr) when converting to_yaml()
19
22
  DumpMeta(key_transform="SNAKE").bind_to(Article)
@@ -50,15 +53,18 @@ class Numero(YAMLWizard):
50
53
  class Article(YAMLWizard):
51
54
  title: str
52
55
  title_f: str
53
- date: Optional[DatePattern["%Y/%m/%d"]] # noqa: F722
54
56
  id: str = ""
55
57
  subtitle: str = ""
56
58
  subtitle_f: str = ""
57
59
  content_md: str = ""
60
+ date: Optional[DatePattern["%Y/%m/%d"]] = None # noqa: F722
58
61
  authors: list = None
59
62
  abstract: list = None
60
63
  keywords: list = None
61
64
 
65
+ def __post_init__(self):
66
+ self.slug = slugify(self.title)
67
+
62
68
 
63
69
  def configure_numero(yaml_path):
64
70
  # Preserves abstract_fr key (vs. abstract-fr) when converting to_yaml()
@@ -1,7 +1,7 @@
1
1
  {% extends "base.html" %}
2
2
 
3
3
  {% block content %}
4
- <h2><a href="{{ base_url }}numeros/{{ numero.name }}">{{ numero.name }}</a></h2>
4
+ <h2><a href="{{ base_url }}numero/{{ numero.slug }}/">{{ numero.name }}</a></h2>
5
5
 
6
6
  <article>
7
7
  <header>
@@ -4,6 +4,7 @@
4
4
  <!-- Has to be within the first 1024 bytes, hence before the <title>
5
5
  See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
6
6
  <meta charset="utf-8" />
7
+ <meta name="generator" content="Crieur {{ crieur_version }}">
7
8
  <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
8
9
  <!-- The viewport meta is quite crowded and we are responsible for that.
9
10
  See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
@@ -75,13 +75,13 @@
75
75
  <article>
76
76
  <header>
77
77
  <hgroup>
78
- <h2><a href="{{ base_url }}numero/{{ numero.name }}/">{{ numero.name }}</a></h2>
78
+ <h2><a href="{{ base_url }}numero/{{ numero.slug }}/">{{ numero.name }}</a></h2>
79
79
  <p>Le {{ numero.articles.0.date.strftime('%d %B %Y') }}</p>
80
80
  </hgroup>
81
81
  </header>
82
82
  <ul>
83
83
  {% for article in numero.articles %}
84
- <li><a href="{{ base_url }}numero/{{ numero.name }}/article/{{ article.id }}/">{{ article.title_f }}</a></li>
84
+ <li><a href="{{ base_url }}numero/{{ numero.slug }}/article/{{ article.id }}/">{{ article.title_f }}</a></li>
85
85
  {% endfor %}
86
86
  </ul>
87
87
  </article>
@@ -9,7 +9,7 @@
9
9
  <div>
10
10
  <ul>
11
11
  {% for article in keyword.articles %}
12
- <li><a href="{{ base_url }}numero/{{ article.numero.name }}/article/{{ article.id }}/">{{ article.title_f }}</a></li>
12
+ <li><a href="{{ base_url }}numero/{{ article.numero.slug }}/article/{{ article.id }}/">{{ article.title_f }}</a></li>
13
13
  {% endfor %}
14
14
  </ul>
15
15
  </div>
@@ -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.name }}/article/{{ article.id }}/">{{ article.title_f }}</a></h3>
62
+ <h3><a href="{{ base_url }}numero/{{ numero.slug }}/article/{{ article.id }}/">{{ article.title_f }}</a></h3>
63
63
  </header>
64
64
  {{ article.subtitle_f|markdown }}
65
65
  {% if article.authors %}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes