Handle citations

This commit is contained in:
Alexis M 2019-11-20 13:56:44 +01:00
parent 62e8a2c932
commit 47dc59cdd8
7 changed files with 104 additions and 12 deletions

View file

@ -1,8 +1,24 @@
from pelican import signals from pelican import signals
from pelican.readers import MarkdownReader, Category from pelican.readers import MarkdownReader, Category, Markdown, pelican_open
from pelican.utils import get_date, slugify from pelican.utils import get_date, slugify
from markdown.preprocessors import Preprocessor
from datefinder import find_dates
import os.path import os.path
from datetime import datetime
class BlockquotesPreprocessor(Preprocessor):
def run(self, lines):
new_lines = []
for line in lines:
if line.startswith(">"):
new_lines.append(" ")
new_lines.append(line)
else:
new_lines.append(line)
return new_lines
class SimpleReader(MarkdownReader): class SimpleReader(MarkdownReader):
@ -14,8 +30,22 @@ class SimpleReader(MarkdownReader):
super(SimpleReader, self).__init__(*args, **kwargs) super(SimpleReader, self).__init__(*args, **kwargs)
self.settings["MARKDOWN"]["extensions"].append("markdown.extensions.toc") self.settings["MARKDOWN"]["extensions"].append("markdown.extensions.toc")
def read(self, filename): def read(self, source_path):
content, metadata = super(SimpleReader, self).read(filename) self._source_path = source_path
self._md = Markdown(**self.settings["MARKDOWN"])
if "Lectures" in source_path:
self._md.preprocessors.register(
BlockquotesPreprocessor(self._md), "blockquotes", 10
)
with pelican_open(source_path) as text:
content = self._md.convert(text)
if hasattr(self._md, "Meta"):
metadata = self._parse_metadata(self._md.Meta)
else:
metadata = {}
# Add the TOC to the metadata. # Add the TOC to the metadata.
if len(self._md.toc) > 300: if len(self._md.toc) > 300:
metadata["table_of_contents"] = self._md.toc metadata["table_of_contents"] = self._md.toc
@ -28,9 +58,11 @@ class SimpleReader(MarkdownReader):
'<h1 id="{id}">{name}</h1>'.format(**first_title), "" '<h1 id="{id}">{name}</h1>'.format(**first_title), ""
) )
# Get the date from the filename. # Get the date from the filename, if possible.
parts = os.path.splitext(os.path.basename(filename))[0].split("-") parts = os.path.splitext(os.path.basename(source_path))[0].split("-")
if len(parts) >= 3: if "read_on" in metadata:
metadata["date"] = datetime.strptime(metadata["read_on"], "%B %Y")
elif len(parts) >= 3:
metadata["date"] = get_date("-".join(parts[:3])) metadata["date"] = get_date("-".join(parts[:3]))
if "slug" not in metadata: if "slug" not in metadata:
@ -38,7 +70,9 @@ class SimpleReader(MarkdownReader):
metadata["title"], self.settings.get("SLUG_REGEX_SUBSTITUTIONS", []) metadata["title"], self.settings.get("SLUG_REGEX_SUBSTITUTIONS", [])
) )
category = os.path.basename(os.path.abspath(os.path.join(filename, os.pardir))) category = os.path.basename(
os.path.abspath(os.path.join(source_path, os.pardir))
)
metadata["category"] = self.process_metadata("category", category) metadata["category"] = self.process_metadata("category", category)
return content, metadata return content, metadata

View file

