Skip to content

Instantly share code, notes, and snippets.

@airios
Created April 13, 2011 19:10
Show Gist options
  • Save airios/918180 to your computer and use it in GitHub Desktop.
Save airios/918180 to your computer and use it in GitHub Desktop.
Multiple Authors w/ Nesta CMS
require 'rubygems'
require 'sinatra'
module Nesta
class App
helpers do
def set_common_variables
@menu_items = Nesta::Menu.for_path('/')
@site_title = Nesta::Config.title
@default_author = Nesta::Config.author
@authors = Nesta::Config.authors
set_from_config(:title, :subtitle, :google_analytics_code)
@heading = @title
end
def author_uri(author)
get_author_data_by_key(author,"uri")
end
def author_email(author)
get_author_data_by_key(author,"email")
end
def get_author_data_by_key(author,key)
item = String.new
@authors.each do |a|
if a[ "name" ].to_s.downcase == author.downcase
item = a[ key ]
end
end
if item.empty?
item = @default_author[ key ]
end
item
end
end
class Config
def self.authors
authors = from_yaml("authors")
end
end
class FileModel
def author
if metadata("author")
metadata("author")
else
Nesta::Config.author["name"]
end
end
end
end
# Title and subheading for your site. Used on the home page and in page
# titles.
#
title: "Example Site"
subtitle: "My Cool Example with Multiple Authors"
# You should really specify your content's author when generating an
# Atom feed. Specify at least one of name, uri or email, and Nesta will
# include it in your feed. See the Atom spec for more info:
#
# http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.feed
#
# Default Author
author:
name: Default Author
uri: http://mycoolsite.com
email: author@mycoolsite.com
# Author listing
authors:
- name: "John Doe"
uri: "http://mycoolsite.com/authors/john-doe/"
email: "john@mycoolsite.com"
- name: "Jane Doe"
uri: "http://mycoolsite.com/authors/jane-doe/"
email: "jane@mycoolsite.com"
# You can stick with the default look and feel, or use a theme. Themes are
# easy to create or install, and live inside the themes directory. You
# can also use scripts/theme to install them.
#
theme: default
# If you want to use the Disqus service (http://disqus.com) to display
# comments on your site, register a Disqus account and then specify your
# site's short name here. A comment form will automatically be added to
# the bottom of your pages.
#
# disqus_short_name: default
# cache
# Set it to true if you'd like Nesta to cache your pages in ./public.
# Useful if you're deploying Nesta with a proxy server such as Nginx,
# but not in the least bit helpful if your pages are dynamic, or you're
# deploying Nesta to Heroku.
#
cache: false
# content
# The root directory where nesta will look for your article files.
# Should contain "pages" and "attachments" subdirectories that contain
# your actual content and the (optional) menu.txt file that links to your
# main category pages.
#
content: content-demo
# google_analytics_code
# Set this if you want Google Analytics to track traffic on your site.
# Probably best not to set a default value, but to set it in production.
#
# The production settings are used if you're deploying to Heroku, so
# scroll down a bit to set it in production even if you're not deploying
# to your own server.
#
# google_analytics_code: "UA-???????-?"
# Overriding "cache" and "content" in production is recommended if you're
# deploying Nesta to your own server (but see the deployment documentation
# on the Nesta site). Setting google_analytics_code in production is
# recommended regardless of how you're deploying (if you have a GA account!).
#
# Don't forget to uncomment the "production:" line too...
# production:
# cache: true
# content: /var/apps/nesta/shared/content
# google_analytics_code: "UA-???????-?"
- unless pages.empty?
- pages.each do |page|
%h1
%a(href="#{page.abspath}")= page.heading
%h2
Posted
- if page.date
on
= format_date(page.date)
- if page.author
by
- if author_uri(page.author)
%a(href="#{author_uri(page.author)}")= page.author
- else
~ page.author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment