kinsite 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -5
- package/build.mjs +17 -4
- package/lib/build.mjs +17 -3
- package/lib/config.mjs +9 -0
- package/lib/css.mjs +7 -0
- package/lib/diff.mjs +265 -0
- package/lib/gedcom.mjs +111 -19
- package/lib/hourglass.mjs +4 -2
- package/lib/kin.mjs +2 -1
- package/lib/living.mjs +18 -7
- package/lib/news.mjs +173 -0
- package/lib/render.mjs +102 -24
- package/package.json +1 -1
package/lib/render.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// HTML for the person pages and the index. Output is pinned by test/golden.test.mjs.
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { place, redact } from './redact.mjs'
|
|
4
|
+
import { restricted, mainChildren } from './gedcom.mjs'
|
|
4
5
|
import { esc } from './html.mjs'
|
|
5
6
|
import { yr, byBirth, birthYear } from './dates.mjs'
|
|
6
7
|
import { hourglassLayout, hourglassSvg } from './hourglass.mjs'
|
|
@@ -9,8 +10,7 @@ export { esc, yr }
|
|
|
9
10
|
export const DEFAULT_TITLE = 'Family Tree'
|
|
10
11
|
export const IMG_EXT = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp'])
|
|
11
12
|
|
|
12
|
-
const known = s => ((s ?? '').trim() === '?' ? '' : s ?? '')
|
|
13
|
-
const restricted = e => (e.resn ?? '').toUpperCase().split(/[\s,]+/).some(t => t === 'PRIVACY' || t === 'CONFIDENTIAL')
|
|
13
|
+
export const known = s => ((s ?? '').trim() === '?' ? '' : s ?? '')
|
|
14
14
|
|
|
15
15
|
export function life(p) {
|
|
16
16
|
const b = restricted(p.birt) ? '' : yr(p.birt.date), d = restricted(p.deat) ? '' : yr(p.deat.date)
|
|
@@ -39,10 +39,28 @@ const LABELS = {
|
|
|
39
39
|
RESI: 'Residence', EMIG: 'Emigrated', OCCU: 'Occupation',
|
|
40
40
|
}
|
|
41
41
|
const ORDER = { BIRT: -3, CHR: -2, BAPM: -1, DEAT: 1, BURI: 2 }
|
|
42
|
+
// Repeats of these are alternate versions; GEDCOM 7 puts the preferred one first.
|
|
43
|
+
export const ONCE = new Set(Object.keys(ORDER))
|
|
44
|
+
const counter = (n = 0) => () => ++n
|
|
45
|
+
export const cited = c => [c.title, c.page, c.text, ...c.notes].some(s => s.trim())
|
|
46
|
+
const evtBits = e => {
|
|
47
|
+
const bits = [], val = known(e.val), plac = place(known(e.plac))
|
|
48
|
+
if (val && val !== 'Y') bits.push(esc(redact(val)))
|
|
49
|
+
if (when(e)) bits.push(esc(when(e)))
|
|
50
|
+
if (plac) bits.push(esc(plac.replace(/[, ]+$/, '')))
|
|
51
|
+
return bits
|
|
52
|
+
}
|
|
53
|
+
// How a child belongs to a parent family; a main family born into needs no label.
|
|
54
|
+
export const linkLabel = (l, main = false) => [
|
|
55
|
+
l.pedi === 'OTHER' ? l.phrase || 'other' : main && l.pedi === 'BIRTH' ? '' : l.pedi.toLowerCase(),
|
|
56
|
+
l.stat.toLowerCase(),
|
|
57
|
+
l.only && `on the ${l.only === 'child' ? "child's" : 'family'} record only`,
|
|
58
|
+
].filter(Boolean).join(', ')
|
|
59
|
+
const notesHtml = notes => (notes ?? []).filter(n => n.trim()).map(n => `<div class=enote>${esc(redact(n))}</div>`).join('')
|
|
42
60
|
|
|
43
61
|
export class Renderer {
|
|
44
|
-
constructor({ indi, fam, kin, copied, title = DEFAULT_TITLE, source = '' }) {
|
|
45
|
-
Object.assign(this, { indi, fam, kin, copied, title, source })
|
|
62
|
+
constructor({ indi, fam, kin, copied, title = DEFAULT_TITLE, source = '', citations = true, notes = true, news = false, updated = new Map() }) {
|
|
63
|
+
Object.assign(this, { indi, fam, kin, copied, title, source, citations, notes, news, updated })
|
|
46
64
|
}
|
|
47
65
|
|
|
48
66
|
page(title, body) {
|
|
@@ -62,22 +80,36 @@ export class Renderer {
|
|
|
62
80
|
return `<a href="${pid}.html">${esc(p.name || '(unnamed)')}</a>` + (l ? ` <span class=yr>(${l})</span>` : '')
|
|
63
81
|
}
|
|
64
82
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
citesHtml(sources, num) {
|
|
84
|
+
if (!this.citations) return ''
|
|
85
|
+
return (sources ?? []).filter(cited).map(c => {
|
|
86
|
+
const head = [c.title, c.page].filter(s => s.trim()).map(s => esc(redact(s.trim()))).join(', ')
|
|
87
|
+
const text = c.text.trim() ? `${head ? ' — ' : ''}<q>${esc(redact(c.text.trim()))}</q>` : ''
|
|
88
|
+
return `<div class=cite><span class=cn>[${num()}]</span> ${head}${text}${notesHtml(c.notes)}</div>`
|
|
89
|
+
}).join('')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
evtHtml(title, e, num = counter(), rank = '') {
|
|
93
|
+
const bits = evtBits(e), ev = (this.notes ? notesHtml(e.notes) : '') + this.citesHtml(e.sources, num)
|
|
94
|
+
if (!bits.length && !ev) {
|
|
71
95
|
if (e.tag !== 'BIRT' && e.tag !== 'DEAT') return ''
|
|
72
96
|
bits.push('date unknown')
|
|
73
97
|
}
|
|
74
|
-
return `<div class="evt"><span class="lbl">${title}</span
|
|
98
|
+
return `<div class="evt"><span class="lbl">${title}</span>` +
|
|
99
|
+
(bits.length ? ` ${bits.join(' · ')}` : '') + (rank ? ` <span class=pref>${rank}</span>` : '') +
|
|
100
|
+
(ev ? `<div class=ev>${ev}</div>` : '') + '</div>'
|
|
75
101
|
}
|
|
76
102
|
|
|
77
|
-
eventsHtml(p) {
|
|
103
|
+
eventsHtml(p, num = counter()) {
|
|
78
104
|
const label = e => (e.tag !== 'EVEN' ? LABELS[e.tag] : e.type === 'Living' ? 'Residence' : esc(e.type || 'Event'))
|
|
79
|
-
|
|
80
|
-
|
|
105
|
+
const kept = p.events.filter(e => !restricted(e))
|
|
106
|
+
const says = new Set(kept.filter(e => evtBits(e).length || (this.notes && e.notes?.some(n => n.trim())) || (this.citations && e.sources?.some(cited))))
|
|
107
|
+
// A tag none of whose versions says anything keeps its first, so a bare birth still reads "date unknown".
|
|
108
|
+
const shown = kept.filter(e => says.has(e) || (kept.find(o => o.tag === e.tag) === e && !kept.some(o => o.tag === e.tag && says.has(o))))
|
|
109
|
+
.sort((a, b) => (ORDER[a.tag] ?? 0) - (ORDER[b.tag] ?? 0))
|
|
110
|
+
const same = (e, i) => ONCE.has(e.tag) && shown[i]?.tag === e.tag
|
|
111
|
+
return shown.map((e, i) => same(e, i - 1) ? this.evtHtml('', e, num, 'alternate')
|
|
112
|
+
: this.evtHtml(label(e), e, num, same(e, i + 1) ? 'preferred' : '')).join('')
|
|
81
113
|
}
|
|
82
114
|
|
|
83
115
|
marriageHtml(mar) {
|
|
@@ -85,6 +117,43 @@ export class Renderer {
|
|
|
85
117
|
return text && !restricted(mar) ? ` <span class=yr>(m. ${esc(text)})</span>` : ''
|
|
86
118
|
}
|
|
87
119
|
|
|
120
|
+
parentIds(fid) {
|
|
121
|
+
const f = this.fam.get(fid)
|
|
122
|
+
return [f.husb, f.wife].filter(Boolean)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
nameLink(pid) {
|
|
126
|
+
const p = this.indi.get(pid)
|
|
127
|
+
return p ? `<a href="${pid}.html">${esc(p.name || '(unnamed)')}</a>` : this.plink(pid)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
parentsHtml(p) {
|
|
131
|
+
const { fam } = this
|
|
132
|
+
const links = (p.parentFams ?? []).filter(l => fam.has(l.fam))
|
|
133
|
+
const main = links.find(l => l.fam === p.famc)
|
|
134
|
+
const items = main ? this.parentIds(main.fam).map(id => this.plink(id)) : []
|
|
135
|
+
for (const l of links) {
|
|
136
|
+
if (l === main) continue
|
|
137
|
+
const label = linkLabel(l)
|
|
138
|
+
const names = this.parentIds(l.fam).map(id => this.plink(id)).join(' and ') || 'unrecorded parents'
|
|
139
|
+
items.push(`Also listed as a child of ${names}` + (label ? ` <span class=pref>${esc(label)}</span>` : ''))
|
|
140
|
+
}
|
|
141
|
+
if (!items.length) return ''
|
|
142
|
+
const label = main && linkLabel(main, true)
|
|
143
|
+
return `<h2>Parents${label ? `<span class=pref>${esc(label)}</span>` : ''}</h2>` +
|
|
144
|
+
'<ul class=rel>' + items.map(x => `<li>${x}</li>`).join('') + '</ul>'
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// A child whose main parent family is another one, or whose link is one-sided, says so.
|
|
148
|
+
childHtml(c, fid) {
|
|
149
|
+
const k = this.indi.get(c)
|
|
150
|
+
const link = k?.parentFams?.find(l => l.fam === fid)
|
|
151
|
+
if (!k || (k.famc === fid && !link?.only)) return this.plink(c)
|
|
152
|
+
const main = k.famc !== fid && this.fam.has(k.famc) && this.parentIds(k.famc).map(id => this.nameLink(id)).join(' and ')
|
|
153
|
+
const note = [link && esc(linkLabel(link)), main && `main parents: ${main}`].filter(Boolean).join('; ')
|
|
154
|
+
return this.plink(c) + (note ? ` <span class=yr>(${note})</span>` : '')
|
|
155
|
+
}
|
|
156
|
+
|
|
88
157
|
chartSvg(pid) {
|
|
89
158
|
const label = id => {
|
|
90
159
|
const p = this.indi.get(id)
|
|
@@ -114,6 +183,14 @@ export class Renderer {
|
|
|
114
183
|
b.push('<p class=sub>Details of living people are withheld.</p>')
|
|
115
184
|
return { html: this.page(p.name, b.join('')), withPhoto: false }
|
|
116
185
|
}
|
|
186
|
+
const up = this.updated.get(pid)
|
|
187
|
+
if (up) {
|
|
188
|
+
const links = [
|
|
189
|
+
up.date && `<a href="whats-new.html#${up.anchor}">Updated ${esc(up.date)}</a>`,
|
|
190
|
+
up.pending && '<a href="whats-new.html#pending">Changed since last deploy</a>',
|
|
191
|
+
]
|
|
192
|
+
b.push(`<p class=updated>${links.filter(Boolean).join(' · ')}</p>`)
|
|
193
|
+
}
|
|
117
194
|
const meta = [{ M: 'Male', F: 'Female' }[p.sex] ?? '', life(p)].filter(Boolean).join(' · ')
|
|
118
195
|
if (meta) b.push(`<p class=sub>${meta}</p>`)
|
|
119
196
|
|
|
@@ -139,16 +216,13 @@ export class Renderer {
|
|
|
139
216
|
b.push(`<div class="photos">${cells}</div>`)
|
|
140
217
|
}
|
|
141
218
|
|
|
142
|
-
const
|
|
219
|
+
const num = counter()
|
|
220
|
+
const vit = this.eventsHtml(p, num)
|
|
143
221
|
if (vit) b.push(`<div class=card>${vit}</div>`)
|
|
144
222
|
|
|
145
223
|
const rel = []
|
|
146
|
-
const par =
|
|
147
|
-
if (
|
|
148
|
-
const f = fam.get(p.famc)
|
|
149
|
-
for (const who of [f.husb, f.wife]) if (who) par.push(this.plink(who))
|
|
150
|
-
}
|
|
151
|
-
if (par.length) rel.push('<h2>Parents</h2><ul class=rel>' + par.map(x => `<li>${x}</li>`).join('') + '</ul>')
|
|
224
|
+
const par = this.parentsHtml(p)
|
|
225
|
+
if (par) rel.push(par)
|
|
152
226
|
for (const fid of p.fams) {
|
|
153
227
|
const f = fam.get(fid)
|
|
154
228
|
if (!f) continue
|
|
@@ -157,12 +231,12 @@ export class Renderer {
|
|
|
157
231
|
if (spouse) {
|
|
158
232
|
sp.push(`<li>${this.plink(spouse)}${this.marriageHtml(f.marr)}</li>`)
|
|
159
233
|
}
|
|
160
|
-
const kids = [...f.chil].sort(byBirth(this.indi)).map(c => `<li>${this.
|
|
234
|
+
const kids = [...f.chil].sort(byBirth(this.indi)).map(c => `<li>${this.childHtml(c, fid)}</li>`)
|
|
161
235
|
rel.push('<h2>Spouse & children</h2><ul class=rel>' + sp.join('') + kids.join('') + '</ul>')
|
|
162
236
|
}
|
|
163
237
|
if (rel.length) b.push(rel.join(''))
|
|
164
238
|
|
|
165
|
-
const sibs = p.famc ? (fam.get(p.famc)
|
|
239
|
+
const sibs = fam.has(p.famc) ? mainChildren(fam.get(p.famc), this.indi).filter(c => c !== pid).sort(byBirth(this.indi)) : []
|
|
166
240
|
if (sibs.length) b.push('<h2>Siblings</h2><ul class=rel>' + sibs.map(c => `<li>${this.plink(c)}</li>`).join('') + '</ul>')
|
|
167
241
|
|
|
168
242
|
const desc = this.descendantsHtml(pid, 3)
|
|
@@ -173,9 +247,12 @@ export class Renderer {
|
|
|
173
247
|
b.push(`<h2>Documents</h2><div class=docs>${links}</div>`)
|
|
174
248
|
}
|
|
175
249
|
|
|
176
|
-
const notes = p.notes.filter(n => n.trim())
|
|
250
|
+
const notes = this.notes ? p.notes.filter(n => n.trim()) : []
|
|
177
251
|
if (notes.length) b.push('<h2>Notes</h2>' + notes.map(n => `<div class=note>${esc(redact(n))}</div>`).join(''))
|
|
178
252
|
|
|
253
|
+
const sources = this.citesHtml(p.sources, num)
|
|
254
|
+
if (sources) b.push(`<h2>Sources</h2><div class=sources>${sources}</div>`)
|
|
255
|
+
|
|
179
256
|
return { html: this.page(p.name || pid, b.join('')), withPhoto: imgs.length > 0 }
|
|
180
257
|
}
|
|
181
258
|
|
|
@@ -200,6 +277,7 @@ export class Renderer {
|
|
|
200
277
|
const body = `<h1>${esc(this.title)}</h1>` +
|
|
201
278
|
`<p class=sub>${this.indi.size} individuals · ${this.fam.size} families ` +
|
|
202
279
|
`· ${withphoto} with photos</p>` +
|
|
280
|
+
(this.news ? `<p><a href="whats-new.html">${esc("What's new")}</a></p>` : '') +
|
|
203
281
|
hero +
|
|
204
282
|
'<h2>All people</h2>' +
|
|
205
283
|
'<input id=q placeholder="Filter by name…" autocomplete=off>' +
|