commit 3dcb357695e122db9c764fd2cf56aee029af54ca Author: Dan Crosta Date: Wed May 6 22:34:50 2015 -0400 move authorpages => autopages diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..44364d3 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f846ded --- /dev/null +++ b/README.md @@ -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. | diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..b562ddc --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from .autopages import * diff --git a/autopages.py b/autopages.py new file mode 100644 index 0000000..8b311a7 --- /dev/null +++ b/autopages.py @@ -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)