kinsite 0.1.0 → 0.2.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,13 +29,14 @@ 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` |
38
40
 
39
41
  Relative paths resolve against the config file's directory. `FOCUS=I3` or `OUT=dir` in
40
42
  the environment override the config for one run.
@@ -48,10 +50,15 @@ Everything in `sample/` is invented: names, places, dates, numbers and addresses
48
50
  - **No contact details.** The build removes phone numbers, email addresses, street
49
51
  addresses and PO boxes from places and notes; never reads contact fields (`ADDR`,
50
52
  `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.
53
+ - **Living people suited to the audience.** By default living people appear as-is,
54
+ which is fine for a site behind proper authorization. For a public site, set
55
+ `"anonymizeLiving": true`: anyone with no `DEAT` event who was born within the last
56
+ 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
58
+ media files not copied. A photo also attached to someone else, such as a group
59
+ 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 mention a
61
+ living person.
55
62
  - **A chart that stays readable.** A focused neighborhood around one person, never a
56
63
  whole tree shrunk until the text is useless.
57
64
  - **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 } = 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
package/lib/config.mjs CHANGED
@@ -8,6 +8,7 @@ export const DEFAULTS = {
8
8
  focus: null,
9
9
  out: 'site',
10
10
  mediaRoot: '.',
11
+ anonymizeLiving: false,
11
12
  }
12
13
  const PATHS = ['gedcom', 'out', 'mediaRoot']
13
14
 
package/lib/css.mjs CHANGED
@@ -24,6 +24,7 @@ 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}
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/living.mjs ADDED
@@ -0,0 +1,22 @@
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 years = (p.birt?.date ?? '').match(/\d{4}/g)
6
+ return !years || year - Math.max(...years) <= 100
7
+ }
8
+
9
+ const stub = ({ id, famc, fams }) => ({
10
+ id, name: 'Private', surn: '', giv: '', sex: '', private: true,
11
+ birt: {}, deat: {}, events: [], famc, fams, media: [], notes: [],
12
+ })
13
+
14
+ export function anonymize(indi, fam, year) {
15
+ const living = new Set([...indi.values()].filter(p => isLiving(p, year)).map(p => p.id))
16
+ const withheld = new Set([...indi.values()].filter(p => living.has(p.id)).flatMap(p => p.media.map(m => m.file)))
17
+ const keep = p => p.media.some(m => withheld.has(m.file)) ? { ...p, media: p.media.filter(m => !withheld.has(m.file)) } : p
18
+ return {
19
+ indi: new Map([...indi].map(([id, p]) => [id, living.has(id) ? stub(p) : keep(p)])),
20
+ fam: new Map([...fam].map(([id, f]) => [id, living.has(f.husb) || living.has(f.wife) ? { ...f, marr: {} } : f])),
21
+ }
22
+ }
package/lib/render.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import path from 'node:path'
3
3
  import { place, redact } from './redact.mjs'
4
4
  import { esc } from './html.mjs'
5
- import { yr, byBirth } from './dates.mjs'
5
+ import { yr, byBirth, birthYear } from './dates.mjs'
6
6
  import { hourglassLayout, hourglassSvg } from './hourglass.mjs'
7
7
 
8
8
  export { esc, yr }
@@ -50,7 +50,7 @@ export class Renderer {
50
50
  `<meta name=viewport content='width=device-width,initial-scale=1'>` +
51
51
  `<title>${esc(title)}</title><link rel=stylesheet href=style.css></head>` +
52
52
  `<body><div class=wrap>${body}` +
53
- `<footer>Generated ${this.source ? `from <code>${esc(this.source)}</code> ` : ''}by kinsite ` +
53
+ `<footer>Generated ${this.source ? `from <code>${esc(this.source)}</code> ` : ''}by <a href="https://github.com/chrismo/kinsite">kinsite</a> ` +
54
54
  `&middot; ${this.indi.size} individuals &middot; ${this.fam.size} families</footer>` +
55
55
  `</div></body></html>`
56
56
  }
