浏览代码

authorpages initial commit

Dan Crosta 10 年之前
父节点
当前提交
005d8e8d53
共有 5 个文件被更改,包括 87 次插入0 次删除
  1. 2 0
      Readme.rst
  2. 28 0
      authorpages/LICENSE
  3. 17 0
      authorpages/README.md
  4. 1 0
      authorpages/__init__.py
  5. 39 0
      authorpages/authorpages.py

+ 2 - 0
Readme.rst

@@ -40,6 +40,8 @@ AsciiDoc reader           Use AsciiDoc to write your posts.
 
 Asset management          Use the Webassets module to manage assets such as CSS and JS files.
                     
+Author Pages              Generate custom content for generated Author pages (e.g. author biography)
+
 Better code samples       Wraps all `table` blocks with a class attribute `.codehilitetable` in an additional `div` of class `.hilitewrapper`. It thus permits to style codeblocks better, especially to make them scrollable.
                     
 Better figures/samples    Adds a `style="width: ???px; height: auto;"` attribute to any `<img>` tags in the content

+ 28 - 0
authorpages/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.

+ 17 - 0
authorpages/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. |

+ 1 - 0
authorpages/__init__.py

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

+ 39 - 0
authorpages/authorpages.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)