@conduction/docusaurus-preset 2.7.0-beta.2 → 2.7.0-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conduction/docusaurus-preset",
3
- "version": "2.7.0-beta.2",
3
+ "version": "2.7.0-beta.4",
4
4
  "scripts": {
5
5
  "prepack": "node scripts/prepack-bundle-css.js"
6
6
  },
package/src/index.js CHANGED
@@ -42,31 +42,47 @@ function resolveAppVersion(opts) {
42
42
  if (opts.appVersion) return String(opts.appVersion);
43
43
 
44
44
  /* Nextcloud apps: appinfo/info.xml carries the canonical version.
45
- We avoid pulling in an XML parser for one tag — a non-greedy regex
46
- against the file content is robust enough for the standard
47
- `<version>x.y.z</version>` shape the app store mandates. */
48
- try {
49
- const infoPath = path.join(process.cwd(), 'appinfo', 'info.xml');
50
- if (fs.existsSync(infoPath)) {
51
- const xml = fs.readFileSync(infoPath, 'utf8');
52
- const m = xml.match(/<version>\s*([^<\s]+)\s*<\/version>/);
53
- if (m && m[1]) return m[1];
45
+ Conduction docs sites live at <appRepo>/docs/ next to the app's
46
+ <appRepo>/appinfo/, so we check both the cwd AND the parent
47
+ before giving up. We avoid pulling in an XML parser for one tag
48
+ a non-greedy regex against the file content is robust enough
49
+ for the standard `<version>x.y.z</version>` shape the app store
50
+ mandates. */
51
+ const cwd = process.cwd();
52
+ const infoCandidates = [
53
+ path.join(cwd, 'appinfo', 'info.xml'),
54
+ path.join(cwd, '..', 'appinfo', 'info.xml'),
55
+ ];
56
+ for (const infoPath of infoCandidates) {
57
+ try {
58
+ if (fs.existsSync(infoPath)) {
59
+ const xml = fs.readFileSync(infoPath, 'utf8');
60
+ const m = xml.match(/<version>\s*([^<\s]+)\s*<\/version>/);
61
+ if (m && m[1]) return m[1];
62
+ }
63
+ } catch (e) {
64
+ /* fall through */
54
65
  }
55
- } catch (e) {
56
- /* fall through */
57
66
  }
58
67
 
59
- /* Non-Nextcloud sites: package.json version. Walks up from cwd in
60
- case the site builds from a sub-directory; one level deep is
61
- enough for the conduction-website layout. */
62
- try {
63
- const pkgPath = path.join(process.cwd(), 'package.json');
64
- if (fs.existsSync(pkgPath)) {
65
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
66
- if (pkg.version) return pkg.version;
68
+ /* Non-Nextcloud sites: package.json version. Same parent-walk so
69
+ a site building from <repo>/site/ still finds <repo>/package.json. */
70
+ const pkgCandidates = [
71
+ path.join(cwd, 'package.json'),
72
+ path.join(cwd, '..', 'package.json'),
73
+ ];
74
+ for (const pkgPath of pkgCandidates) {
75
+ try {
76
+ if (fs.existsSync(pkgPath)) {
77
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
78
+ /* Skip the docs-site's own placeholder package.json (every
79
+ Conduction docs site is scaffolded with name="*-docs" and
80
+ version="0.0.0"); fall through to the parent in that case. */
81
+ if (pkg.version && pkg.version !== '0.0.0') return pkg.version;
82
+ }
83
+ } catch (e) {
84
+ /* fall through */
67
85
  }
68
- } catch (e) {
69
- /* fall through */
70
86
  }
71
87
 
72
88
  return undefined;
@@ -112,10 +128,16 @@ const baseNavbar = (siteName, repoUrl) => ({
112
128
  src: 'img/logo.svg',
113
129
  srcDark: 'img/logo-dark.svg',
114
130
  },
131
+ /* `custom-*` prefix is the Docusaurus convention for theme-defined
132
+ navbar item types — items prefixed this way bypass the strict Joi
133
+ schema validator in @docusaurus/theme-classic, so the brand Navbar
134
+ swizzle can dispatch on them without registering each shape with
135
+ core. The swizzle accepts both `custom-github` and the bare
136
+ `github` (etc.) for forward-compat. */
115
137
  items: [
116
- { type: 'versionPill', position: 'right' },
117
- { type: 'apiDocs', position: 'right' },
118
- { type: 'github', href: repoUrl || 'https://github.com/ConductionNL', position: 'right' },
138
+ { type: 'custom-versionPill', position: 'right' },
139
+ { type: 'custom-apiDocs', position: 'right' },
140
+ { type: 'custom-github', href: repoUrl || 'https://github.com/ConductionNL', position: 'right' },
119
141
  { type: 'localeDropdown', position: 'right' },
120
142
  ],
121
143
  });
@@ -24,12 +24,18 @@
24
24
  * { type: 'doc', label, to } internal doc link
25
25
  * { type: 'link', label, to | href } internal/external link
26
26
  * { type: 'localeDropdown' } Docusaurus locale switcher
27
- * { type: 'github', href } icon-only GitHub mark
28
- * { type: 'apiDocs', label?, to } icon + "API Documentation"
29
- * { type: 'versionPill', prefix? } "Stable · v{x.y.z}" pill
27
+ * { type: 'custom-github', href } icon-only GitHub mark
28
+ * { type: 'custom-apiDocs', label?, to } icon + "API Documentation"
29
+ * { type: 'custom-versionPill', prefix? } "Stable · v{x.y.z}" pill
30
30
  * reads customFields.appVersion;
31
31
  * hidden when no version
32
32
  *
33
+ * The `custom-` prefix is required so Docusaurus's themeConfig schema
34
+ * validator passes (`@docusaurus/theme-classic` rejects unknown bare
35
+ * type names). The swizzle below accepts both the prefixed and the
36
+ * bare names so 2.7.0-beta.1 sites that wired the bare names keep
37
+ * working after the upgrade.
38
+ *
33
39
  * The pill prefix defaults to "Stable" but can be overridden per site
34
40
  * (e.g. prefix="Beta" while on a pre-1.0 release line).
35
41
  *
@@ -46,6 +52,24 @@ import {brandFor, productWordmark} from '../brand.jsx';
46
52
  import {ICONS} from '../../components/primitives/icons';
47
53
  import styles from './styles.module.css';
48
54
 
55
+ /**
56
+ * Brand-specific navbar item types live under the `custom-` prefix
57
+ * because Docusaurus's themeConfig validator (Joi schema in
58
+ * @docusaurus/theme-classic) rejects unknown top-level types. The
59
+ * `custom-` namespace is the documented escape hatch: items prefixed
60
+ * with `custom-` bypass schema validation and are passed through to
61
+ * the theme as-is. The brand Navbar then dispatches on them below.
62
+ *
63
+ * Sites may also use the bare names (`github`, `apiDocs`,
64
+ * `versionPill`) — they render identically here but Docusaurus will
65
+ * reject the config at load time. Accept both forms so the migration
66
+ * from 2.7.0-beta.1 to .beta.2 doesn't break sites that already
67
+ * configured the bare names.
68
+ */
69
+ function typeIs(item, kind) {
70
+ return item.type === kind || item.type === 'custom-' + kind;
71
+ }
72
+
49
73
  /**
50
74
  * Render a single navbar item. The brand navbar supports a small
51
75
  * subset of Docusaurus item types plus the three brand-specific types
@@ -64,7 +88,7 @@ function NavItem({item, location, appVersion}) {
64
88
  /* GitHub: icon-only link with an accessible label. The aria-label
65
89
  gives screen-readers + browser tooltips a name without rendering
66
90
  a visible text label in the navbar. */
67
- if (item.type === 'github') {
91
+ if (typeIs(item, 'github')) {
68
92
  return (
69
93
  <a
70
94
  href={item.href || 'https://github.com/ConductionNL'}
@@ -82,7 +106,7 @@ function NavItem({item, location, appVersion}) {
82
106
  /* API Documentation: icon + label link. Target defaults to /api
83
107
  (the Redocusaurus mount point used by every Conduction docs site).
84
108
  Sites can override via `to` or `href`. */
85
- if (item.type === 'apiDocs') {
109
+ if (typeIs(item, 'apiDocs')) {
86
110
  const label = item.label || 'API Documentation';
87
111
  const to = item.to || '/api';
88
112
  const href = item.href;
@@ -106,7 +130,7 @@ function NavItem({item, location, appVersion}) {
106
130
  or package.json). Hidden when no version is available so sites
107
131
  without an app version (Hydra, design-system itself) get a clean
108
132
  navbar instead of an empty pill. */
109
- if (item.type === 'versionPill') {
133
+ if (typeIs(item, 'versionPill')) {
110
134
  if (!appVersion) return null;
111
135
  const prefix = item.prefix || 'Stable';
112
136
  return (
@@ -198,7 +222,12 @@ export default function Navbar() {
198
222
  position="right" — but the three brand-specific item types
199
223
  (github, apiDocs, versionPill) live on the right by convention,
200
224
  mirroring the docs-shell mock. */
201
- const RIGHT_TYPES = new Set(['localeDropdown', 'github', 'apiDocs', 'versionPill']);
225
+ const RIGHT_TYPES = new Set([
226
+ 'localeDropdown',
227
+ 'github', 'custom-github',
228
+ 'apiDocs', 'custom-apiDocs',
229
+ 'versionPill', 'custom-versionPill',
230
+ ]);
202
231
  const leftItems = items.filter(i => i.position !== 'right' && !RIGHT_TYPES.has(i.type));
203
232
  const rightItems = items.filter(i => i.position === 'right' || RIGHT_TYPES.has(i.type));
204
233