@@ -110,6 +110,10 @@ export class Renderer {
110
110
  const p = this.indi.get(pid), { kin, fam } = this
111
111
  const b = ['<p class=back><a href="index.html">&larr; All people</a></p>',
112
112
  `<h1>${esc(p.name || '(unnamed)')}</h1>`]
113
+ if (p.private) {
114
+ b.push('<p class=sub>Details of living people are withheld.</p>')
115
+ return { html: this.page(p.name, b.join('')), withPhoto: false }
116
+ }
113
117
  const meta = [{ M: 'Male', F: 'Female' }[p.sex] ?? '', life(p)].filter(Boolean).join(' &middot; ')
114
118
  if (meta) b.push(`<p class=sub>${meta}</p>`)
115
119
 
@@ -125,6 +129,8 @@ export class Renderer {
125
129
  }
126
130
  }
127
131
 
132
+ b.push('<h2>Family</h2>' + this.chartSvg(pid))
133
+
128
134
  const { imgs, docs } = this.attachments(p)
129
135
  if (imgs.length) {
130
136
  const cells = imgs.map(([md, src]) =>
@@ -136,8 +142,6 @@ export class Renderer {
136
142
  const vit = this.eventsHtml(p)
137
143
  if (vit) b.push(`<div class=card>${vit}</div>`)
138
144
 
139
- b.push('<h2>Family</h2>' + this.chartSvg(pid))
140
-
141
145
  const rel = []
142
146
  const par = []
143
147
  if (p.famc && fam.has(p.famc)) {
@@ -186,7 +190,8 @@ export class Renderer {
186
190
  const disp = p.surn ? `${esc(p.surn)}, ${esc(p.giv)}` : esc(p.name || '(unnamed)')
187
191
  const l = life(p)
188
192
  const photo = hasPhoto(p)
189
- return `<li data-n="${esc(p.name.toLowerCase())}"${photo ? ' data-photo' : ''}>` +
193
+ const b = birthYear(p)
194
+ return `<li data-n="${esc(p.name.toLowerCase())}"${b ? ` data-b=${b}` : ''}${photo ? ' data-photo' : ''}>` +
190
195
  `<a href="${p.id}.html">${disp}</a>` + (l ? ` <span class=yr>${l}</span>` : '') +
191
196
  (photo ? ' <span class=cam title="Has photos">📷</span>' : '') + '</li>'
192
197
  })
@@ -198,6 +203,8 @@ export class Renderer {
198
203
  hero +
199
204
  '<h2>All people</h2>' +
200
205
  '<input id=q placeholder="Filter by name…" autocomplete=off>' +
206
+ '<label id=sortby hidden>Sort by <select id=sort><option value=name selected>Name (A–Z)</option>' +
207
+ '<option value=old>Birth year, oldest first</option><option value=new>Birth year, newest first</option></select></label>' +
201
208
  `<label class=only><input type=checkbox id=photos> Only people with photos (${withphoto})</label>` +
202
209
  `<ul class=people id=list>${items.join('')}</ul>` +
203
210
  "<script>var q=document.getElementById('q'),ph=document.getElementById('photos')," +
@@ -205,7 +212,14 @@ export class Renderer {
205
212
  "function f(){var v=q.value.toLowerCase();" +
206
213
  'for(var i=0;i<L.length;i++){L[i].style.display=' +
207
214
  "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>"
215
+ "q.addEventListener('input',f);ph.addEventListener('change',f);f();" +
216
+ "var sb=document.getElementById('sort'),u=document.getElementById('list'),A=[].slice.call(L);" +
217
+ "function b(e){var y=e.getAttribute('data-b');return y?+y:null;}" +
218
+ "document.getElementById('sortby').hidden=false;" +
219
+ "sb.addEventListener('change',function(){var d={name:0,old:1,new:-1}[sb.value];" +
220
+ "A.map(function(e,i){return[e,i];}).sort(function(x,y){var p=b(x[0]),r=b(y[0]);" +
221
+ "return (!d?0:p===null||r===null?(p===null)-(r===null):d*(p-r))||x[1]-y[1];})" +
222
+ ".forEach(function(x){u.appendChild(x[0]);});});</script>"
209
223
  return this.page(this.title, body)
210
224
  }
211
225
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kinsite",
3
- "version": "0.1.0",
3
+ "version": "0.2.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
  }