Hi,
It's working fine for the main directory page, but this is where I'm running into an issue:
> Finally you have to stop Nanoc from writing out pages for every employee item provided by the data source.
I actually want this behavior from Nanoc so that each character has a profile page with their name, description, and works that they appear in.
My Rules for laying out the pages is creating outputs in the right location:
# Lay out database pages
compile '/character/*' do
filter :erb
layout '/default.*'
write @item.identifier.without_ext + '/index.html'
end
However, when I try to add an if statement to the layout page to get the title to display @item[:full_name] instead of my default @item[:title], the attribute full_name does not seem to exist.
Here is characters_db.rb:
require 'sequel'
class CharactersDataSource < ::Nanoc::DataSource
identifier :character
def up
@db = Sequel.sqlite('lib/data/characters.db')
end
def down
@db.disconnect
end
def items
@db[:characters].map do |character|
new_item(
'',
character,
"/character/#{character[:slug]}"
)
end
end
end
Here is the sorted characters helper:
def sorted_characters
characters = @items.find_all('/character/*')
characters.sort_by do |c|
[ c[:full_name] ]
end
end
And here is the layout code that is not working:
<h1 id="page-title" tabindex="-1">
<% if @item[:full_name] %>
<a href="<%= item.path %>" title="[permalink]"><%= @item[:full_name] %>
<% if item[:alt_lang] && item[:alt_name] %>
<span class="alt-name" lang="<%= item[:alt_lang] %>"><%= item[:alt_name] %></span>
<% end %>
</a>
<% else %>
<%= link_to(@item[:title], @item, title: '[permalink]') %>
<% end %>
</h1>
This is made more complicated by some characters having alternate names in non-Latin scripts (Chinese, Japanese, Greek) where I want the name surrounded in a proper lang tag.
I could theoretically copy name data into a new title column in the database, but that seems redundant when it seems like I'm either accessing the attributes array incorrectly, or when I could copy the attributes array into @item.attributes.
All the Ruby I know is from messing around with Nanoc, so I'm not sure if it's Ruby logic or Nanoc logic that I'm missing here. Or SQL logic, which I also don't know much about.
Any help would be greatly appreciated. If I can get this to work, I can pretty much ditch WordPress, as the main benefit there was the increased complexity provided by a database structure, and I'd like to reuse this structure for larger data sources.
Best,
S.