Skip to content

Commit

Permalink
Refactored data sources and identifiers involving people.
Browse files Browse the repository at this point in the history
Fixes #85 and parts of #79.

Separates out the concept of a company member and any other person.
Assigns a local identifier if a web_id is not provided, so every person
  has a unique and stable identifier.
Updates relevant filters for greater clarity and to these identifiers.
Populates web_id during preprocessing as an item attribute rather than
  providing a function to dynamically assemble during buildtime.
Provides a new data source for people.
  • Loading branch information
cdchapman committed Oct 23, 2019
1 parent 96755c1 commit 13bcc87
Show file tree
Hide file tree
Showing 21 changed files with 295 additions and 104 deletions.
15 changes: 14 additions & 1 deletion METADATA.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ The kind of document. Currently we have the following kinds of documents:
* `benefit-report`
* `tag`: the tag itself (a controlled concept)
* `tag-page` (distinct from tag as a concept)
* `author-page`
* `personal-profile-page`: a foaf personal profile document
* `archive-page`
* `vocabulary`
* `dependency`
* `person`
* `member`: A member of the company
* `base-dictionary`
* `extra-dictionary`
* `acronym-dictionary`
Expand Down Expand Up @@ -110,3 +111,15 @@ resolve to a document in the archive.
### `redirect_to_id`

The item to which this item should be redirected in some way.

## Metadata relating to people (and member) items

### `web_id` {.optional}

The [WebID](https://www.w3.org/2005/Incubator/webid/spec/identity/) of the
person, if the person has one.

### `hashtag` {.optional}

The fragment identifier to use to identify the person denoted by the WebID. By
default uses the identifier `me`.
4 changes: 4 additions & 0 deletions etc/people.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Sarven Capadisli
web_id: https://csarven.ca/#i
...
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ Here's a tiny example:
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
&lt;<%= iri_for(me) %>&gt; a foaf:Person ;
&lt;<%= me.fetch(:web_id) %>&gt; a foaf:Person ;
rdfs:label "<%= full_name(me) %>"@en ;
foaf:familyName "<%= me[:last_name] %>"@en ;
foaf:givenName "<%= me[:first_name] %>"@en ;
foaf:img &lt;<%= photo_url(me, global: true) %>&gt; ;
foaf:img &lt;<%= path_to_photo(me, absolute: true) %>&gt; ;
foaf:mbox &lt;mailto:<%= me[:email] %>&gt; ;
foaf:name "<%= full_name(me) %>"@en ;
cc:license &lt;https://creativecommons.org/licenses/by/4.0/&gt; .
Expand Down
2 changes: 1 addition & 1 deletion layouts/blog/partials/citations.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</label>
<label>
<abbr title="HyperText Markup Language">HTML</abbr><span class="math">+</span><abbr title="Resource Description Framework in Attributes">RDFa</abbr>
<input readonly="readonly" type="text" class="code" value="<%= h %[<span vocab="http://schema.org/" property="citation" typeof="BlogPosting"><a property="title" rel="url" href="#{path_to(item, absolute: true)}##{item.fetch(:kind)}"><cite>#{item[:title]}</cite></a> (<span property="author" resource="#{web_id(author)}" typeof="Person"><abbr property="name" content="#{item[:author_name]}" title="#{item[:author_name]}">#{author[:last_name]}</abbr></span> <time property="datePublished">#{simple_date(:published_at, item: item)}</time>)</span>] %>">
<input readonly="readonly" type="text" class="code" value="<%= h %[<span vocab="http://schema.org/" property="citation" typeof="BlogPosting"><a property="title" rel="url" href="#{path_to(item, absolute: true)}##{item.fetch(:kind)}"><cite>#{item[:title]}</cite></a> (<span property="author" resource="#{author.fetch(:web_id)}" typeof="Person"><abbr property="name" content="#{item[:author_name]}" title="#{item[:author_name]}">#{author[:last_name]}</abbr></span> <time property="datePublished">#{simple_date(:published_at, item: item)}</time>)</span>] %>">
</label>
<label>
<abbr title="HyperText Markup Language">HTML</abbr><span class="math">+</span>microformats
Expand Down
8 changes: 4 additions & 4 deletions layouts/blog/partials/sidebar.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
</p>

<% author = person_by_name(@item[:author_name]) %>
<section class="section banner" resource="<%= iri_for(author).pname %>" typeof="dc:Agent schema:Person foaf:Person" property="dc:creator schema:author foaf:maker">
<section class="section banner" resource="<%= author.fetch(:web_id) %>" typeof="dc:Agent schema:Person foaf:Person" property="dc:creator schema:author foaf:maker">
<h3 class="big">The Author</h3>
<figure id="author">
<img class="photo framed" src="<%= photo_url(author) %>" alt="Photo of <%= full_name(author) %>" property="schema:image foaf:img" />
<img class="photo framed" src="<%= path_to_photo(author) %>" alt="Photo of <%= full_name(author) %>" property="schema:image foaf:img" />
<figcaption class="small nav">
<h4 class="normal shaved" property="rdfs:label schema:name foaf:name"><a href="<%= description_path(author) %>" property="schema:url" class="subtle"><%= full_name(author) %></a></h4>
<p class="small em flush" property="schema:jobTitle"><%= author.fetch(:title) %></p>
<h4 class="normal shaved" property="rdfs:label schema:name foaf:name"><a href="<%= author.fetch(:web_id) %>" property="schema:url" class="subtle"><%= full_name(author) %></a></h4>
<p class="small em flush" property="schema:jobTitle"><%= current_seat(author)&.fetch(:title) %></p>
</figcaption>
</figure>
<link property="schema:worksFor" resource="pentandra:company" typeof="schema:Corporation" />
Expand Down
2 changes: 1 addition & 1 deletion layouts/proposals/default.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dl id="document-submitted-by" class="group">
<dt class="aside"><div class="close">Submitted by</div></dt>
<% @item.fetch(:submitted_by).map { |n| person_by_name(n) }.each do |submitter| %>
<dd class="bd"><a href="<%= iri_for(submitter) %>" property="schema:organizer" typeof="schema:Person"><span class="schema:name"><%= full_name(submitter) %></span></a></dd>
<dd class="bd"><a href="<%= submitter.fetch(:web_id) %>" property="schema:organizer" typeof="schema:Person"><span class="schema:name"><%= full_name(submitter) %></span></a></dd>
<% end %>
</dl>
<% end %>
Expand Down
22 changes: 14 additions & 8 deletions lib/data_sources/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/string/inflections'
require 'digest'

Class.new(Nanoc::DataSource) do
identifier :company
Expand All @@ -13,37 +14,42 @@ def up
def items
items = []

company = @company_info[:company]
items << new_item(
'',
{
mtime: mtime_of(@config[:company_metafile]),
is_hidden: true,
}.merge(@company_info[:company]),
}.merge(company),
Nanoc::Identifier.new('/company/_'),
attributes_checksum_data: Digest::SHA1.digest(Marshal.dump(company)),
)

