merge: working branch(presentations) into main branch

This commit is contained in:
2025-02-15 20:23:46 +01:00
32 changed files with 1743 additions and 2 deletions

28
plugins/autopages/LICENSE Normal file
View File

@ -0,0 +1,28 @@
Copyright (c) 2015, Magnetic Media Online, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,21 @@
# Auto Pages
This plugin adds an attribute `page` to the author, category, and tag
objects which can be used in templates by themes. The page is processed as
an ordinary Pelican page, so it can be Markdown, reStructuredText, etc.
## Configuration
| Setting | Default | Notes |
|----------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `AUTHOR_PAGE_PATH` | `authors` | The location, relative to the project root where author pages can be found. The filename of the author page minus the extension must match the Author's slug. |
| `CATEGORY_PAGE_PATH` | `categories` | The location, relative to the project root where category pages can be found. The filename of the category page minus the extension must match the Category's slug. |
| `TAG_PAGE_PATH` | `tags` | The location, relative to the project root where tag pages can be found. The filename of the tag page minus the extension must match the Tag's slug. |
## Template Variables
| Variable | Notes |
|-----------------|--------------------------------------|
| `author.page` | `Page` object for the author page. |
| `category.page` | `Page` object for the category page. |
| `tag.page` | `Page` object for the tag page. |

View File

@ -0,0 +1 @@
from .autopages import *

View File

@ -0,0 +1,64 @@
import logging
import os
import os.path
from pelican import signals
from pelican.contents import Page
logger = logging.getLogger("autopages")
def yield_files(root):
root = os.path.realpath(os.path.abspath(root))
for dirpath, dirnames, filenames in os.walk(root):
for dirname in list(dirnames):
try:
if dirname.startswith("."):
dirnames.remove(dirname)
except IndexError:
# duplicate already removed?
pass
for filename in filenames:
if filename.startswith("."):
continue
yield os.path.join(dirpath, filename)
def make_page(readers, context, filename):
base_path, filename = os.path.split(filename)
page = readers.read_file(base_path, filename, Page, None, context)
slug, _ = os.path.splitext(filename)
return slug, page
def make_pages(readers, context, path):
pages = {}
for filename in yield_files(path):
try:
slug, page = make_page(readers, context, filename)
except Exception:
logger.exception("Could not make autopage for %r", filename)
continue
pages[slug] = page
return pages
def create_autopages(article_generator):
settings = article_generator.settings
readers = article_generator.readers
context = article_generator.context
authors_path = settings.get("AUTHOR_PAGE_PATH", "authors")
categories_path = settings.get("CATEGORY_PAGE_PATH", "categories")
tags_path = settings.get("TAG_PAGE_PATH", "tags")
author_pages = make_pages(readers, context, authors_path)
category_pages = make_pages(readers, context, categories_path)
tag_pages = make_pages(readers, context, tags_path)
for author, _ in article_generator.authors:
author.page = author_pages.get(author.slug, "")
for category, _ in article_generator.categories:
category.page = category_pages.get(category.slug, "")
for tag in article_generator.tags:
tag.page = tag_pages.get(tag.slug, "")
def register():
signals.article_generator_finalized.connect(create_autopages)