Commits

Sergey Astanin  committed bcb0853

Obraz plugin: unpublished (draft) posts

  • Participants
  • Parent commits 860ed8d

Comments (0)

Files changed (1)

File plugins/unpublished.py

+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2013 Sergey Astanin
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+"""Don't publish posts which have a `published: false` header.
+
+How to use:
+
+  * put this file into _plugins/ directory of your site
+
+  * add
+
+        published: false
+
+    header to your posts which are not ready yet
+
+  * change the header to
+
+        published: true
+
+    or remove it when the post is ready to be published.
+
+To enable publishing of draft posts (like for local preview), add
+
+    future: true
+
+to site configuration (`_config.yml`).
+
+Requirements:
+
+  * Obraz >= 0.4
+
+"""
+
+import obraz
+
+
+@obraz.processor
+def dont_publish_drafts(site):
+    "Hide posts with `published: false`"
+    config = obraz._default_config.copy()
+    config_file = '_config.yml'
+    config.update(obraz.load_yaml_mapping(config_file))
+    show_future = config.get("future", False)
+
+    if not show_future:
+        posts = site.get("posts",[])
+        published = [ p for p in posts if p.get("published", True) ]
+        site["posts"] = published