Add support for status: hidden in pages

Resolves #380 If the status metadata is set to 'hidden' on a page it is translated and rendered but not linked anywhere in the site.
This commit is contained in:
tBunnyMan 2012-06-26 19:26:43 -07:00
commit a0e46c9106
3 changed files with 28 additions and 2 deletions

View file

@ -136,6 +136,10 @@ generate static pages.
Then, use the `DISPLAY_PAGES_ON_MENU` setting, which will add all the pages to
the menu.
If you want to exclude any pages from being linked to or listed in the menu
then add a ``status: hidden`` attribute to it's metadata. This is useful for
things like making error pages that fit the generated theme of your site.
Importing an existing blog
--------------------------

View file

@ -357,10 +357,13 @@ class PagesGenerator(Generator):
def __init__(self, *args, **kwargs):
self.pages = []
self.hidden_pages = []
self.hidden_translations = []
super(PagesGenerator, self).__init__(*args, **kwargs)
def generate_context(self):
all_pages = []
hidden_pages = []
for f in self.get_files(
os.path.join(self.path, self.settings['PAGE_DIR']),
exclude=self.settings['PAGE_EXCLUDES']):
@ -373,15 +376,25 @@ class PagesGenerator(Generator):
filename=f)
if not is_valid_content(page, f):
continue
all_pages.append(page)
if page.status == "published":
all_pages.append(page)
elif page.status == "hidden":
hidden_pages.append(page)
else:
logger.warning(u"Unknown status %s for file %s, skipping it." %
(repr(unicode.encode(article.status, 'utf-8')),
repr(f)))
self.pages, self.translations = process_translations(all_pages)
self.hidden_pages, self.hidden_translations = process_translations(hidden_pages)
self._update_context(('pages', ))
self.context['PAGES'] = self.pages
def generate_output(self, writer):
for page in chain(self.translations, self.pages):
for page in chain(self.translations, self.pages,
self.hidden_translations, self.hidden_pages):
writer.write_file(page.save_as, self.get_template('page'),
self.context, page=page,
relative_urls=self.settings.get('RELATIVE_URLS'))

View file

@ -0,0 +1,9 @@
This is a test hidden page
##########################
:category: test
:status: hidden
This is great for things like error(404) pages
Anyone can see this page but it's not linked to anywhere!