@ -37,7 +37,7 @@
/* Prevent scroll on narrow devices */ /* Prevent scroll on narrow devices */
html, html,
body { body {
overflow-x: hidden; /* overflow-x: hidden; */
} }
html { html {

View file

@ -113,3 +113,7 @@ a.no-color {
#toc_container li, #toc_container ul, #toc_container ul li{ #toc_container li, #toc_container ul, #toc_container ul li{
list-style: outside none none !important; list-style: outside none none !important;
} }
.illustration-Lectures {
max-width: 50% !important;
}

View file

@ -40,6 +40,7 @@ h1 {
.post-headline { .post-headline {
padding: 15px; padding: 15px;
text-align: center;
} }
</style> </style>
{% if article.image %} {% if article.image %}
@ -57,9 +58,16 @@ h1 {
{% block content %} {% block content %}
<div id="main" class="posts"> <div id="main" class="posts">
<h1 class="post-title">{{ article.title }}</h1> <h1 class="post-title">{% if article.category == "Lectures" %}{{ article.title }} par {{ article.author }}{% else %}{{ article.title }}{% endif %}</h1>
<span class="post-date">{{ article.locale_date | capitalize }}, dans <a class="no-color" href="{{ article.category.url }}">{{ article.category }}</a></span>
<img id="illustration" src="{{ article.image}}" /> <span class="post-date">
{% if article.category == "Lectures" %}
<span class="post-date">Lu en {{ article.read_on }}. Thèmes : {% if article.tags %}{% for tag in article.tags %}<a href="{{ SITEURL }}/{{ tag.url }}">{{ tag | escape }}</a> {% endfor %}{% endif %}. {% if article.link %}<a href="{{ article.link }}">Accéder en ligne.</a>{% endif %}</span>
{% else %}
{{ article.locale_date | capitalize }}, dans <a class="no-color" href="{{ article.category.url }}">{{ article.category }}</a>
{% endif %}
</span>
<img id="illustration" class="illustration-{{ article.category }}" src="{{ article.image }}" />
<div class="post article"> <div class="post article">
{% if article.headline %} {% if article.headline %}

View file

@ -24,7 +24,7 @@
{{ macros.list_articles( {{ macros.list_articles(
articles_page.object_list, articles_page.object_list,
included_categories=dict(categories).keys(), included_categories=dict(categories).keys(),
excluded_categories=("journal", "notes"), excluded_categories=("journal", "notes", "lectures"),
title="Réfléxions", title="Réfléxions",
limit=7, limit=7,
see_more="/categories.html" see_more="/categories.html"
@ -39,6 +39,15 @@
see_more="/category/journal.html" see_more="/category/journal.html"
)}} )}}
{{ macros.list_articles(
articles_page.object_list,
included_categories=("lectures",),
display_category=False,
title="Notes de lecture",
limit=7,
see_more="/category/lectures.html"
)}}
{{ macros.list_articles( {{ macros.list_articles(
articles_page.object_list, articles_page.object_list,
included_categories=("notes",), included_categories=("notes",),

View file

@ -14,3 +14,17 @@
{% if see_more %}<li><span class="metadata date"></span><a class="post_title" href="{{ see_more }}">plus d'articles </a>&nbsp;</li>{% endif %} {% if see_more %}<li><span class="metadata date"></span><a class="post_title" href="{{ see_more }}">plus d'articles </a>&nbsp;</li>{% endif %}
</ul> </ul>
{%- endmacro %} {%- endmacro %}
{% macro list_tag(articles, title, limit=None) -%}
<ul class="articles_list">
{% if title is defined %}<li><span class="metadata date"><h2>{{ title }}</h2></span></li>{% endif %}
{% for article in articles | batch(limit) | first %}
<li>
<span class="metadata date">{{ article.date.strftime("%B %Y") }}</span>
<a class="post_title" href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a>&nbsp;
<span class="metadata category">{{ article.category }}</span>
</li>
{% endfor %}
</ul>
{%- endmacro %}

View file

@ -0,0 +1,23 @@
{% import "macros/list_articles.html" as macros %}
{% extends "base.html" %}
{% block containerclass %}container-wide{% endblock %}
{% block containertitleclass %}container-wide{% endblock %}
{% block extrahead %}
<style>
</style>
{% endblock %}
{% block content %}
<div class="content-title">
{% block content_title %}{% endblock %}
<div class="posts">
{{ macros.list_tag(
articles_page.object_list,
title=tag,
limit=None,
)}}
</div>
</div>
{% endblock content %}