coherent-docs-theme 1.0.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.
Files changed (40) hide show
  1. package/README.md +314 -0
  2. package/assets/gameface-ui-header-dark.svg +5 -0
  3. package/assets/gameface-ui-header-light.svg +5 -0
  4. package/components/Api.astro +29 -0
  5. package/components/BeforeAfter.astro +124 -0
  6. package/components/Details.astro +37 -0
  7. package/components/Enhancement.astro +29 -0
  8. package/components/Feature.astro +29 -0
  9. package/components/Figure.astro +107 -0
  10. package/components/Fix.astro +29 -0
  11. package/components/GallerySlider.astro +260 -0
  12. package/components/If.astro +6 -0
  13. package/components/IfEnv.astro +5 -0
  14. package/components/IfNot.astro +6 -0
  15. package/components/IncludeSnippets.astro +13 -0
  16. package/components/Internal.astro +3 -0
  17. package/components/ProductName.astro +13 -0
  18. package/components/Release.astro +68 -0
  19. package/components/SideBarWithDropdown.astro +8 -0
  20. package/components/Typeref.astro +35 -0
  21. package/index.ts +152 -0
  22. package/internal/overrideComponents.ts +29 -0
  23. package/internal/themeConfig.ts +21 -0
  24. package/internal-components/ChangelogRow.astro +39 -0
  25. package/internal-components/NavLinks.astro +253 -0
  26. package/internal-components/ProgressIndicator.astro +53 -0
  27. package/overrides/Footer.astro +103 -0
  28. package/overrides/Header.astro +91 -0
  29. package/overrides/Search.astro +234 -0
  30. package/overrides/ThemeSelect.astro +218 -0
  31. package/package.json +46 -0
  32. package/remark-directives/if.ts +51 -0
  33. package/remark-directives/includeSnippets.ts +120 -0
  34. package/remark-directives/index.ts +13 -0
  35. package/remark-directives/internal.ts +20 -0
  36. package/remark-directives/release.ts +29 -0
  37. package/styles.css +452 -0
  38. package/utils/changelogSideBar.ts +105 -0
  39. package/utils/changelogSideBarMultipleDocs.ts +119 -0
  40. package/utils/coherentReleases.ts +62 -0