@company_info[:people].each do |person|
items << person_to_item(person)
@company_info[:members].each do |member|
items << member_to_item(member)
end

items
end

protected

def person_to_item(person)
full_name = "#{person[:first_name]} #{person[:last_name]}"
def member_to_item(member)
full_name = member[:full_name] || "#{member[:first_name]} #{member[:last_name]}"
slug = full_name.parameterize

attributes = {
kind: 'person',
kind: 'member',
slug: slug,
mtime: mtime_of(@config[:company_metafile]),
is_hidden: true,
}

new_item(
full_name,
attributes.merge(person),
Nanoc::Identifier.new("/company/people/_#{slug}"),
attributes.merge(member),
Nanoc::Identifier.new("/company/members/_#{slug}"),
attributes_checksum_data: Digest::SHA1.digest(Marshal.dump(member)),
)
end

Expand Down
43 changes: 43 additions & 0 deletions lib/data_sources/people.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/string/inflections'
require 'digest'

Class.new(Nanoc::DataSource) do
identifier :people

def up
@people = YAML.load_file(@config[:people_data]).map(&:symbolize_keys)
end

def items
@people.map do |person|
person_to_item(person)
end
end

protected

def person_to_item(person)
slug = person[:name].parameterize

attributes = {
kind: 'person',
slug: slug,
mtime: mtime_of(@config[:people_data]),
is_hidden: true,
}

new_item(
person[:name],
attributes.merge(person),
Nanoc::Identifier.new("/people/_#{slug}"),
attributes_checksum_data: Digest::SHA1.digest(Marshal.dump(person)),
)
end

