kinsite 0.1.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 CHANGED
@@ -8,11 +8,12 @@ output may still change.
8
8
 
9
9
  ## Usage
10
10
 
11
- Needs Node 22 or later; no dependencies.
11
+ Needs Node 22 or later; no dependencies. Live demo: https://chrismo.github.io/kinsite/
12
12
 
13
13
  ```sh
14
14
  node build.mjs sample/kinsite.config.json # build the fictional sample tree into site/
15
15
  open site/index.html
16
+ npm run dev # preview the sample at http://localhost:4000 (PORT=... to change); rebuilds and reloads on edits
16
17
  npm test
17
18
  ```
18
19
 
@@ -28,30 +29,89 @@ For your own tree, write a `kinsite.config.json` next to your GEDCOM:
28
29
  }
29
30
  ```
30
31
 
31
- | Key | Meaning | Default |
32
- |-------------|-------------------------------------------------------------------------------|------------------------|
33
- | `gedcom` | GEDCOM 7.0 file to read (required) | |
34
- | `title` | Site title on the index page | `Family Tree` |
35
- | `focus` | ID of the person the site centers on: home-page chart and every "Path to ..." | first person |
36
- | `out` | Output directory (deleted and rebuilt on each run) | `site` |
37
- | `mediaRoot` | Base directory for relative `FILE` paths of photos and documents | the config's directory |
32
+ | Key | Meaning | Default |
33
+ |-------------------|-------------------------------------------------------------------------------|------------------------|
34
+ | `gedcom` | GEDCOM 7.0 file to read (required) | |
35
+ | `title` | Site title on the index page | `Family Tree` |
36
+ | `focus` | ID of the person the site centers on: home-page chart and every "Path to ..." | first person |
37
+ | `out` | Output directory (deleted and rebuilt on each run) | `site` |
38
+ | `mediaRoot` | Base directory for relative `FILE` paths of photos and documents | the config's directory |
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` |
38
42
 
39
43
  Relative paths resolve against the config file's directory. `FOCUS=I3` or `OUT=dir` in
40
- 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.
41
80
 
42
81
  Everything in `sample/` is invented: names, places, dates, numbers and addresses.
43
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
+
44
98
  ## Goals
45
99
 
46
100
  - **Static output only.** No server, no database. JavaScript in the browser is fine,
47
101
  but every page must be readable without it.
48
102
  - **No contact details.** The build removes phone numbers, email addresses, street