@@ -0,0 +1,119 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import matter from 'gray-matter';
4
+ import { unified } from 'unified';
5
+ import remarkParse from 'remark-parse';
6
+ import remarkMdx from 'remark-mdx';
7
+ import type { Root, Content, Heading as MdastHeading, Text } from 'mdast';
8
+ import type { MdxTextExpression } from 'mdast-util-mdx-expression';
9
+
10
+ type BadgeVariant = "note" | "danger" | "success" | "caution" | "tip" | "default";
11
+
12
+ type HeadingSidebarItem = {
13
+ label: string;
14
+ link: string;
15
+ badge?: {
16
+ text: string;
17
+ variant?: BadgeVariant
18
+ }
19
+ };
20
+
21
+ function parseHeadingWithBadge(node: MdastHeading) {
22
+ const text = node.children
23
+ .filter((child): child is Text => child.type === 'text')
24
+ .map((child) => child.value)
25
+ .join('');
26
+
27
+ const badgeNode = node.children.find(
28
+ (child): child is Text =>
29
+ child.type === 'text' && child.value.includes(':badge[')
30
+ );
31
+
32
+ let badgeText = '';
33
+ if (badgeNode) {
34
+ const match = badgeNode.value.match(/:badge\[(.*?)\]/);
35
+ if (match && match[1]) {
36
+ badgeText = match[1];
37
+ }
38
+ }
39
+
40
+ const badgeVariantNode = node.children.find(
41
+ (child): child is MdxTextExpression =>
42
+ child.type === 'mdxTextExpression' && child.value.includes('variant="')
43
+ );
44
+
45
+ let badgeVariant: BadgeVariant | undefined;
46
+ if (badgeVariantNode) {
47
+ const match = badgeVariantNode.value.match(/variant="(.*?)"/);
48
+ if (match && match[1]) {
49
+ badgeVariant = match[1] as BadgeVariant;
50
+ }
51
+ }
52
+
53
+ let badge = null;
54
+ if (badgeText) {
55
+ badge = { text: badgeText, variant: badgeVariant };
56
+ }
57
+
58
+ return { text, badge };
59
+ }
60
+
61
+ function slugify(text: string): string {
62
+ return text
63
+ .replace(/:badge\[.*?\]/g, '')
64
+ .trim()
65
+ .toLowerCase()
66
+ .replace(/\s+/g, '-')
67
+ .replace(/[^\w\-]+/g, '');
68
+ }
69
+
70
+ function walk(node: Content | Root, docsDir: string, headings: HeadingSidebarItem[]): void {
71
+ if (node.type === 'heading' && node.depth === 2) {
72
+ const { text, badge } = parseHeadingWithBadge(node);
73
+ const heading: HeadingSidebarItem = {
74
+ label: text.replace(/:badge\[.*?\]/g, '').trim(),
75
+ link: `${docsDir}/changelog/#${slugify(text)}`,
76
+ };
77
+
78
+ if (badge) {
79
+ heading.badge = {
80
+ text: badge.text,
81
+ ...(badge.variant && { variant: badge.variant })
82
+ };
83
+ }
84
+
85
+ headings.push(heading);
86
+ }
87
+
88
+ if ('children' in node && node.children) {
89
+ for (const child of node.children) {
90
+ walk(child, docsDir, headings);
91
+ }
92
+ }
93
+ }
94
+
95
+ function generateChangelog(docsDirName: string, changelogPath: string) {
96
+ const headings: HeadingSidebarItem[] = [];
97
+ const filePath = path.resolve(changelogPath);
98
+
99
+ if (!fs.existsSync(filePath)) {
100
+ return { label: 'Changelog', items: [] };
101
+ }
102
+
103
+ const file = fs.readFileSync(filePath, 'utf-8');
104
+ const { content } = matter(file);
105
+
106
+ const tree = unified()
107
+ .use(remarkParse)
108
+ .use(remarkMdx)
109
+ .parse(content) as Root;
110
+
111
+ walk(tree, docsDirName, headings);
112
+
113
+ return {
114
+ label: 'Changelog',
115
+ items: [...headings]
116
+ };
117
+ }
118
+
119
+ export default generateChangelog;
@@ -0,0 +1,62 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import matter from 'gray-matter';
4
+
5
+ export function getSortedCoherentReleases(directory: string = 'src/content/docs/releases') {
6
+ if (!fs.existsSync(directory)) return [];
7
+
8
+ const isDev = process.env.NODE_ENV === 'development' || process.env.MODE === 'development';
9
+
10
+ const entries = fs.readdirSync(directory, { withFileTypes: true });
11
+ const folders = entries.filter(entry => entry.isDirectory());
12
+
13
+ const releaseItems = folders
14
+ .map(folder => {
15
+ const folderName = folder.name;
16
+
17
+ if (folderName.toLowerCase() === 'next_release' && !isDev) {
18
+ return null;
19
+ }
20
+
21
+ const indexPath = path.join(directory, folderName, 'index.mdx');
22
+ const indexMdPath = path.join(directory, folderName, 'index.md');
23
+ const finalPath = fs.existsSync(indexPath) ? indexPath : (fs.existsSync(indexMdPath) ? indexMdPath : null);
24
+
25
+ if (!finalPath) return null;
26
+
27
+ const fileContent = fs.readFileSync(finalPath, 'utf-8');
28
+ const { data } = matter(fileContent);
29
+
30
+ if (data.draft === true && !isDev) {
31
+ return null;
32
+ }
33
+
34
+ return {
35
+ label: data.sidebar?.label || data.title || folderName,
36
+ link: `/releases/${folderName.replaceAll('.', '').toLowerCase()}`,
37
+ badge: data.sidebar?.badge,
38
+ };
39
+ })
40
+ .filter((item): item is NonNullable<typeof item> => item !== null);
41
+
42
+ const nextRelease = releaseItems.find(i => i.label.toLowerCase() === 'next_release');
43
+ const versionedReleases = releaseItems
44
+ .filter(i => i.label.toLowerCase() !== 'next_release')
45
+ .sort((a, b) => b.label.localeCompare(a.label, undefined, { numeric: true }));
46
+
47
+ if (versionedReleases[0] && !versionedReleases[0].badge) {
48
+ versionedReleases[0].badge = {
49
+ text: 'Latest',
50
+ variant: 'tip'
51
+ };
52
+ }
53
+ const finalItems = nextRelease ? [nextRelease, ...versionedReleases] : versionedReleases;
54
+
55
+ return [
56
+ {
57
+ label: 'Releases',
58
+ items: finalItems,
59
+ collapsed: true
60
+ }
61
+ ];
62
+ }