def mtime_of(meta_filename)
File.stat(meta_filename).mtime
end
end
2 changes: 1 addition & 1 deletion lib/data_sources/vocabularies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def cleanup(text)

def vocab_uri(vocab)
# HACK: until we have better handling of ontology definitions at a
# different uri than the namespace uri.
# different uri than the vocabulary namespace.
if vocab == RDF::Vocab::VOID
'http://vocab.deri.ie/void'
elsif vocab == RDF::Vocab::CC
Expand Down
1 change: 0 additions & 1 deletion lib/filters/vcard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def run(_content, params = {})

# Last chance property setting for individuals
photo_uri ||= path_to_photo(@item, absolute: true)
uid ||= web_id(@item)
end

vcard.nickname(nick_name) unless nick_name.nil?
Expand Down
22 changes: 13 additions & 9 deletions lib/helpers/atom_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def validate_entries
end

def build_for_feed(xml)
root_url = @config[:base_url] + '/'
root_url = @config[:base_url] + '/'
xml.instruct!
xml.feed(xmlns: 'http://www.w3.org/2005/Atom', 'xml:base' => root_url) do

Expand Down Expand Up @@ -151,16 +151,20 @@ def build_for_entry(entry, xml)
end
end

# @option params [Number] :limit
# @option params [Array] :entries
# @option params [Boolean] :preserve_order
# Generate an Atom feed.
#
# @param [Hash] params General parameters for the feed.
# @option params [Number] :limit (5) The limiting number of entries for the feed.
# @option params [Array] :entries ([]) An array of items to publish.
# @option params [Boolean] :preserve_order (false) Whether to preserve the order
# of items as given. Otherwise items will be sorted by published or created date.
# @option params [Proc] :content_proc
# @option params [Proc] :excerpt_proc
# @option params [String] :title
# @option params [String] :author_name
# @option params [String] :author_uri
# @option params [String] :icon
# @option params [String] :logo
# @option params [String] :title The title of the feed.
# @option params [String] :author_name The default author of the feed.
# @option params [String] :author_uri The default author URI of the feed.
# @option params [String] :icon The icon associated with the feed.
# @option params [String] :logo The logo associated with the feed.
#
# @return [String]
def atom_feed(params = {})
Expand Down
28 changes: 14 additions & 14 deletions lib/helpers/blogging.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

require_relative 'link_to'
require_relative 'people'

module LifePreserver
module Blogging
include LinkTo
include People

def blog_post?(item)
item.identifier =~ %r{^/static/blog/posts/.*\.(md|html)}
Expand Down Expand Up @@ -52,32 +54,30 @@ def post_summary(post_rep, snapshot: nil, read_more_text: 'Read more ⇢', separ
# Create a link for the author of this page
#
def link_for_author(author, rel_tag: true)
%(<a href="#{@config[:blog][:authors_path]}/#{h author.to_slug}/" title="Articles by #{h author}"#{' rel="author"' if rel_tag}>#{h author}</a>)
author = person_by_name(author)
%(<a resource="#{author.fetch(:web_id)}" href="#{path_to_profile_page(author)}" title="More about #{h full_name(author)}"#{' rel="author"' if rel_tag}>#{h full_name(author)}</a>)
end

# run during preprocessing
def generate_author_uris(item_set = nil)
# Populates the `author_uri` for the given blog post items. If not set
# specifically, falls back to the WebID of the author.
#
# @note Run during preprocessing.
#
# @param [Array<Nanoc::BasicItemView>] item_set An array of blog post items.
#
# @return [void]
def populate_author_uris(item_set = nil)
item_set ||= blog_posts
validate_config

item_set.each do |item|
author = person_by_name(item[:author_name])
if author
item[:author_uri] ||= "#{@config[:base_url]}#{description_path(author)}"
item[:author_uri] ||= author.fetch(:web_id)
end
end
end

def bibtex_key(item, author)
item[:bibtex_key] || [author.fetch(:last_name), author.fetch(:first_name)[0], attribute_to_time(item[:published_at]).year, Digest::SHA1.hexdigest(item[:title])[0..6]].join(':').downcase
end

protected

def validate_config
if @config[:base_url].nil?
raise Nanoc::Int::Errors::GenericTrivial.new('Cannot generate author URIs: site configuration has no base_url')
end
end
end
end
Loading

0 comments on commit 13bcc87

Please sign in to comment.