@glossarist/concept-browser 0.4.1 → 0.4.3

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
@@ -101,6 +101,29 @@ Replace `IEV` with the uppercase dataset ID.
101
101
 
102
102
  All dataset configuration lives in a single file. Adding a new dataset requires **zero code changes** — just add an entry to `datasets.yml` and run the pipeline.
103
103
 
104
+ ### Branding and favicon
105
+
106
+ The `site-config.yml` `branding` section controls the site's visual identity:
107
+
108
+ ```yaml
109
+ branding:
110
+ primaryColor: "#d97706"
111
+ darkColor: "#1a1a2e"
112
+ logo:
113
+ path: /logos/my-logo.svg # URL path served to browsers
114
+ alt: "My Org"
115
+ localPath: logos/my-logo.svg # Local file used as favicon source
116
+ favicon: logos/my-favicon.svg # Optional — overrides logo.localPath for favicon generation
117
+ ```
118
+
119
+ During build, favicons are auto-generated from a single SVG source using the [`favicons`](https://npmjs.com/package/favicons) package. The resolution order is:
120
+
121
+ 1. `branding.favicon` — explicit path to favicon source SVG
122
+ 2. `branding.logo.localPath` — falls back to the site logo
123
+ 3. Package default `public/favicon.svg`
124
+
125
+ The build produces: `favicon.ico`, `favicon.svg`, `favicon-{16,32,48}x{16,32,48}.png`, `apple-touch-icon-*.png` (all standard iOS sizes), and injects the corresponding `<link>` and `<meta>` tags into `index.html` via a Vite plugin.
126
+
104
127
  ### Full reference
105
128
 
106
129
  ```yaml
package/cli/index.mjs CHANGED
@@ -78,7 +78,7 @@ Environment:
78
78
  if (!process.env.SITE_CONFIG && !process.env.SITE_ID && named.site) {
79
79
  process.env.SITE_ID = named.site;
80
80
  }
81
- loadSiteConfig(named.site ? [named.site] : []);
81
+ const { config } = loadSiteConfig(named.site ? [named.site] : []);
82
82
 
83
83
  if (cmd === 'build' || cmd === 'site') {
84
84
  for (const step of ['fetch', 'generate', 'edges']) {
@@ -86,15 +86,62 @@ Environment:
86
86
  await commands[step]();
87
87
  }
88
88
 
89
- // Copy package static files (favicon, etc.) to deployment public dir
89
+ // Generate favicons from site logo
90
90
  const fs = await import('fs');
91
91
  const publicDir = resolve(process.cwd(), 'public');
92
92
  fs.mkdirSync(publicDir, { recursive: true });
93
- for (const file of ['favicon.svg']) {
94
- const src = resolve(pkgRoot, 'public', file);
95
- if (fs.existsSync(src)) {
96
- fs.copyFileSync(src, resolve(publicDir, file));
93
+
94
+ const branding = config?.branding || {};
95
+ const faviconSrc =
96
+ (branding.favicon && resolve(process.cwd(), branding.favicon)) ||
97
+ (branding.logo?.localPath && resolve(process.cwd(), branding.logo.localPath)) ||
98
+ resolve(pkgRoot, 'public', 'favicon.svg');
99
+
100
+ let faviconHtml = '';
101
+ if (fs.existsSync(faviconSrc)) {
102
+ console.log(`\n=== FAVICONS ===\n`);
103
+ const favicons = (await import('favicons')).default;
104
+ const source = fs.readFileSync(faviconSrc);
105
+ const response = await favicons(source, {
106
+ appName: config?.title || 'Glossarist',
107
+ background: branding.primaryColor || '#2563eb',
108
+ theme_color: branding.primaryColor || '#2563eb',
109
+ icons: {
110
+ android: false,
111
+ appleIcon: true,
112
+ appleStartup: false,
113
+ favicons: true,
114
+ windows: false,
115
+ yandex: false,
116
+ },
117
+ });
118
+
119
+ // Write all generated images and files to public/
120
+ for (const img of response.images) {
121
+ fs.writeFileSync(resolve(publicDir, img.name), img.contents);
122
+ }
123
+ for (const file of response.files) {
124
+ fs.writeFileSync(resolve(publicDir, file.name), file.contents);
125
+ }
126
+
127
+ // Keep the original SVG for dark mode support
128
+ if (faviconSrc.endsWith('.svg')) {
129
+ fs.copyFileSync(faviconSrc, resolve(publicDir, 'favicon.svg'));
97
130
  }
131
+
132
+ faviconHtml = response.html.join('\n ');
133
+ // Add SVG favicon
134
+ if (faviconSrc.endsWith('.svg')) {
135
+ faviconHtml += '\n <link rel="icon" type="image/svg+xml" href="/favicon.svg">';
136
+ }
137
+ // Write tags for Vite plugin to pick up
138
+ fs.writeFileSync(resolve(publicDir, 'favicon-links.html'), faviconHtml);
139
+ console.log(` Generated ${response.images.length} favicon files`);
140
+ }
141
+
142
+ // Pass favicon tags to Vite via env
143
+ if (faviconHtml) {
144
+ process.env.FAVICON_HTML = faviconHtml;
98
145
  }
99
146
 
100
147
  // Run vite build using the package's vite.config.ts
package/index.html CHANGED
@@ -2,7 +2,6 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
6
  <link rel="preconnect" href="https://fonts.googleapis.com">
8
7
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glossarist/concept-browser",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Vue SPA for browsing Glossarist terminology datasets with cross-reference resolution, graph visualization, and multi-language support",
5
5
  "type": "module",
6
6
  "bin": {
@@ -36,6 +36,7 @@
36
36
  "devDependencies": {
37
37
  "@types/d3": "^7.4.3",
38
38
  "@vue/test-utils": "^2.4.8",
39
+ "favicons": "^7.2.0",
39
40
  "happy-dom": "^20.9.0",
40
41
  "typescript": "~5.7.3",
41
42
  "vitest": "^4.1.5",
@@ -123,9 +123,13 @@ function sourcesToJsonLd(sources) {
123
123
  if (s.origin.ref) {
124
124
  const ref = s.origin.ref;
125
125
  const refObj = { '@type': 'gl:Ref' };
126
- if (ref.source) refObj['gl:source'] = ref.source;
127
- if (ref.id) refObj['gl:id'] = ref.id;
128
- if (ref.version) refObj['gl:version'] = ref.version;
126
+ if (typeof ref === 'string') {
127
+ refObj['gl:source'] = ref;
128
+ } else {
129
+ if (ref.source) refObj['gl:source'] = ref.source;
130
+ if (ref.id) refObj['gl:id'] = ref.id;
131
+ if (ref.version) refObj['gl:version'] = ref.version;
132
+ }
129
133
  origin['gl:ref'] = refObj;
130
134
  }
131
135
  if (s.origin.locality) {
@@ -119,15 +119,19 @@ function mapSourceFromJsonLd(s: any): Record<string, unknown> {
119
119
  const o = s['gl:origin'];
120
120
  if (o['gl:ref']) {
121
121
  const rawRef = o['gl:ref'];
122
- const refObj: Record<string, unknown> = {};
123
- // v3: ref is always an object { gl:source, gl:id, gl:version }
124
- if (rawRef['gl:source']) refObj.source = rawRef['gl:source'];
125
- if (rawRef['gl:id']) refObj.id = rawRef['gl:id'];
126
- if (rawRef['gl:version']) refObj.version = rawRef['gl:version'];
127
- if (rawRef['source']) refObj.source = rawRef['source'];
128
- if (rawRef['id']) refObj.id = rawRef['id'];
129
- if (rawRef['version']) refObj.version = rawRef['version'];
130
- if (Object.keys(refObj).length > 0) origin.ref = refObj;
122
+ if (typeof rawRef === 'string') {
123
+ // Legacy format: gl:ref is a plain string (e.g. "ISO/TS 14812:2022")
124
+ origin.ref = { source: rawRef };
125
+ } else {
126
+ const refObj: Record<string, unknown> = {};
127
+ if (rawRef['gl:source']) refObj.source = rawRef['gl:source'];
128
+ if (rawRef['gl:id']) refObj.id = rawRef['gl:id'];
129
+ if (rawRef['gl:version']) refObj.version = rawRef['gl:version'];
130
+ if (rawRef['source']) refObj.source = rawRef['source'];
131
+ if (rawRef['id']) refObj.id = rawRef['id'];
132
+ if (rawRef['version']) refObj.version = rawRef['version'];
133
+ if (Object.keys(refObj).length > 0) origin.ref = refObj;
134
+ }
131
135
  }
132
136
  if (o['gl:locality']) {
133
137
  const loc: Record<string, unknown> = {};
@@ -176,13 +176,14 @@ function buildSimulation(width: number, height: number) {
176
176
  const renderNodes = capped ? allVisible.slice(0, MAX_RENDER_NODES) : allVisible;
177
177
 
178
178
  const simNodes: SimNode[] = renderNodes.map(n => {
179
- const desig = Object.values(n.designations)[0] || '';
179
+ const lang = uiStore.selectedLang;
180
+ const desig = n.designations[lang] || Object.values(n.designations)[0] || '';
180
181
  return {
181
182
  uri: n.uri,
182
183
  register: n.register,
183
184
  conceptId: n.conceptId,
184
185
  designation: desig,
185
- hasDesignation: !!desig,
186
+ hasDesignation: !!n.designations[lang],
186
187
  loaded: n.loaded,
187
188
  nodeType: n.nodeType,
188
189
  x: width / 2 + (Math.random() - 0.5) * 200,
@@ -392,6 +393,11 @@ watch(registerEnabled, () => {
392
393
  nextTick(rebuildGraph);
393
394
  });
394
395
 
396
+ // Rebuild when language changes (designation labels depend on language)
397
+ watch(() => uiStore.selectedLang, () => {
398
+ nextTick(rebuildGraph);
399
+ });
400
+
395
401
  onMounted(() => {
396
402
  nextTick(() => {
397
403
  if (props.nodes.length > 0) {
@@ -555,7 +561,7 @@ function selectedNodeColor(): string {
555
561
  <div class="flex items-start justify-between gap-3">
556
562
  <div class="min-w-0">
557
563
  <h3 class="font-serif text-base text-ink-800 leading-snug truncate">
558
- {{ Object.values(selectedNode.designations)[0] || selectedNode.conceptId }}
564
+ {{ selectedNode.designations[uiStore.selectedLang] || Object.values(selectedNode.designations)[0] || selectedNode.conceptId }}
559
565
  </h3>
560
566
  <p class="text-xs text-ink-300 font-mono mt-0.5">{{ selectedNode.conceptId }}</p>
561
567
  <div class="flex items-center gap-1.5 mt-2">
package/vite.config.ts CHANGED
@@ -8,6 +8,27 @@ const cwd = process.cwd()
8
8
 
9
9
  const isTest = process.env.VITEST !== undefined
10
10
 
11
+ function faviconPlugin() {
12
+ return {
13
+ name: 'favicon-inject',
14
+ transformIndexHtml(html: string) {
15
+ const tags = process.env.FAVICON_HTML
16
+ if (!tags) return html
17
+ const faviconTags = tags.split('\n').map((line: string) => {
18
+ const m = line.trim().match(/<(\w+)\s+(.*)\/?>/s)
19
+ if (!m) return null
20
+ const tag = m[1]
21
+ const attrs: Record<string, string> = {}
22
+ for (const [, k, v] of m[2].matchAll(/(\w[\w-]*)="([^"]*)"/g)) {
23
+ attrs[k] = v
24
+ }
25
+ return { tag, attrs, injectTo: 'head' as const }
26
+ }).filter(Boolean)
27
+ return { html, tags: faviconTags }
28
+ },
29
+ }
30
+ }
31
+
11
32
  export default defineConfig({
12
33
  base: process.env.BASE_PATH || '/',
13
34
  root: __dirname,
@@ -16,7 +37,7 @@ export default defineConfig({
16
37
  outDir: resolve(cwd, 'dist'),
17
38
  emptyOutDir: true,
18
39
  },
19
- plugins: [vue()],
40
+ plugins: [faviconPlugin(), vue()],
20
41
  resolve: {
21
42
  alias: {
22
43
  '@': resolve(__dirname, 'src'),