kinsite 0.2.0 → 0.3.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 +58 -5
- package/lib/build.mjs +4 -2
- package/lib/config.mjs +6 -0
- package/lib/css.mjs +6 -0
- package/lib/gedcom.mjs +60 -16
- package/lib/living.mjs +4 -3
- package/lib/render.mjs +45 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,28 +37,81 @@ For your own tree, write a `kinsite.config.json` next to your GEDCOM:
|
|
|
37
37
|
| `out` | Output directory (deleted and rebuilt on each run) | `site` |
|
|
38
38
|
| `mediaRoot` | Base directory for relative `FILE` paths of photos and documents | the config's directory |
|
|
39
39
|
| `anonymizeLiving` | Show living people only as "Private", for a public site (see Goals) | `false` |
|
|
40
|
+
| `citations` | Show source citations on person pages; event notes follow `notes` | `true` |
|
|
41
|
+
| `notes` | Show person and event notes; a citation's own notes go with the citation | `true` |
|
|
40
42
|
|
|
41
43
|
Relative paths resolve against the config file's directory. `FOCUS=I3` or `OUT=dir` in
|
|
42
|
-
the environment override the config for one run.
|
|
44
|
+
the environment override the config for one run. The build log says what was
|
|
45
|
+
published, e.g. `published : citations shown, notes hidden, living anonymized`.
|
|
46
|
+
|
|
47
|
+
### A research site or a public site
|
|
48
|
+
|
|
49
|
+
The defaults suit a **research site**: one you and other researchers reach behind
|
|
50
|
+
proper authorization, showing everything the GEDCOM records, living people included.
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"gedcom": "my-tree.ged",
|
|
55
|
+
"title": "My Family Tree (research)",
|
|
56
|
+
"out": "site-research"
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
A **public site** is for relatives and anyone else to browse without a login: living
|
|
61
|
+
people appear only as "Private", and the working notes and citations behind the
|
|
62
|
+
research are left out.
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"gedcom": "my-tree.ged",
|
|
67
|
+
"title": "My Family Tree",
|
|
68
|
+
"out": "site-public",
|
|
69
|
+
"anonymizeLiving": true,
|
|
70
|
+
"citations": false,
|
|
71
|
+
"notes": false
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Each setting stands alone, so a public site can still show citations or notes. With
|
|
76
|
+
`anonymizeLiving`, a living person's own notes and citations are withheld whatever these
|
|
77
|
+
say, but notes and citations on other people's records are shown as written: they can
|
|
78
|
+
still name a living relative. A citation's own notes go with the citation, so turning off
|
|
79
|
+
only `notes` still publishes them.
|
|
43
80
|
|
|
44
81
|
Everything in `sample/` is invented: names, places, dates, numbers and addresses.
|
|
45
82
|
|
|
83
|
+
## Facts and their sources
|
|
84
|
+
|
|
85
|
+
When a GEDCOM records a birth, christening, baptism, death or burial more than once,
|
|
86
|
+
the person page shows the versions together, in file order, which GEDCOM 7 uses for
|
|
87
|
+
preference: the first shown is marked preferred and the rest alternates. Versions
|
|
88
|
+
with nothing to show, and those marked `RESN PRIVACY` or `CONFIDENTIAL`, are left out.
|
|
89
|
+
Life spans and the birth-year sort use the first version with a year. With
|
|
90
|
+
`anonymizeLiving`, every birth version counts toward deciding who is living,
|
|
91
|
+
restricted or not.
|
|
92
|
+
|
|
93
|
+
Under each event come its notes and citations, numbered: source title, page, and the
|
|
94
|
+
quoted text of the record. Citations on the person record or on the name shown are
|
|
95
|
+
listed under Sources at the foot of the page. Marriages don't show notes or citations
|
|
96
|
+
yet.
|
|
97
|
+
|
|
46
98
|
## Goals
|
|
47
99
|
|
|
48
100
|
- **Static output only.** No server, no database. JavaScript in the browser is fine,
|
|
49
101
|
but every page must be readable without it.
|
|
50
102
|
- **No contact details.** The build removes phone numbers, email addresses, street
|
|
51
|
-
addresses and PO boxes from places and
|
|
103
|
+
addresses and PO boxes from places, notes and citations; never reads contact fields (`ADDR`,
|
|
52
104
|
`PHON`, `EMAIL`); and hides events marked `RESN PRIVACY` or `CONFIDENTIAL`.
|
|
53
105
|
- **Living people suited to the audience.** By default living people appear as-is,
|
|
54
106
|
which is fine for a site behind proper authorization. For a public site, set
|
|
55
107
|
`"anonymizeLiving": true`: anyone with no `DEAT` event who was born within the last
|
|
56
108
|
100 years, or has no birth date, still appears in the tree but only as "Private",
|
|
57
|
-
with name, sex, dates, places, events, marriages, notes and media withheld and their
|
|
109
|
+
with name, sex, dates, places, events, marriages, notes, citations and media withheld and their
|
|
58
110
|
media files not copied. A photo also attached to someone else, such as a group
|
|
59
111
|
photo, is withheld from their page too. Their page stays at the same address and says only "Private".
|
|
60
|
-
Notes on deceased people's records are shown as written, even if they
|
|
61
|
-
living person
|
|
112
|
+
Notes and citations on deceased people's records are shown as written, even if they
|
|
113
|
+
mention a living person, unless `notes` and `citations` are off (see "A research site
|
|
114
|
+
or a public site").
|
|
62
115
|
- **A chart that stays readable.** A focused neighborhood around one person, never a
|
|
63
116
|
whole tree shrunk until the text is useless.
|
|
64
117
|
- **Works on a phone.**
|
package/lib/build.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { CSS } from './css.mjs'
|
|
|
7
7
|
import { anonymize } from './living.mjs'
|
|
8
8
|
|
|
9
9
|
export function buildSite(config, { log = console.log } = {}) {
|
|
10
|
-
const { gedcom, out, mediaRoot, title, focus, anonymizeLiving } = config
|
|
10
|
+
const { gedcom, out, mediaRoot, title, focus, anonymizeLiving, citations = true, notes = true } = config
|
|
11
11
|
if (!fs.statSync(gedcom, { throwIfNoEntry: false })?.isFile()) throw new Error(`GEDCOM not found: ${gedcom}`)
|
|
12
12
|
const mediaOut = path.join(out, 'media')
|
|
13
13
|
const inside = (dir, f) => {
|
|
@@ -50,7 +50,7 @@ export function buildSite(config, { log = console.log } = {}) {
|
|
|
50
50
|
fs.writeFileSync(path.join(out, 'style.css'), CSS)
|
|
51
51
|
|
|
52
52
|
const kin = new Kin(indi, fam, focus)
|
|
53
|
-
const r = new Renderer({ indi, fam, kin, copied, title, source: path.basename(gedcom) })
|
|
53
|
+
const r = new Renderer({ indi, fam, kin, copied, title, source: path.basename(gedcom), citations, notes })
|
|
54
54
|
let withPhoto = 0
|
|
55
55
|
for (const pid of indi.keys()) {
|
|
56
56
|
const page = r.personPage(pid)
|
|
@@ -67,6 +67,8 @@ export function buildSite(config, { log = console.log } = {}) {
|
|
|
67
67
|
log(` families : ${stats.families}`)
|
|
68
68
|
log(` with photos : ${stats.withPhoto}`)
|
|
69
69
|
log(` media copied: ${stats.media}`)
|
|
70
|
+
const shown = on => (on ? 'shown' : 'hidden')
|
|
71
|
+
log(` published : citations ${shown(citations)}, notes ${shown(notes)}, living ${anonymizeLiving ? 'anonymized' : 'shown'}`)
|
|
70
72
|
log(`Wrote ${stats.pages} HTML pages.`)
|
|
71
73
|
log(`Open it: open "${path.join(out, 'index.html')}"`)
|
|
72
74
|
return stats
|
package/lib/config.mjs
CHANGED
|
@@ -9,8 +9,11 @@ export const DEFAULTS = {
|
|
|
9
9
|
out: 'site',
|
|
10
10
|
mediaRoot: '.',
|
|
11
11
|
anonymizeLiving: false,
|
|
12
|
+
citations: true,
|
|
13
|
+
notes: true,
|
|
12
14
|
}
|
|
13
15
|
const PATHS = ['gedcom', 'out', 'mediaRoot']
|
|
16
|
+
const FLAGS = ['anonymizeLiving', 'citations', 'notes']
|
|
14
17
|
|
|
15
18
|
export function loadConfig(file, overrides = {}) {
|
|
16
19
|
const raw = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
@@ -20,6 +23,9 @@ export function loadConfig(file, overrides = {}) {
|
|
|
20
23
|
const set = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))
|
|
21
24
|
const c = { ...DEFAULTS, ...raw, ...set }
|
|
22
25
|
if (!c.gedcom) throw new Error(`config needs a "gedcom" path (in ${file})`)
|
|
26
|
+
for (const k of FLAGS) {
|
|
27
|
+
if (typeof c[k] !== 'boolean') throw new Error(`${k} must be true or false, not ${JSON.stringify(c[k])} (in ${file})`)
|
|
28
|
+
}
|
|
23
29
|
const base = path.dirname(path.resolve(file))
|
|
24
30
|
for (const k of PATHS) c[k] = path.resolve(base, c[k])
|
|
25
31
|
return c
|
package/lib/css.mjs
CHANGED
|
@@ -31,6 +31,12 @@ ul.people{list-style:none;padding:0;margin:0;columns:2;column-gap:28px}
|
|
|
31
31
|
@media(max-width:640px){ul.people{columns:1}}
|
|
32
32
|
ul.people li{margin:.12em 0;break-inside:avoid}
|
|
33
33
|
details{margin:.5em 0}summary{cursor:pointer;color:var(--mut)}
|
|
34
|
+
.pref{margin-left:.6em;color:var(--mut);font-size:.72em;text-transform:uppercase;letter-spacing:.04em}
|
|
35
|
+
.ev{margin:.1em 0 .5em 68px;color:#444;font-size:.9em}
|
|
36
|
+
@media(max-width:640px){.ev{margin-left:14px}}
|
|
37
|
+
.enote{white-space:pre-wrap;margin:.1em 0}
|
|
38
|
+
.cite{margin:.15em 0}.cite q{white-space:pre-wrap}.cn{color:var(--mut)}.cite .enote{padding-left:1.8em}
|
|
39
|
+
.sources{color:#444;font-size:.92em}
|
|
34
40
|
.note{white-space:pre-wrap;font-size:.92em;color:#444;border-left:3px solid var(--line);
|
|
35
41
|
padding-left:10px;margin:.4em 0}
|
|
36
42
|
footer{color:var(--mut);font-size:.85em;margin:2em 0 1em;border-top:1px solid var(--line);
|
package/lib/gedcom.mjs
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
// Minimal GEDCOM 7.0 reader: only what the site renders.
|
|
2
|
+
import { yr } from './dates.mjs'
|
|
2
3
|
|
|
3
4
|
const EVENTS = new Set(['BIRT', 'CHR', 'BAPM', 'DEAT', 'BURI', 'RESI', 'EMIG', 'OCCU', 'EVEN'])
|
|
4
5
|
|
|
6
|
+
export const restricted = e => (e.resn ?? '').toUpperCase().split(/[\s,]+/).some(t => t === 'PRIVACY' || t === 'CONFIDENTIAL')
|
|
7
|
+
|
|
5
8
|
export function parseGedcom(text) {
|
|
6
|
-
const indi = new Map(), fam = new Map(), obje = new Map()
|
|
7
|
-
let cur = null, ctype = null, evt = null, media = null,
|
|
9
|
+
const indi = new Map(), fam = new Map(), obje = new Map(), sour = new Map(), pointers = []
|
|
10
|
+
let cur = null, ctype = null, evt = null, media = null, sub = null, cite = null, citeLvl = 0, cont = null, shownName = false
|
|
11
|
+
const startCitation = (val, lvl, list) => {
|
|
12
|
+
cite = { title: '', page: '', text: '', notes: [] }
|
|
13
|
+
citeLvl = lvl
|
|
14
|
+
list.push(cite)
|
|
15
|
+
const ptr = val.match(/^@(\w+)@$/)
|
|
16
|
+
if (ptr) pointers.push([cite, ptr[1]])
|
|
17
|
+
else {
|
|
18
|
+
cite.title = val.trim()
|
|
19
|
+
cont = { lvl, obj: cite, key: 'title' }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
8
22
|
|
|
9
23
|
for (const ln of text.replace(/\r\n?/g, '\n').split('\n')) {
|
|
10
24
|
if (!ln.trim()) continue
|
|
@@ -12,14 +26,13 @@ export function parseGedcom(text) {
|
|
|
12
26
|
if (!m) continue
|
|
13
27
|
const lvl = Number(m[1]), rest = m[2]
|
|
14
28
|
if (lvl === 0) {
|
|
15
|
-
cur = ctype = evt = media = null
|
|
16
|
-
note = false
|
|
29
|
+
cur = ctype = evt = media = cite = cont = null
|
|
17
30
|
const r = rest.match(/^@(\w+)@ (\w+)$/)
|
|
18
31
|
if (r && r[2] === 'INDI') {
|
|
19
32
|
ctype = 'INDI'
|
|
20
33
|
if (!indi.has(r[1])) indi.set(r[1], {
|
|
21
34
|
id: r[1], name: '', surn: '', giv: '', sex: '',
|
|
22
|
-
birt: {}, deat: {}, events: [], famc: null, fams: [], media: [], notes: [],
|
|
35
|
+
birt: {}, deat: {}, events: [], famc: null, fams: [], media: [], notes: [], sources: [],
|
|
23
36
|
})
|
|
24
37
|
cur = indi.get(r[1])
|
|
25
38
|
} else if (r && r[2] === 'FAM') {
|
|
@@ -30,6 +43,10 @@ export function parseGedcom(text) {
|
|
|
30
43
|
ctype = 'OBJE'
|
|
31
44
|
cur = { file: '', title: '', form: '' }
|
|
32
45
|
obje.set(r[1], cur)
|
|
46
|
+
} else if (r && r[2] === 'SOUR') {
|
|
47
|
+
ctype = 'SOUR'
|
|
48
|
+
cur = { title: '' }
|
|
49
|
+
sour.set(r[1], cur)
|
|
33
50
|
}
|
|
34
51
|
continue
|
|
35
52
|
}
|
|
@@ -37,10 +54,35 @@ export function parseGedcom(text) {
|
|
|
37
54
|
const sp = rest.indexOf(' ')
|
|
38
55
|
const tag = sp < 0 ? rest : rest.slice(0, sp)
|
|
39
56
|
let val = sp < 0 ? '' : rest.slice(sp + 1)
|
|
57
|
+
const note = tag === 'NOTE' && !/^@\w+@$/.test(val)
|
|
40
58
|
if (val.startsWith('@@')) val = val.slice(1)
|
|
59
|
+
if (cont && lvl <= cont.lvl) cont = null
|
|
60
|
+
if (tag === 'CONT') {
|
|
61
|
+
if (cont?.lvl === lvl - 1) cont.obj[cont.key] += '\n' + val
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
41
64
|
if (lvl === 2) sub = tag
|
|
65
|
+
if (cite && lvl <= citeLvl) cite = null
|
|
42
66
|
const phrase = lvl === 3 && sub === 'DATE' && tag === 'PHRASE'
|
|
43
|
-
if (
|
|
67
|
+
if (cite) {
|
|
68
|
+
if (lvl === citeLvl + 1 && tag === 'PAGE') {
|
|
69
|
+
cite.page = val.trim()
|
|
70
|
+
cont = { lvl, obj: cite, key: 'page' }
|
|
71
|
+
}
|
|
72
|
+
else if (lvl === citeLvl + 1 && note) cont = { lvl, obj: cite.notes, key: cite.notes.push(val) - 1 }
|
|
73
|
+
else if (lvl === citeLvl + 2 && sub === 'DATA' && tag === 'TEXT') {
|
|
74
|
+
cite.text = cite.text ? `${cite.text}\n${val}` : val
|
|
75
|
+
cont = { lvl, obj: cite, key: 'text' }
|
|
76
|
+
}
|
|
77
|
+
if (lvl === citeLvl + 1) sub = tag
|
|
78
|
+
continue
|
|
79
|
+
}
|
|
80
|
+
if (ctype === 'SOUR') {
|
|
81
|
+
if (lvl === 1 && tag === 'TITL') {
|
|
82
|
+
cur.title = val
|
|
83
|
+
cont = { lvl, obj: cur, key: 'title' }
|
|
84
|
+
}
|
|
85
|
+
} else if (ctype === 'OBJE') {
|
|
44
86
|
if (lvl === 1) {
|
|
45
87
|
media = tag === 'FILE' && !cur.file ? cur : null
|
|
46
88
|
if (media) media.file = val.trim()
|
|
@@ -51,8 +93,8 @@ export function parseGedcom(text) {
|
|
|
51
93
|
} else if (ctype === 'INDI') {
|
|
52
94
|
if (lvl === 1) {
|
|
53
95
|
evt = null
|
|
54
|
-
|
|
55
|
-
if (
|
|
96
|
+
shownName = tag === 'NAME' && !cur.name
|
|
97
|
+
if (shownName) {
|
|
56
98
|
cur.name = val.replaceAll('/', '').trim()
|
|
57
99
|
const s = val.match(/\/([^/]*)\//)
|
|
58
100
|
cur.surn = s ? s[1].trim() : ''
|
|
@@ -61,24 +103,21 @@ export function parseGedcom(text) {
|
|
|
61
103
|
else if (EVENTS.has(tag)) {
|
|
62
104
|
evt = { tag, val: val.trim() }
|
|
63
105
|
cur.events.push(evt)
|
|
64
|
-
if (tag === 'BIRT' && !cur.birt.tag) cur.birt = evt
|
|
65
|
-
if (tag === 'DEAT' && !cur.deat.tag) cur.deat = evt
|
|
66
106
|
} else if (tag === 'FAMC') cur.famc = stripAt(val)
|
|
67
107
|
else if (tag === 'FAMS') cur.fams.push(stripAt(val))
|
|
68
108
|
else if (tag === 'OBJE') cur.media.push(stripAt(val))
|
|
69
|
-
else if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
109
|
+
else if (note) cont = { lvl, obj: cur.notes, key: cur.notes.push(val) - 1 }
|
|
110
|
+
else if (tag === 'SOUR') startCitation(val, 1, cur.sources)
|
|
111
|
+
} else if (lvl === 2 && tag === 'SOUR' && (evt || shownName)) {
|
|
112
|
+
startCitation(val, 2, evt ? (evt.sources ??= []) : cur.sources)
|
|
73
113
|
} else if (evt && lvl === 2) {
|
|
74
114
|
if (tag === 'DATE') evt.date = val.trim()
|
|
75
115
|
else if (tag === 'PLAC') evt.plac = val.trim()
|
|
76
116
|
else if (tag === 'TYPE') evt.type = val.trim()
|
|
77
117
|
else if (tag === 'RESN') evt.resn = val.trim()
|
|
118
|
+
else if (note) cont = { lvl, obj: (evt.notes ??= []), key: evt.notes.push(val) - 1 }
|
|
78
119
|
} else if (evt && phrase) {
|
|
79
120
|
evt.phrase = val.trim()
|
|
80
|
-
} else if (note && tag === 'CONT') {
|
|
81
|
-
cur.notes[cur.notes.length - 1] += '\n' + val
|
|
82
121
|
}
|
|
83
122
|
} else {
|
|
84
123
|
if (lvl === 1) {
|
|
@@ -94,7 +133,12 @@ export function parseGedcom(text) {
|
|
|
94
133
|
} else if (evt && phrase) evt.phrase = val.trim()
|
|
95
134
|
}
|
|
96
135
|
}
|
|
136
|
+
for (const [c, id] of pointers) c.title = sour.get(id)?.title ?? ''
|
|
97
137
|
for (const p of indi.values()) {
|
|
138
|
+
for (const [key, tag] of [['birt', 'BIRT'], ['deat', 'DEAT']]) {
|
|
139
|
+
const all = p.events.filter(e => e.tag === tag)
|
|
140
|
+
p[key] = all.find(e => !restricted(e) && yr(e.date)) ?? all[0] ?? {}
|
|
141
|
+
}
|
|
98
142
|
p.media = p.media.flatMap(id => obje.get(id) ?? [])
|
|
99
143
|
}
|
|
100
144
|
return { indi, fam }
|
package/lib/living.mjs
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
export function isLiving(p, year = new Date().getFullYear()) {
|
|
4
4
|
if (p.deat?.tag) return false
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const births = [p.birt, ...(p.events ?? []).filter(e => e.tag === 'BIRT')]
|
|
6
|
+
const years = births.flatMap(e => e?.date?.match(/\d{4}/g) ?? [])
|
|
7
|
+
return !years.length || year - Math.max(...years) <= 100
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
const stub = ({ id, famc, fams }) => ({
|
|
10
11
|
id, name: 'Private', surn: '', giv: '', sex: '', private: true,
|
|
11
|
-
birt: {}, deat: {}, events: [], famc, fams, media: [], notes: [],
|
|
12
|
+
birt: {}, deat: {}, events: [], famc, fams, media: [], notes: [], sources: [],
|
|
12
13
|
})
|
|
13
14
|
|
|
14
15
|
export function anonymize(indi, fam, year) {
|
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 } 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'
|
|
@@ -10,7 +11,6 @@ export const DEFAULT_TITLE = 'Family Tree'
|
|
|
10
11
|
export const IMG_EXT = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp'])
|
|
11
12
|
|
|
12
13
|
const known = s => ((s ?? '').trim() === '?' ? '' : s ?? '')
|
|
13
|
-
const restricted = e => (e.resn ?? '').toUpperCase().split(/[\s,]+/).some(t => t === 'PRIVACY' || t === 'CONFIDENTIAL')
|
|
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,22 @@ 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
|
+
const ONCE = new Set(Object.keys(ORDER))
|
|
44
|
+
const counter = (n = 0) => () => ++n
|
|
45
|
+
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
|
+
const notesHtml = notes => (notes ?? []).filter(n => n.trim()).map(n => `<div class=enote>${esc(redact(n))}</div>`).join('')
|
|
42
54
|
|
|
43
55
|
export class Renderer {
|
|
44
|
-
constructor({ indi, fam, kin, copied, title = DEFAULT_TITLE, source = '' }) {
|
|
45
|
-
Object.assign(this, { indi, fam, kin, copied, title, source })
|
|
56
|
+
constructor({ indi, fam, kin, copied, title = DEFAULT_TITLE, source = '', citations = true, notes = true }) {
|
|
57
|
+
Object.assign(this, { indi, fam, kin, copied, title, source, citations, notes })
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
page(title, body) {
|
|
@@ -62,22 +74,36 @@ export class Renderer {
|
|
|
62
74
|
return `<a href="${pid}.html">${esc(p.name || '(unnamed)')}</a>` + (l ? ` <span class=yr>(${l})</span>` : '')
|
|
63
75
|
}
|
|
64
76
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
citesHtml(sources, num) {
|
|
78
|
+
if (!this.citations) return ''
|
|
79
|
+
return (sources ?? []).filter(cited).map(c => {
|
|
80
|
+
const head = [c.title, c.page].filter(s => s.trim()).map(s => esc(redact(s.trim()))).join(', ')
|
|
81
|
+
const text = c.text.trim() ? `${head ? ' — ' : ''}<q>${esc(redact(c.text.trim()))}</q>` : ''
|
|
82
|
+
return `<div class=cite><span class=cn>[${num()}]</span> ${head}${text}${notesHtml(c.notes)}</div>`
|
|
83
|
+
}).join('')
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
evtHtml(title, e, num = counter(), rank = '') {
|
|
87
|
+
const bits = evtBits(e), ev = (this.notes ? notesHtml(e.notes) : '') + this.citesHtml(e.sources, num)
|
|
88
|
+
if (!bits.length && !ev) {
|
|
71
89
|
if (e.tag !== 'BIRT' && e.tag !== 'DEAT') return ''
|
|
72
90
|
bits.push('date unknown')
|
|
73
91
|
}
|
|
74
|
-
return `<div class="evt"><span class="lbl">${title}</span
|
|
92
|
+
return `<div class="evt"><span class="lbl">${title}</span>` +
|
|
93
|
+
(bits.length ? ` ${bits.join(' · ')}` : '') + (rank ? ` <span class=pref>${rank}</span>` : '') +
|
|
94
|
+
(ev ? `<div class=ev>${ev}</div>` : '') + '</div>'
|
|
75
95
|
}
|
|
76
96
|
|
|
77
|
-
eventsHtml(p) {
|
|
97
|
+
eventsHtml(p, num = counter()) {
|
|
78
98
|
const label = e => (e.tag !== 'EVEN' ? LABELS[e.tag] : e.type === 'Living' ? 'Residence' : esc(e.type || 'Event'))
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
const kept = p.events.filter(e => !restricted(e))
|
|
100
|
+
const says = new Set(kept.filter(e => evtBits(e).length || (this.notes && e.notes?.some(n => n.trim())) || (this.citations && e.sources?.some(cited))))
|
|
101
|
+
// A tag none of whose versions says anything keeps its first, so a bare birth still reads "date unknown".
|
|
102
|
+
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))))
|
|
103
|
+
.sort((a, b) => (ORDER[a.tag] ?? 0) - (ORDER[b.tag] ?? 0))
|
|
104
|
+
const same = (e, i) => ONCE.has(e.tag) && shown[i]?.tag === e.tag
|
|
105
|
+
return shown.map((e, i) => same(e, i - 1) ? this.evtHtml('', e, num, 'alternate')
|
|
106
|
+
: this.evtHtml(label(e), e, num, same(e, i + 1) ? 'preferred' : '')).join('')
|
|
81
107
|
}
|
|
82
108
|
|
|
83
109
|
marriageHtml(mar) {
|
|
@@ -139,7 +165,8 @@ export class Renderer {
|
|
|
139
165
|
b.push(`<div class="photos">${cells}</div>`)
|
|
140
166
|
}
|
|
141
167
|
|
|
142
|
-
const
|
|
168
|
+
const num = counter()
|
|
169
|
+
const vit = this.eventsHtml(p, num)
|
|
143
170
|
if (vit) b.push(`<div class=card>${vit}</div>`)
|
|
144
171
|
|
|
145
172
|
const rel = []
|
|
@@ -173,9 +200,12 @@ export class Renderer {
|
|
|
173
200
|
b.push(`<h2>Documents</h2><div class=docs>${links}</div>`)
|
|
174
201
|
}
|
|
175
202
|
|
|
176
|
-
const notes = p.notes.filter(n => n.trim())
|
|
203
|
+
const notes = this.notes ? p.notes.filter(n => n.trim()) : []
|
|
177
204
|
if (notes.length) b.push('<h2>Notes</h2>' + notes.map(n => `<div class=note>${esc(redact(n))}</div>`).join(''))
|
|
178
205
|
|
|
206
|
+
const sources = this.citesHtml(p.sources, num)
|
|
207
|
+
if (sources) b.push(`<h2>Sources</h2><div class=sources>${sources}</div>`)
|
|
208
|
+
|
|
179
209
|
return { html: this.page(p.name || pid, b.join('')), withPhoto: imgs.length > 0 }
|
|
180
210
|
}
|
|
181
211
|
|