-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.go
62 lines (51 loc) · 1.75 KB
/
history.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"html"
"io"
"sort"
"github.com/iand/gordf"
)
func renderHistory(w io.StringWriter, c *Context, inline bool, brief bool, level int) {
items := []string{}
for _, o := range c.Objects(rdf.IRI("http://purl.org/dc/terms/issued")) {
if rdf.IsLiteral(o) {
items = append(items, fmt.Sprintf("%s - first issued", o.Value))
}
}
for _, o := range c.Objects(rdf.IRI("http://www.w3.org/2004/02/skos/core#changeNote")) {
items = append(items, historyItem(c.New(o), "editorial"))
}
for _, o := range c.Objects(rdf.IRI("http://www.w3.org/2004/02/skos/core#historyNote")) {
items = append(items, historyItem(c.New(o), "semantic"))
}
if len(items) > 0 {
sort.Strings(items)
w.WriteString(`<ul>`)
for _, item := range items {
w.WriteString(`<li>`)
w.WriteString(html.EscapeString(item))
w.WriteString(`</li>`)
}
w.WriteString(`</ul>`)
}
}
func historyItem(c *Context, typ string) string {
label := c.Label(false, false)
date := "unknown date"
var creator string
if dateTerm, exists := c.FirstLiteral(rdf.IRI("http://purl.org/dc/terms/date")); exists {
date = c.New(dateTerm).Label(false, false)
} else if dateTerm, exists = c.FirstLiteral(rdf.IRI("http://purl.org/dc/elements/1.1/date")); exists {
date = c.New(dateTerm).Label(false, false)
}
if creatorTerm, exists := c.FirstLiteral(rdf.IRI("http://purl.org/dc/terms/creator")); exists {
creator = c.New(creatorTerm).Label(false, false)
} else if creatorTerm, exists = c.FirstLiteral(rdf.IRI("http://purl.org/dc/elements/1.1/creator")); exists {
creator = c.New(creatorTerm).Label(false, false)
}
if creator != "" {
return fmt.Sprintf("%s - %s change by %s: %s", date, typ, creator, label)
}
return fmt.Sprintf("%s - %s change: %s", date, typ, label)
}