move authorpages => autopages

This commit is contained in:
Dan Crosta 2015-05-06 22:34:50 -04:00
commit 3dcb357695
4 changed files with 85 additions and 0 deletions

28
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.

17
README.md Normal file
View File

@ -0,0 +1,17 @@
# Author Pages
This plugin adds an attribute `page` to the author object 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. |
## Template Variables
| Setting | Notes |
|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `author.page` | 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. |

1
__init__.py Normal file
View File

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

39
autopages.py Normal file
View File

@ -0,0 +1,39 @@
import os
import os.path
from pelican import signals
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 test(article_generator):
settings = article_generator.settings
readers = article_generator.readers
path = settings.get("AUTHOR_PAGE_PATH", "authors")
author_pages = {}
for filename in yield_files(path):
base_path, filename = os.path.split(filename)
page = readers.read_file(base_path, filename)
slug, _ = os.path.splitext(filename)
author_pages[slug] = page
for author, _ in article_generator.authors:
print "set author.page for %s to %r" % (author.slug, author_pages.get(author.slug, ""))
author.page = author_pages.get(author.slug, "")
def register():
signals.article_generator_finalized.connect(test)