From 62e8a2c932eb194399925aa5dfd680fd0c60050b Mon Sep 17 00:00:00 2001 From: Alexis M Date: Sun, 17 Nov 2019 19:15:04 +0100 Subject: [PATCH] Add a TOC --- pelicanconf.py | 7 ++++--- simplereader.py | 4 ++++ theme/static/css/styles.css | 30 +++++++++++++++++++++++++++++- theme/templates/article.html | 5 +++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/pelicanconf.py b/pelicanconf.py index 250e9a3..13b8196 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -27,6 +27,7 @@ FIREFOX_BOOKMARKS_PATH = ( ) PIWIK_SITE_ID = 3 PLUGIN_PATHS = ["."] -PLUGINS = [ - "simplereader", -] +PLUGINS = ["simplereader", ] + +CACHE_OUTPUT_DIRECTORY = "cache" +CACHE_DOMAIN = "/cache/" diff --git a/simplereader.py b/simplereader.py index 411d7ae..8812fef 100644 --- a/simplereader.py +++ b/simplereader.py @@ -16,6 +16,10 @@ class SimpleReader(MarkdownReader): def read(self, filename): content, metadata = super(SimpleReader, self).read(filename) + # Add the TOC to the metadata. + if len(self._md.toc) > 300: + metadata["table_of_contents"] = self._md.toc + # Get the title from the first h1 if "title" not in metadata and len(self._md.toc_tokens): first_title = self._md.toc_tokens[0] diff --git a/theme/static/css/styles.css b/theme/static/css/styles.css index 6f46378..59a3817 100644 --- a/theme/static/css/styles.css +++ b/theme/static/css/styles.css @@ -38,7 +38,6 @@ td img { ul.articles_list { margin: auto; - padding-left: 10rem; } ul.articles_list h2 { @@ -62,6 +61,15 @@ ul.articles_list li { font-weight: lighter; } +@media screen and (max-width: 600px) { + .articles_list .category { + display: none; + } + .articles_list .metadata { + min-width: 120px; + } +} + .articles_list .date { font-weight: bold; text-align: right; @@ -84,4 +92,24 @@ ul.articles_list li { a.no-color { color: inherit; +} + +#toc_container { + background: #f9f9f9 none repeat scroll 0 0; + border: 1px solid #aaa; + display: table; + font-size: 95%; + margin-bottom: 1em; + padding: 20px; + width: auto; + margin: auto; +} + +#toc_container > ul { + font-weight: 700; + text-align: center; +} + +#toc_container li, #toc_container ul, #toc_container ul li{ + list-style: outside none none !important; } \ No newline at end of file diff --git a/theme/templates/article.html b/theme/templates/article.html index 4809d31..55cc5d1 100644 --- a/theme/templates/article.html +++ b/theme/templates/article.html @@ -65,6 +65,11 @@ h1 { {% if article.headline %}

{{ article.headline }}

{% endif %} + {% if article.table_of_contents %} +
+ {{ article.table_of_contents }} +
+ {% endif %}

🌟

{{ article.content }} {% if article.image and article.image_link and article.image_author and article.image_license %}