-
-
Notifications
You must be signed in to change notification settings - Fork 85
Fonctionnalité : ajoute une page listant les derniers articles #917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Guts
wants to merge
20
commits into
master
Choose a base branch
from
feature/liste-articles
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f8b538d
WIP Ajoute une page listant les derniers articles
Guts be7029c
Fix CSS path
Guts 495fd13
Ajout date
Guts 49c7da3
Ajoute la date formattée
Guts 8b1db57
Ajout mots-clés, sous-titre
Guts 772f619
Try to reconfigure locales
Guts a498b7c
Fix locale install
Guts 4f9bc42
Try to reconfigure locales
Guts a658ab6
Fix locale install
Guts 4266037
Quelques améliorations suite aux retours de @gounux
Guts 7b6fb1c
Ajout mots-clés
Guts ae34642
feature: utilise la date formatée en français
Guts 5f57567
virgule entre les mots-clés
Guts 7a1b814
cache le footer
Guts 31d27b3
Ajoute une virgule entre les mots-clés
Guts 863a84e
[pre-commit.ci] Corrections automatiques appliquées par les git hooks.
pre-commit-ci[bot] 5db7224
update(hook): exclue l'index des articles du hook bloc auteur
Guts 7c09481
update(hook): stocke les derniers contenus dans un fichier pour facil…
Guts fea01c8
update(hook): ajoute le filtre date_localized au template
Guts 69f1ad3
update(hook): utilise le filtre date_localized pour la liste des arti…
Guts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,3 +234,4 @@ linkchecker_report.html | |
| gource.ini | ||
| avatars/ | ||
| mkdocs-generated-configuration.yml | ||
| latest_content.yml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| title: "📖 Articles" | ||
|
|
||
| nav: | ||
| - "Derniers articles": index.md | ||
| - "2025" | ||
| - "2024" | ||
| - "2023" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| title: "Liste des derniers articles parus" | ||
| template: custom_templates/index_articles.html | ||
| # theme customizations | ||
| hide: | ||
| - footer | ||
| - navigation | ||
| - toc | ||
| search: | ||
| exclude: true | ||
| --- | ||
|
|
||
| <!-- Page qui utilise un template personnalisé (cf clé "template" dans l'en-tête) --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| {% extends "base.html" %} | ||
|
|
||
| {% block styles %} | ||
| {{ super() }} | ||
|
|
||
| <link rel=stylesheet href=../theme/assets/stylesheets/homepage.min.css> | ||
| {% endblock %} | ||
|
|
||
| <!-- Render hero under tabs --> | ||
| {% block tabs %} | ||
| {{ super() }} | ||
|
|
||
| <!-- Hero for landing page --> | ||
| <div class="tx-container"> | ||
| <div class="md-grid md-typeset"> | ||
| <div class="tx-hero"> | ||
| <div class="tx-hero__title"> | ||
| <h1 style="visibility: hidden">Geotribu</h1> | ||
| </div> | ||
| <div class="tx-hero__image"> | ||
| <img src="https://cdn.geotribu.fr/img/internal/charte/geotribu_logo_rectangle_384x80.png" | ||
| alt="Bannière Geotribu" draggable="false" title="logo Geotribu"> | ||
| </div> | ||
| <div class="tx-hero__content"> | ||
| <p>Site collaboratif sur la géomatique <span class="em">libre</span> et <span class="em">ouverte</span>.</p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- Content --> | ||
| <div class="md-container secondary-section"> | ||
| <div class="g"> | ||
| {% if config.extra.latest %}{% for contenu in config.extra.latest.articles %} | ||
| <div class="section" id="articles"> | ||
| <div class="component-wrapper"> | ||
| <div class="first-column"> | ||
| <a class="toclink" href="/{{ contenu.url_rel | default('/') }}"> | ||
| <h3>{{ contenu.title | default('Titre') }}</h3> | ||
| </a> | ||
|
|
||
| {% if contenu.subtitle %}<h4>{{ contenu.subtitle | default('Sous-titre') }}</h4>{% | ||
| endif | ||
| %} | ||
| {% for tag in contenu.tags %} | ||
| <a class="md-tag md-tag-icon" href="/tags/#tag:{{ tag | lower }}">{{ tag }}</a>{{ ", " if not loop.last else | ||
| "" }} | ||
| {% endfor %} | ||
| <h5>{{ "Publié le {}".format(contenu.date | date_localized ) | | ||
| default('vendredi 9 août 1985') }} par {{ contenu.authors | default('Prénom NOM') | join(", ") }}</h5> | ||
| <p>{{ contenu.description | default('Description') }}</p> | ||
| <a href="/{{ contenu.url_rel | default('/') }}" class="md-button">Lire cet article...</a> | ||
| </div> | ||
| <div class="second-column"> | ||
| <div class="image-wrapper"> | ||
| <a href="/{{ contenu.url_rel | default('/') }}" hreflang="{{ contenu.language | default('fr') }}" | ||
| title="Lien vers le dernier article"> | ||
| <img | ||
| src="{{ contenu.image | default('https://cdn.geotribu.fr/img/internal/charte/geotribu_logo_rectangle_384x80.png') }}" | ||
| alt="Illustration du dernier article publié" decoding="async" loading="lazy" draggable="false"> | ||
| <div class="image-overlay">{{ contenu.title | default('Placeholder') }}, par {{ | ||
| contenu.authors | default('Prénom NOM') | join(", ") }}</div> | ||
| </a> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {% endfor %}{% endif %} | ||
|
|
||
| </div> | ||
| </div> | ||
|
|
||
|
|
||
| {% endblock %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| #! python3 # noqa: E265 | ||
|
|
||
| """Script permettant de lister les derniers contenus avec leurs propriétés | ||
| dans un fichier YAML. Utilisé pour la page d'accueil et les pages | ||
| d'index des derniers contenus publiés. | ||
| """ | ||
|
|
||
| # ############################################################################ | ||
| # ########## Libraries ############# | ||
| # ################################## | ||
|
|
||
| # standard library | ||
| import locale | ||
| import logging | ||
| from datetime import datetime | ||
| from pathlib import Path | ||
| from typing import Literal | ||
| from zoneinfo import ZoneInfo | ||
|
|
||
| # 3rd party | ||
| import yaml | ||
| from mkdocs.structure.pages import Page | ||
| from mkdocs.utils.meta import get_data | ||
|
|
||
| # ########################################################################### | ||
| # ########## Global ################ | ||
| # ################################## | ||
|
|
||
| # journalisation | ||
| logger = logging.getLogger("mkdocs") | ||
|
|
||
| # gestion des dates | ||
| config_tz = ZoneInfo("Europe/Paris") | ||
| locale.setlocale(locale.LC_TIME, "fr_FR.UTF-8") | ||
|
|
||
| # ########################################################################### | ||
| # ########## Functions ############# | ||
| # ################################## | ||
|
|
||
|
|
||
| def format_datetime(in_datetime_string: str, out_format: str = "long") -> str: | ||
| """Formatte un datetime au format textuel standard (isocalendar) en version textuelle. | ||
| Proche du fonctionnement de 'babel.format_date'. | ||
|
|
||
| :param str in_datetime_string: chaîne de caractères en entrée. Doit être au format ISO. | ||
| :param str out_format: format de sortie, defaults to "long" | ||
|
|
||
| :return str: chaîne de caractères formatée | ||
| """ | ||
| dt = datetime.fromisoformat(in_datetime_string).replace(tzinfo=config_tz) | ||
| if out_format == "long": | ||
| return dt.strftime("%A %d %B %Y") | ||
|
|
||
|
|
||
| def get_latest_content( | ||
| content_type: Literal["articles", "rdp"], count: int = 10 | ||
| ) -> list[dict]: | ||
| """Liste les X (défini par 'count') derniers contenus d'un certain type | ||
| en retournant les métadonnées de chaque contenu, ainsi que quelques | ||
| attributs personnalisés. | ||
|
|
||
| :param Literal["articles", "rdp"] content_type: type de contenu à lister | ||
| :param int count: nombre de contenus à lister, defaults to 10 | ||
|
|
||
| :return list[dict]: liste des contenus avec leurs attributs | ||
| """ | ||
| output_contents_list: list[Page] = [] | ||
|
|
||
| if content_type == "articles": | ||
| glob_pattern = "202*/202*.md" | ||
| elif content_type == "rdp": | ||
| glob_pattern = "202*/rdp_202*.md" | ||
|
|
||
| for content in sorted( | ||
| Path(f"content/{content_type}/").glob(glob_pattern), reverse=True | ||
| )[:count]: | ||
| with content.open(encoding="utf-8-sig", errors="strict") as f: | ||
| source = f.read() | ||
| # markdown, meta = get_data(source) | ||
|
|
||
| # ajout attributs personnalisés | ||
| output_contents_list.append( | ||
| # ajout URL relative | ||
| get_data(source)[1] | ||
| | {"url_rel": str(content.relative_to("content/"))[:-3]} | ||
| # ajoute la date au format textuel | ||
| | { | ||
| "date_txt_full": format_datetime( | ||
| in_datetime_string=get_data(source)[1].get("date"), | ||
| out_format="long", | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| return output_contents_list | ||
|
|
||
|
|
||
| # ########################################################################### | ||
| # ########## Main ################## | ||
| # ################################## | ||
|
|
||
| output_dict = {"latest": {"articles": [], "rdp": []}} | ||
| # print(get_latest_content(content_type="articles")) | ||
| for k in output_dict.get("latest"): | ||
| output_dict["latest"][k] = get_latest_content(content_type=k) | ||
|
|
||
| # écrit le fichier final | ||
| with Path("config/extra_latest.yml").open("w", encoding="UTF-8") as out_file: | ||
| yaml.safe_dump( | ||
| output_dict, | ||
| out_file, | ||
| allow_unicode=True, | ||
| default_flow_style=False, | ||
| encoding="UTF8", | ||
| # indent=4, | ||
| sort_keys=True, | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.