From 47dc59cdd867800451960e2757dc2300e5506e76 Mon Sep 17 00:00:00 2001 From: Alexis M Date: Wed, 20 Nov 2019 13:56:44 +0100 Subject: [PATCH] Handle citations --- simplereader.py | 48 +++++++++++++++++++---- theme/static/css/lanyon.css | 2 +- theme/static/css/styles.css | 4 ++ theme/templates/article.html | 14 +++++-- theme/templates/index.html | 11 +++++- theme/templates/macros/list_articles.html | 14 +++++++ theme/templates/tag.html | 23 +++++++++++ 7 files changed, 104 insertions(+), 12 deletions(-) diff --git a/simplereader.py b/simplereader.py index 8812fef..417e328 100644 --- a/simplereader.py +++ b/simplereader.py @@ -1,8 +1,24 @@ 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 markdown.preprocessors import Preprocessor +from datefinder import find_dates + 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): @@ -14,8 +30,22 @@ class SimpleReader(MarkdownReader): super(SimpleReader, self).__init__(*args, **kwargs) self.settings["MARKDOWN"]["extensions"].append("markdown.extensions.toc") - def read(self, filename): - content, metadata = super(SimpleReader, self).read(filename) + def read(self, source_path): + 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. if len(self._md.toc) > 300: metadata["table_of_contents"] = self._md.toc @@ -28,9 +58,11 @@ class SimpleReader(MarkdownReader): '

{name}

'.format(**first_title), "" ) - # Get the date from the filename. - parts = os.path.splitext(os.path.basename(filename))[0].split("-") - if len(parts) >= 3: + # Get the date from the filename, if possible. + parts = os.path.splitext(os.path.basename(source_path))[0].split("-") + 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])) if "slug" not in metadata: @@ -38,7 +70,9 @@ class SimpleReader(MarkdownReader): 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) return content, metadata diff --git a/theme/static/css/lanyon.css b/theme/static/css/lanyon.css index f431ece..8f268b9 100644 --- a/theme/static/css/lanyon.css +++ b/theme/static/css/lanyon.css @@ -37,7 +37,7 @@ /* Prevent scroll on narrow devices */ html, body { - overflow-x: hidden; + /* overflow-x: hidden; */ } html { diff --git a/theme/static/css/styles.css b/theme/static/css/styles.css index 59a3817..0acf50f 100644 --- a/theme/static/css/styles.css +++ b/theme/static/css/styles.css @@ -112,4 +112,8 @@ a.no-color { #toc_container li, #toc_container ul, #toc_container ul li{ list-style: outside none none !important; +} + +.illustration-Lectures { + max-width: 50% !important; } \ No newline at end of file diff --git a/theme/templates/article.html b/theme/templates/article.html index 55cc5d1..527a636 100644 --- a/theme/templates/article.html +++ b/theme/templates/article.html @@ -40,6 +40,7 @@ h1 { .post-headline { padding: 15px; + text-align: center; } {% if article.image %} @@ -57,9 +58,16 @@ h1 { {% block content %}
-

{{ article.title }}

- - +

{% if article.category == "Lectures" %}{{ article.title }} par {{ article.author }}{% else %}{{ article.title }}{% endif %}

+ + +
{% if article.headline %} diff --git a/theme/templates/index.html b/theme/templates/index.html index a30262f..5244dec 100644 --- a/theme/templates/index.html +++ b/theme/templates/index.html @@ -24,7 +24,7 @@ {{ macros.list_articles( articles_page.object_list, included_categories=dict(categories).keys(), - excluded_categories=("journal", "notes"), + excluded_categories=("journal", "notes", "lectures"), title="Réfléxions", limit=7, see_more="/categories.html" @@ -39,6 +39,15 @@ 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( articles_page.object_list, included_categories=("notes",), diff --git a/theme/templates/macros/list_articles.html b/theme/templates/macros/list_articles.html index 827c3a9..b363a39 100644 --- a/theme/templates/macros/list_articles.html +++ b/theme/templates/macros/list_articles.html @@ -13,4 +13,18 @@ {% endfor %} {% if see_more %}
  • plus d'articles  
  • {% endif %} +{%- endmacro %} + +{% macro list_tag(articles, title, limit=None) -%} +
      + {% if title is defined %}
    • {% endif %} + + {% for article in articles | batch(limit) | first %} +
    • + + {{ article.title }}  + +
    • + {% endfor %} +
    {%- endmacro %} \ No newline at end of file diff --git a/theme/templates/tag.html b/theme/templates/tag.html index e69de29..2ea4efe 100644 --- a/theme/templates/tag.html +++ b/theme/templates/tag.html @@ -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 %} + +{% endblock %} +{% block content %} +
    +{% block content_title %}{% endblock %} + +
    + {{ macros.list_tag( + articles_page.object_list, + title=tag, + limit=None, + )}} +
    +
    +{% endblock content %}