cosmos-docusaurus-theme 2.0.2 → 2.0.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/CHANGELOG.md +25 -1
- package/README.md +34 -33
- package/package.json +12 -3
- package/src/css/theme.css +1061 -259
- package/src/index.js +57 -9
package/src/index.js
CHANGED
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
*
|
|
10
10
|
* No component swizzling — CSS-only override of Infima variables.
|
|
11
11
|
*
|
|
12
|
+
* Options:
|
|
13
|
+
* injectFavicon {boolean} — inject the cosmos atom favicon (default: true).
|
|
14
|
+
* Set to false if your site already has its own favicon.
|
|
15
|
+
*
|
|
12
16
|
* @see https://docusaurus.io/docs/api/plugin-methods/lifecycle-apis#getClientModules
|
|
13
17
|
*/
|
|
14
18
|
|
|
@@ -17,12 +21,27 @@
|
|
|
17
21
|
const path = require('path');
|
|
18
22
|
const { version } = require('../package.json');
|
|
19
23
|
|
|
24
|
+
// Cosmos favicon — indigo rounded-square with atom/constellation symbol.
|
|
25
|
+
// Pre-encoded as a valid data: URI (all special chars percent-encoded).
|
|
26
|
+
const FAVICON_SVG = encodeURIComponent(
|
|
27
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">' +
|
|
28
|
+
'<rect width="32" height="32" rx="7" fill="#465fff"/>' +
|
|
29
|
+
'<circle cx="16" cy="16" r="6.5" fill="none" stroke="white" stroke-width="1.5" opacity="0.5"/>' +
|
|
30
|
+
'<circle cx="16" cy="16" r="2.5" fill="white"/>' +
|
|
31
|
+
'<circle cx="16" cy="9" r="1.5" fill="white"/>' +
|
|
32
|
+
'<circle cx="22" cy="20" r="1.5" fill="white"/>' +
|
|
33
|
+
'<circle cx="10" cy="20" r="1.5" fill="white"/>' +
|
|
34
|
+
'</svg>'
|
|
35
|
+
);
|
|
36
|
+
|
|
20
37
|
/**
|
|
21
38
|
* @param {import('@docusaurus/types').LoadContext} _context
|
|
22
|
-
* @param {
|
|
39
|
+
* @param {{ injectFavicon?: boolean }} options
|
|
23
40
|
* @returns {import('@docusaurus/types').Plugin}
|
|
24
41
|
*/
|
|
25
|
-
function cosmosDocusaurusTheme(_context,
|
|
42
|
+
function cosmosDocusaurusTheme(_context, options) {
|
|
43
|
+
const { injectFavicon = true } = options ?? {};
|
|
44
|
+
|
|
26
45
|
return {
|
|
27
46
|
name: 'cosmos-docusaurus-theme',
|
|
28
47
|
|
|
@@ -39,20 +58,49 @@ function cosmosDocusaurusTheme(_context, _options) {
|
|
|
39
58
|
/**
|
|
40
59
|
* Inject the package version as a CSS custom property so the sidebar
|
|
41
60
|
* version badge stays in sync with package.json automatically.
|
|
61
|
+
* Optionally injects the cosmos favicon (opt-out via injectFavicon: false).
|
|
42
62
|
*
|
|
43
63
|
* @returns {import('@docusaurus/types').HtmlTags}
|
|
44
64
|
*/
|
|
45
65
|
injectHtmlTags() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
/** @type {import('@docusaurus/types').HtmlTagObject[]} */
|
|
67
|
+
const headTags = [
|
|
68
|
+
{
|
|
69
|
+
tagName: 'style',
|
|
70
|
+
innerHTML: `:root { --cosmos-version: "cosmos v${version}"; }`,
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
if (injectFavicon) {
|
|
75
|
+
headTags.push({
|
|
76
|
+
tagName: 'link',
|
|
77
|
+
attributes: {
|
|
78
|
+
rel: 'icon',
|
|
79
|
+
type: 'image/svg+xml',
|
|
80
|
+
href: `data:image/svg+xml,${FAVICON_SVG}`,
|
|
51
81
|
},
|
|
52
|
-
|
|
53
|
-
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { headTags };
|
|
54
86
|
},
|
|
55
87
|
};
|
|
56
88
|
}
|
|
57
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Validate plugin options passed by the consumer.
|
|
92
|
+
*
|
|
93
|
+
* @param {{ validate: Function, options: object }} param
|
|
94
|
+
* @returns {object}
|
|
95
|
+
*/
|
|
96
|
+
cosmosDocusaurusTheme.validateOptions = ({ options }) => {
|
|
97
|
+
const { injectFavicon = true } = options ?? {};
|
|
98
|
+
if (typeof injectFavicon !== 'boolean') {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`[cosmos-docusaurus-theme] Option "injectFavicon" must be a boolean, got: ${typeof injectFavicon}`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return { injectFavicon };
|
|
104
|
+
};
|
|
105
|
+
|
|
58
106
|
module.exports = cosmosDocusaurusTheme;
|