49
- addresses and PO boxes from places and notes; never reads contact fields (`ADDR`,
103
+ addresses and PO boxes from places, notes and citations; never reads contact fields (`ADDR`,
50
104
  `PHON`, `EMAIL`); and hides events marked `RESN PRIVACY` or `CONFIDENTIAL`.
51
- - **Living people suited to the audience.** Living people are not detected, so
52
- their names and pages appear. That's fine for a site behind proper authorization.
53
- For a public site, leave them out of the GEDCOM you build from, or at least set
54
- `RESN PRIVACY` on their events.
105
+ - **Living people suited to the audience.** By default living people appear as-is,
106
+ which is fine for a site behind proper authorization. For a public site, set
107
+ `"anonymizeLiving": true`: anyone with no `DEAT` event who was born within the last
108
+ 100 years, or has no birth date, still appears in the tree but only as "Private",
109
+ with name, sex, dates, places, events, marriages, notes, citations and media withheld and their
110
+ media files not copied. A photo also attached to someone else, such as a group
111
+ photo, is withheld from their page too. Their page stays at the same address and says only "Private".
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").
55
115
  - **A chart that stays readable.** A focused neighborhood around one person, never a
56
116
  whole tree shrunk until the text is useless.
57
117
  - **Works on a phone.**
package/lib/build.mjs CHANGED
@@ -4,9 +4,10 @@ import { parseGedcom } from './gedcom.mjs'
4
4
  import { Kin } from './kin.mjs'
5
5
  import { Renderer } from './render.mjs'
6
6
  import { CSS } from './css.mjs'
7
+ import { anonymize } from './living.mjs'
7
8
 
8
9
  export function buildSite(config, { log = console.log } = {}) {
9
- const { gedcom, out, mediaRoot, title, focus } = config
10
+ const { gedcom, out, mediaRoot, title, focus, anonymizeLiving, citations = true, notes = true } = config
10
11
  if (!fs.statSync(gedcom, { throwIfNoEntry: false })?.isFile()) throw new Error(`GEDCOM not found: ${gedcom}`)
11
12
  const mediaOut = path.join(out, 'media')
12
13
  const inside = (dir, f) => {
@@ -22,7 +23,8 @@ export function buildSite(config, { log = console.log } = {}) {
22
23
  fs.rmSync(out, { recursive: true, force: true })
23
24
  fs.mkdirSync(mediaOut, { recursive: true })
24
25
 
25
- const { indi, fam } = parseGedcom(fs.readFileSync(gedcom, 'utf8'))
26
+ const parsed = parseGedcom(fs.readFileSync(gedcom, 'utf8'))
27
+ const { indi, fam } = anonymizeLiving ? anonymize(parsed.indi, parsed.fam) : parsed
26
28
 
27
29
  const copied = new Map()
28
30
  const isFile = f => fs.statSync(f, { throwIfNoEntry: false })?.isFile() ?? false
@@ -48,7 +50,7 @@ export function buildSite(config, { log = console.log } = {}) {
48
50
  fs.writeFileSync(path.join(out, 'style.css'), CSS)
49
51
 
50
52
  const kin = new Kin(indi, fam, focus)
51
- 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 })
52
54
  let withPhoto = 0
53
55
  for (const pid of indi.keys()) {
54
56
  const page = r.personPage(pid)
@@ -65,6 +67,8 @@ export function buildSite(config, { log = console.log } = {}) {
65
67
  log(` families : ${stats.families}`)
66
68
  log(` with photos : ${stats.withPhoto}`)
67
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'}`)
68
72
  log(`Wrote ${stats.pages} HTML pages.`)
69
73
  log(`Open it: open "${path.join(out, 'index.html')}"`)
70
74
  return stats
package/lib/config.mjs CHANGED
@@ -8,8 +8,12 @@ export const DEFAULTS = {
8
8
  focus: null,
9
9
  out: 'site',
10
10
  mediaRoot: '.',
11
+ anonymizeLiving: false,
12
+ citations: true,
13
+ notes: true,
11
14
  }
12
15
  const PATHS = ['gedcom', 'out', 'mediaRoot']
16
+ const FLAGS = ['anonymizeLiving', 'citations', 'notes']
13
17
 
14
18
  export function loadConfig(file, overrides = {}) {
15
19
  const raw = JSON.parse(fs.readFileSync(file, 'utf8'))
@@ -19,6 +23,9 @@ export function loadConfig(file, overrides = {}) {
19
23
  const set = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))
20
24
  const c = { ...DEFAULTS, ...raw, ...set }
21
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
+ }
22
29
  const base = path.dirname(path.resolve(file))
23
30
  for (const k of PATHS) c[k] = path.resolve(base, c[k])
24
31
  return c
package/lib/css.mjs CHANGED
@@ -24,12 +24,19 @@ ul.rel{list-style:none;padding:0;margin:0}ul.rel li{margin:.2em 0}
24
24
  .docs a{display:inline-block;margin:.2em .6em .2em 0}
25
25
  #q{width:100%;padding:10px 12px;font-size:1em;border:1px solid var(--line);
26
26
  border-radius:8px;margin:.6em 0 .4em}
27
+ #sortby{display:block;color:var(--mut);font-size:.9em;margin:0 0 .5em}#sortby[hidden]{display:none}
27
28
  .only{display:block;color:var(--mut);font-size:.9em;margin:0 0 1em;cursor:pointer}
28
29
  .cam{font-size:.85em}
29
30
  ul.people{list-style:none;padding:0;margin:0;columns:2;column-gap:28px}
30
31
  @media(max-width:640px){ul.people{columns:1}}
31
32
  ul.people li{margin:.12em 0;break-inside:avoid}
32
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}
33
40
  .note{white-space:pre-wrap;font-size:.92em;color:#444;border-left:3px solid var(--line);
34
41
  padding-left:10px;margin:.4em 0}
35
42
  footer{color:var(--mut);font-size:.85em;margin:2em 0 1em;border-top:1px solid var(--line);
package/lib/dates.mjs CHANGED
@@ -5,3 +5,7 @@ export const byBirth = indi => (a, b) => {
5
5
  const ya = yr(indi.get(a)?.birt?.date), yb = yr(indi.get(b)?.birt?.date)
6
6
  return (ya ? Number(ya) : Infinity) - (yb ? Number(yb) : Infinity)
7
7
  }
8
+
9
+ /** Birth year as a number, or null when missing, unparseable or private. */
10
+ export const birthYear = p => (p?.birt?.resn ? null : Number(yr(p?.birt?.date)) || null)
11
+
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, note = false, sub = 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 (ctype === 'OBJE') {
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
- note = false
55
- if (tag === 'NAME' && !cur.name) {
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 (tag === 'NOTE') {
70
- cur.notes.push(val)
71
- note = true
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 ADDED
@@ -0,0 +1,23 @@
1
+ // Living people on a public site: kept in the tree for its shape, shown only as "Private".
2
+
3
+ export function isLiving(p, year = new Date().getFullYear()) {
4
+ if (p.deat?.tag) return false
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
8
+ }
9
+
10
+ const stub = ({ id, famc, fams }) => ({
11
+ id, name: 'Private', surn: '', giv: '', sex: '', private: true,
12
+ birt: {}, deat: {}, events: [], famc, fams, media: [], notes: [], sources: [],
13
+ })
14
+
15
+ export function anonymize(indi, fam, year) {
16
+ const living = new Set([...indi.values()].filter(p => isLiving(p, year)).map(p => p.id))
17
+ const withheld = new Set([...indi.values()].filter(p => living.has(p.id)).flatMap(p => p.media.map(m => m.file)))
18
+ const keep = p => p.media.some(m => withheld.has(m.file)) ? { ...p, media: p.media.filter(m => !withheld.has(m.file)) } : p
19
+ return {
20
+ indi: new Map([...indi].map(([id, p]) => [id, living.has(id) ? stub(p) : keep(p)])),
21
+ fam: new Map([...fam].map(([id, f]) => [id, living.has(f.husb) || living.has(f.wife) ? { ...f, marr: {} } : f])),
22
+ }
23
+ }
package/lib/render.mjs CHANGED
@@ -1,8 +1,9 @@
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
- import { yr, byBirth } from './dates.mjs'
6
+ import { yr, byBirth, birthYear } from './dates.mjs'
6
7
  import { hourglassLayout, hourglassSvg } from './hourglass.mjs'
7
8
 
8
9
  export { esc, yr }
@@ -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) {
@@ -50,7 +62,7 @@ export class Renderer {
50
62
  `<meta name=viewport content='width=device-width,initial-scale=1'>` +
51
63
  `<title>${esc(title)}</title><link rel=stylesheet href=style.css></head>` +
52
64
  `<body><div class=wrap>${body}` +
53
- `<footer>Generated ${this.source ? `from <code>${esc(this.source)}</code> ` : ''}by kinsite ` +
65
+ `<footer>Generated ${this.source ? `from <code>${esc(this.source)}</code> ` : ''}by <a href="https://github.com/chrismo/kinsite">kinsite</a> ` +
54
66
  `&middot; ${this.indi.size} individuals &middot; ${this.fam.size} families</footer>` +
55
67
  `</div></body></html>`
56
68
  }
@@ -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
- evtHtml(title, e) {
66
- const bits = [], val = known(e.val), plac = place(known(e.plac))
67
- if (val && val !== 'Y') bits.push(esc(redact(val)))
68
- if (when(e)) bits.push(esc(when(e)))
69
- if (plac) bits.push(esc(plac.replace(/[, ]+$/, '')))
70
- if (!bits.length) {
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> ${bits.join(' &middot; ')}</div>`
92
+ return `<div class="evt"><span class="lbl">${title}</span>` +
93
+ (bits.length ? ` ${bits.join(' &middot; ')}` : '') + (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
- return p.events.filter(e => !restricted(e)).sort((a, b) => (ORDER[a.tag] ?? 0) - (ORDER[b.tag] ?? 0))
80
- .map(e => this.evtHtml(label(e), e)).join('')
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) {
@@ -110,6 +136,10 @@ export class Renderer {
110
136
  const p = this.indi.get(pid), { kin, fam } = this
111
137
  const b = ['<p class=back><a href="index.html">&larr; All people</a></p>',
112
138
  `<h1>${esc(p.name || '(unnamed)')}</h1>`]
139
+ if (p.private) {
140
+ b.push('<p class=sub>Details of living people are withheld.</p>')
141
+ return { html: this.page(p.name, b.join('')), withPhoto: false }
142
+ }
113
143
  const meta = [{ M: 'Male', F: 'Female' }[p.sex] ?? '', life(p)].filter(Boolean).join(' &middot; ')
114
144
  if (meta) b.push(`<p class=sub>${meta}</p>`)
115
145
 
@@ -125,6 +155,8 @@ export class Renderer {
125
155
  }
126
156
  }
127
157
 
158
+ b.push('<h2>Family</h2>' + this.chartSvg(pid))
159
+
128
160
  const { imgs, docs } = this.attachments(p)
129
161
  if (imgs.length) {
130
162
  const cells = imgs.map(([md, src]) =>
@@ -133,11 +165,10 @@ export class Renderer {
133
165
  b.push(`<div class="photos">${cells}</div>`)
134
166
  }
135
167
 
136
- const vit = this.eventsHtml(p)
168
+ const num = counter()
169
+ const vit = this.eventsHtml(p, num)
137
170
  if (vit) b.push(`<div class=card>${vit}</div>`)
138
171
 
139
- b.push('<h2>Family</h2>' + this.chartSvg(pid))
140
-
141
172
  const rel = []
142
173
  const par = []
143
174
  if (p.famc && fam.has(p.famc)) {
@@ -169,9 +200,12 @@ export class Renderer {
169
200
  b.push(`<h2>Documents</h2><div class=docs>${links}</div>`)
170
201
  }
171
202
 
172
- const notes = p.notes.filter(n => n.trim())
203
+ const notes = this.notes ? p.notes.filter(n => n.trim()) : []
173
204
  if (notes.length) b.push('<h2>Notes</h2>' + notes.map(n => `<div class=note>${esc(redact(n))}</div>`).join(''))
174
205
 
206
+ const sources = this.citesHtml(p.sources, num)
207
+ if (sources) b.push(`<h2>Sources</h2><div class=sources>${sources}</div>`)
208
+
175
209
  return { html: this.page(p.name || pid, b.join('')), withPhoto: imgs.length > 0 }
176
210
  }
177
211
 
@@ -186,7 +220,8 @@ export class Renderer {
186
220
  const disp = p.surn ? `${esc(p.surn)}, ${esc(p.giv)}` : esc(p.name || '(unnamed)')
187
221
  const l = life(p)
188
222
  const photo = hasPhoto(p)
189
- return `<li data-n="${esc(p.name.toLowerCase())}"${photo ? ' data-photo' : ''}>` +
223
+ const b = birthYear(p)
224
+ return `<li data-n="${esc(p.name.toLowerCase())}"${b ? ` data-b=${b}` : ''}${photo ? ' data-photo' : ''}>` +
190
225
  `<a href="${p.id}.html">${disp}</a>` + (l ? ` <span class=yr>${l}</span>` : '') +
191
226
  (photo ? ' <span class=cam title="Has photos">📷</span>' : '') + '</li>'
192
227
  })
@@ -198,6 +233,8 @@ export class Renderer {
198
233
  hero +
199
234
  '<h2>All people</h2>' +
200
235
  '<input id=q placeholder="Filter by name…" autocomplete=off>' +
236
+ '<label id=sortby hidden>Sort by <select id=sort><option value=name selected>Name (A–Z)</option>' +
237
+ '<option value=old>Birth year, oldest first</option><option value=new>Birth year, newest first</option></select></label>' +
201
238
  `<label class=only><input type=checkbox id=photos> Only people with photos (${withphoto})</label>` +
202
239
  `<ul class=people id=list>${items.join('')}</ul>` +
203
240
  "<script>var q=document.getElementById('q'),ph=document.getElementById('photos')," +
@@ -205,7 +242,14 @@ export class Renderer {
205
242
  "function f(){var v=q.value.toLowerCase();" +
206
243
  'for(var i=0;i<L.length;i++){L[i].style.display=' +
207
244
  "L[i].getAttribute('data-n').indexOf(v)>-1&&(!ph.checked||L[i].hasAttribute('data-photo'))?'':'none';}}" +
208
- "q.addEventListener('input',f);ph.addEventListener('change',f);f();</script>"
245
+ "q.addEventListener('input',f);ph.addEventListener('change',f);f();" +
246
+ "var sb=document.getElementById('sort'),u=document.getElementById('list'),A=[].slice.call(L);" +
247
+ "function b(e){var y=e.getAttribute('data-b');return y?+y:null;}" +
248
+ "document.getElementById('sortby').hidden=false;" +
249
+ "sb.addEventListener('change',function(){var d={name:0,old:1,new:-1}[sb.value];" +
250
+ "A.map(function(e,i){return[e,i];}).sort(function(x,y){var p=b(x[0]),r=b(y[0]);" +
251
+ "return (!d?0:p===null||r===null?(p===null)-(r===null):d*(p-r))||x[1]-y[1];})" +
252
+ ".forEach(function(x){u.appendChild(x[0]);});});</script>"
209
253
  return this.page(this.title, body)
210
254
  }
211
255
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kinsite",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Static HTML family-tree site from a GEDCOM file",
6
6
  "license": "MIT",
@@ -31,6 +31,7 @@
31
31
  "scripts": {
32
32
  "build": "node build.mjs",
33
33
  "sample": "node build.mjs sample/kinsite.config.json",
34
+ "dev": "node scripts/dev.mjs",
34
35
  "test": "node --test 'test/*.test.mjs'"
35
36
  }
36
37
  }