@jaamd/jaad 0.0.0-stage → 1.0.0-rc.1

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 (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +58 -2
  3. package/dist/jaad.css +1331 -0
  4. package/docs/00-overview.md +25 -0
  5. package/docs/01-getting-started/01-installation.md +216 -0
  6. package/docs/01-getting-started/02-pages.md +109 -0
  7. package/docs/01-getting-started/03-deployment.md +100 -0
  8. package/docs/02-configurations/01-reference.md +215 -0
  9. package/docs/02-configurations/02-frontmatter.md +105 -0
  10. package/docs/02-configurations/03-i18n.md +210 -0
  11. package/docs/02-configurations/04-search.md +58 -0
  12. package/docs/02-configurations/05-themes.md +104 -0
  13. package/docs/02-configurations/06-styles.md +156 -0
  14. package/docs/02-configurations/07-custom-pages.md +119 -0
  15. package/docs/02-configurations/08-advanced-layout.md +139 -0
  16. package/docs/03-upgrading.md +208 -0
  17. package/index.ts +31 -0
  18. package/package.json +71 -3
  19. package/site.ts +36 -0
  20. package/src/config.ts +85 -0
  21. package/src/docs/advanced.ts +23 -0
  22. package/src/docs/collection.ts +109 -0
  23. package/src/docs/components/Breadcrumbs.astro +29 -0
  24. package/src/docs/components/DocsMobileNav.astro +90 -0
  25. package/src/docs/components/DocsNavTree.astro +57 -0
  26. package/src/docs/components/DocsPage.astro +66 -0
  27. package/src/docs/components/DocsPageNav.astro +53 -0
  28. package/src/docs/components/DocsSidebarLeft.astro +53 -0
  29. package/src/docs/components/PageActions.astro +83 -0
  30. package/src/docs/components/StructuredData.astro +55 -0
  31. package/src/docs/components/TableOfContents.astro +71 -0
  32. package/src/docs/config.ts +167 -0
  33. package/src/docs/content.ts +36 -0
  34. package/src/docs/endpoints.ts +89 -0
  35. package/src/docs/integration.ts +249 -0
  36. package/src/docs/layouts/DefaultDocsFrame.astro +33 -0
  37. package/src/docs/layouts/Docs.astro +169 -0
  38. package/src/docs/layouts/Page.astro +18 -0
  39. package/src/docs/link-plugins.ts +52 -0
  40. package/src/docs/links.ts +42 -0
  41. package/src/docs/locale-tree.ts +51 -0
  42. package/src/docs/model/ids.ts +87 -0
  43. package/src/docs/model/rendered.ts +185 -0
  44. package/src/docs/model/tree.ts +124 -0
  45. package/src/docs/model/validate.ts +75 -0
  46. package/src/docs/navigation.ts +75 -0
  47. package/src/docs/routes/404.astro +16 -0
  48. package/src/docs/routes/docs-index.astro +19 -0
  49. package/src/docs/routes/docs-slug.astro +54 -0
  50. package/src/docs/routes/docs-slug.md.ts +35 -0
  51. package/src/docs/routes/llms-locale.txt.ts +8 -0
  52. package/src/docs/routes/llms.txt.ts +4 -0
  53. package/src/docs/routes/search-index-locale.json.ts +8 -0
  54. package/src/docs/routes/search-index.json.ts +4 -0
  55. package/src/docs/runtime.ts +17 -0
  56. package/src/docs/search-index.ts +39 -0
  57. package/src/docs/styles/components/breadcrumbs.css +26 -0
  58. package/src/docs/styles/components/docs-mobile-nav.css +47 -0
  59. package/src/docs/styles/components/docs-page-nav.css +41 -0
  60. package/src/docs/styles/components/docs-page.css +9 -0
  61. package/src/docs/styles/components/docs-sidebar.css +59 -0
  62. package/src/docs/styles/components/page-actions.css +51 -0
  63. package/src/docs/styles/components/toc.css +38 -0
  64. package/src/docs/styles/components.css +7 -0
  65. package/src/docs/styles/docs.css +81 -0
  66. package/src/docs/styles/jaamd.css +11 -0
  67. package/src/docs/types.ts +39 -0
  68. package/src/docs/urls.ts +35 -0
  69. package/src/env.d.ts +13 -0
  70. package/src/integration.ts +36 -0
  71. package/src/site/components/Footer.astro +18 -0
  72. package/src/site/components/Head.astro +119 -0
  73. package/src/site/components/Header.astro +50 -0
  74. package/src/site/components/LocaleSwitcher.astro +111 -0
  75. package/src/site/components/Nav.astro +22 -0
  76. package/src/site/components/NavMobile.astro +105 -0
  77. package/src/site/components/SearchPalette.astro +409 -0
  78. package/src/site/components/SocialLinks.astro +27 -0
  79. package/src/site/components/ThemeSwitcher.astro +55 -0
  80. package/src/site/components/locale-switcher.ts +6 -0
  81. package/src/site/config.ts +149 -0
  82. package/src/site/fonts/OFL.txt +94 -0
  83. package/src/site/fonts/inter.woff2 +0 -0
  84. package/src/site/fonts/merriweather-italic.woff2 +0 -0
  85. package/src/site/fonts/merriweather.woff2 +0 -0
  86. package/src/site/fonts.ts +29 -0
  87. package/src/site/forges.ts +60 -0
  88. package/src/site/helpers.ts +4 -0
  89. package/src/site/infer.ts +75 -0
  90. package/src/site/integration.ts +59 -0
  91. package/src/site/layouts/Shell.astro +41 -0
  92. package/src/site/locales.ts +199 -0
  93. package/src/site/runtime.ts +19 -0
  94. package/src/site/search.ts +227 -0
  95. package/src/site/social.ts +44 -0
  96. package/src/site/styles/components/footer.css +8 -0
  97. package/src/site/styles/components/header.css +31 -0
  98. package/src/site/styles/components/locale-switcher.css +20 -0
  99. package/src/site/styles/components/nav-mobile.css +15 -0
  100. package/src/site/styles/components/nav.css +11 -0
  101. package/src/site/styles/components/not-found.css +11 -0
  102. package/src/site/styles/components/search.css +118 -0
  103. package/src/site/styles/components/shell.css +77 -0
  104. package/src/site/styles/components/social-links.css +8 -0
  105. package/src/site/styles/components/theme-switcher.css +14 -0
  106. package/src/site/styles/components.css +10 -0
  107. package/src/site/styles/global.css +140 -0
  108. package/src/site/styles/jaamd-forward.css +16 -0
  109. package/src/site/styles/jaamd-reverse.css +18 -0
  110. package/src/site/styles/tailwind.css +30 -0
  111. package/src/site/themes.ts +26 -0
  112. package/src/site/ui/en.ts +27 -0
  113. package/src/site/ui/it.ts +28 -0
  114. package/src/site/ui.ts +49 -0
  115. package/src/site/urls.ts +14 -0
  116. package/src/site/virtual.ts +42 -0
  117. package/src/styles.css +5 -0
@@ -0,0 +1,149 @@
1
+ import type { Locale } from './locales.ts'
2
+ import { existsSync } from 'node:fs'
3
+ import { createRequire } from 'node:module'
4
+ import { join } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { z } from 'astro/zod'
7
+ import { inferDescription, type RepoInfo } from './infer.ts'
8
+ import { PRESETS, PRESET_NAMES, isPreset } from './themes.ts'
9
+
10
+ const publicUrl = (field: string, example: string) =>
11
+ z.string().refine((v) => v.startsWith('/') || /^https?:\/\//.test(v), {
12
+ message: `${field} must be a public url, such as "${example}"`,
13
+ })
14
+
15
+ /** The options of the site around the pages: identity, header, footer, head and theme. */
16
+ export const siteConfigShape = {
17
+ title: z.string(),
18
+ description: z.string().optional(),
19
+ lang: z.string().default('en'),
20
+ logo: publicUrl('logo', '/logo.svg').optional(),
21
+ /** Where the site name in the header leads: the site root, or another site. */
22
+ homeLink: z.string().default('/'),
23
+
24
+ social: z
25
+ .record(
26
+ z.string(),
27
+ z.union([
28
+ z.string(),
29
+ z.object({
30
+ href: z.string(),
31
+ label: z.string().optional(),
32
+ svg: z.string().optional(),
33
+ }),
34
+ ]),
35
+ )
36
+ .default({}),
37
+ nav: z.array(z.object({ label: z.string(), href: z.string() })).default([]),
38
+ footer: z
39
+ .union([z.string(), z.literal(false)], {
40
+ error:
41
+ 'footer is one line of text, or false to remove it. ' +
42
+ 'The message/copyright pair is gone: write them as a single string, ' +
43
+ 'e.g. "MIT Licensed · © 2026 Me · :credit".',
44
+ })
45
+ .optional(),
46
+
47
+ head: z
48
+ .array(
49
+ z.object({
50
+ tag: z.string(),
51
+ attrs: z.record(z.string(), z.union([z.string(), z.boolean()])).optional(),
52
+ content: z.string().optional(),
53
+ }),
54
+ )
55
+ .default([]),
56
+ ogImage: z.union([publicUrl('ogImage', '/og-image.png'), z.literal(false)]).optional(),
57
+
58
+ theme: z
59
+ .union([
60
+ z.string().refine(isPreset, {
61
+ message: `unknown theme; available: ${PRESET_NAMES.join(', ')}`,
62
+ }),
63
+ z.object({ light: z.string(), dark: z.string() }),
64
+ ])
65
+ .default('default'),
66
+
67
+ appearance: z
68
+ .enum(['auto', 'light', 'dark'], {
69
+ error: 'unknown appearance; available: auto, light, dark',
70
+ })
71
+ .default('auto'),
72
+
73
+ /** Registers Tailwind (the site's own install) and exposes JAAD's tokens to it. */
74
+ tailwind: z.boolean().default(false),
75
+
76
+ /** Per-locale overrides for JAAD's bundled interface strings. */
77
+ ui: z.record(z.string(), z.record(z.string(), z.string())).default({}),
78
+ }
79
+
80
+ const siteConfigSchema = z.object(siteConfigShape)
81
+
82
+ export type SiteConfig = z.output<typeof siteConfigSchema>
83
+
84
+ /** The site options plus what the project could tell. Inferred fields are null
85
+ * when unavailable. */
86
+ export interface SiteResolvedConfig extends SiteConfig {
87
+ /** What jaamd gets for code blocks. */
88
+ shiki: string | { light: string; dark: string }
89
+ repoUrl: string | null
90
+ favicon: string | null
91
+ /** Explicit, inferred from public/, or false when no valid image exists. */
92
+ ogImage: string | false
93
+ /** Empty when the site is not localised. */
94
+ locales: Locale[]
95
+ /** `lang` when the site is not localised. */
96
+ defaultLocale: string
97
+ }
98
+
99
+ const FAVICONS = ['favicon.svg', 'favicon.ico', 'favicon.png']
100
+ const OG_IMAGES = ['og-image.png', 'og-image.jpg', 'og-image.jpeg', 'og-image.webp']
101
+
102
+ function findPublicAsset(cwd: string, candidates: string[]): string | null {
103
+ for (const name of candidates) {
104
+ if (existsSync(join(cwd, 'public', name))) return `/${name}`
105
+ }
106
+ return null
107
+ }
108
+
109
+ /** The fields the site derives from its options and the project. */
110
+ export function resolveSiteConfig(
111
+ config: SiteConfig,
112
+ repo: RepoInfo | null,
113
+ cwd: string,
114
+ ): Pick<SiteResolvedConfig, 'description' | 'repoUrl' | 'favicon' | 'ogImage' | 'shiki'> {
115
+ return {
116
+ description: config.description ?? inferDescription(cwd) ?? undefined,
117
+ repoUrl: repo?.url ?? null,
118
+ favicon: findPublicAsset(cwd, FAVICONS),
119
+ ogImage: config.ogImage ?? findPublicAsset(cwd, OG_IMAGES) ?? false,
120
+ shiki: typeof config.theme === 'string' ? PRESETS[config.theme].shiki : config.theme,
121
+ }
122
+ }
123
+
124
+ const requireFrom = createRequire(import.meta.url)
125
+
126
+ const styleInPackage = (name: string) => fileURLToPath(new URL(`./styles/${name}`, import.meta.url))
127
+
128
+ /** Absolute paths, kept off the resolved config, which gets serialised. */
129
+ export function resolveStylesheets(
130
+ config: SiteConfig,
131
+ cwd: string = process.cwd(),
132
+ ): {
133
+ user: string | null
134
+ theme: string | null
135
+ bridge: string
136
+ tailwind: string | null
137
+ } {
138
+ const userCss = join(cwd, 'src', 'jaad.css')
139
+ const slug = typeof config.theme === 'string' ? PRESETS[config.theme].theme : null
140
+
141
+ return {
142
+ user: existsSync(userCss) ? userCss : null,
143
+ // Resolved through JAAMD's export map rather than by path.
144
+ theme: slug ? requireFrom.resolve(`@jaamd/astro/themes/${slug}.css`) : null,
145
+ // A preset supplies the palette, so the colours travel the other way.
146
+ bridge: styleInPackage(slug ? 'jaamd-reverse.css' : 'jaamd-forward.css'),
147
+ tailwind: config.tailwind ? styleInPackage('tailwind.css') : null,
148
+ }
149
+ }
@@ -0,0 +1,94 @@
1
+ Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)
2
+ Copyright 2020 The Merriweather Project Authors (https://github.com/EbenSorkin/Merriweather4) with Reserved Font Name "Merriweather".
3
+
4
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
5
+ This license is copied below, and is also available with a FAQ at:
6
+ https://scripts.sil.org/OFL
7
+
8
+
9
+ -----------------------------------------------------------
10
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
11
+ -----------------------------------------------------------
12
+
13
+ PREAMBLE
14
+ The goals of the Open Font License (OFL) are to stimulate worldwide
15
+ development of collaborative font projects, to support the font creation
16
+ efforts of academic and linguistic communities, and to provide a free and
17
+ open framework in which fonts may be shared and improved in partnership
18
+ with others.
19
+
20
+ The OFL allows the licensed fonts to be used, studied, modified and
21
+ redistributed freely as long as they are not sold by themselves. The
22
+ fonts, including any derivative works, can be bundled, embedded,
23
+ redistributed and/or sold with any software provided that any reserved
24
+ names are not used by derivative works. The fonts and derivatives,
25
+ however, cannot be released under any other type of license. The
26
+ requirement for fonts to remain under this license does not apply
27
+ to any document created using the fonts or their derivatives.
28
+
29
+ DEFINITIONS
30
+ "Font Software" refers to the set of files released by the Copyright
31
+ Holder(s) under this license and clearly marked as such. This may
32
+ include source files, build scripts and documentation.
33
+
34
+ "Reserved Font Name" refers to any names specified as such after the
35
+ copyright statement(s).
36
+
37
+ "Original Version" refers to the collection of Font Software components as
38
+ distributed by the Copyright Holder(s).
39
+
40
+ "Modified Version" refers to any derivative made by adding to, deleting,
41
+ or substituting -- in part or in whole -- any of the components of the
42
+ Original Version, by changing formats or by porting the Font Software to a
43
+ new environment.
44
+
45
+ "Author" refers to any designer, engineer, programmer, technical
46
+ writer or other person who contributed to the Font Software.
47
+
48
+ PERMISSION & CONDITIONS
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
51
+ redistribute, and sell modified and unmodified copies of the Font
52
+ Software, subject to the following conditions:
53
+
54
+ 1) Neither the Font Software nor any of its individual components,
55
+ in Original or Modified Versions, may be sold by itself.
56
+
57
+ 2) Original or Modified Versions of the Font Software may be bundled,
58
+ redistributed and/or sold with any software, provided that each copy
59
+ contains the above copyright notice and this license. These can be
60
+ included either as stand-alone text files, human-readable headers or
61
+ in the appropriate machine-readable metadata fields within text or
62
+ binary files as long as those fields can be easily viewed by the user.
63
+
64
+ 3) No Modified Version of the Font Software may use the Reserved Font
65
+ Name(s) unless explicit written permission is granted by the corresponding
66
+ Copyright Holder. This restriction only applies to the primary font name as
67
+ presented to the users.
68
+
69
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
70
+ Software shall not be used to promote, endorse or advertise any
71
+ Modified Version, except to acknowledge the contribution(s) of the
72
+ Copyright Holder(s) and the Author(s) or with their explicit written
73
+ permission.
74
+
75
+ 5) The Font Software, modified or unmodified, in part or in whole,
76
+ must be distributed entirely under this license, and must not be
77
+ distributed under any other license. The requirement for fonts to
78
+ remain under this license does not apply to any document created
79
+ using the Font Software.
80
+
81
+ TERMINATION
82
+ This license becomes null and void if any of the above conditions are
83
+ not met.
84
+
85
+ DISCLAIMER
86
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
88
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
89
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
90
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
91
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
92
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
94
+ OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file
@@ -0,0 +1,29 @@
1
+ import { fontProviders } from 'astro/config'
2
+
3
+ const file = (name: string) => new URL(`./fonts/${name}.woff2`, import.meta.url)
4
+
5
+ export const fonts = [
6
+ {
7
+ provider: fontProviders.local(),
8
+ name: 'Inter',
9
+ cssVariable: '--font-inter',
10
+ options: {
11
+ variants: [{ weight: '400 600', style: 'normal', src: [file('inter')] }],
12
+ },
13
+ },
14
+ {
15
+ provider: fontProviders.local(),
16
+ name: 'Merriweather',
17
+ cssVariable: '--font-merriweather',
18
+ options: {
19
+ variants: [
20
+ { weight: '300 700', style: 'normal', src: [file('merriweather')] },
21
+ {
22
+ weight: '300 700',
23
+ style: 'italic',
24
+ src: [file('merriweather-italic')],
25
+ },
26
+ ],
27
+ },
28
+ },
29
+ ]
@@ -0,0 +1,60 @@
1
+ // Icon paths from simple-icons (CC0-1.0). Only git forges are bundled: they
2
+ // are what the repository link inferred from the git remote needs.
3
+
4
+ interface Forge {
5
+ label: string
6
+ /** Single 24×24 filled path. */
7
+ path: string
8
+ /** Host that identifies this forge in a git remote, when unambiguous. */
9
+ host: string | null
10
+ }
11
+
12
+ export const FORGES: Record<string, Forge> = {
13
+ github: {
14
+ label: 'GitHub',
15
+ host: 'github.com',
16
+ path: 'M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12',
17
+ },
18
+ gitlab: {
19
+ label: 'GitLab',
20
+ host: 'gitlab.com',
21
+ path: 'm23.6004 9.5927-.0337-.0862L20.3.9814a.851.851 0 0 0-.3362-.405.8748.8748 0 0 0-.9997.0539.8748.8748 0 0 0-.29.4399l-2.2055 6.748H7.5375l-2.2057-6.748a.8573.8573 0 0 0-.29-.4412.8748.8748 0 0 0-.9997-.0537.8585.8585 0 0 0-.3362.4049L.4332 9.5015l-.0325.0862a6.0657 6.0657 0 0 0 2.0119 7.0105l.0113.0087.03.0213 4.976 3.7264 2.462 1.8633 1.4995 1.1321a1.0085 1.0085 0 0 0 1.2197 0l1.4995-1.1321 2.4619-1.8633 5.006-3.7489.0125-.01a6.0682 6.0682 0 0 0 2.0094-7.003z',
22
+ },
23
+ codeberg: {
24
+ label: 'Codeberg',
25
+ host: 'codeberg.org',
26
+ path: 'M11.999.747A11.974 11.974 0 0 0 0 12.75c0 2.254.635 4.465 1.833 6.376L11.837 6.19c.072-.092.251-.092.323 0l4.178 5.402h-2.992l.065.239h3.113l.882 1.138h-3.674l.103.374h3.86l.777 1.003h-4.358l.135.483h4.593l.695.894h-5.038l.165.589h5.326l.609.785h-5.717l.182.65h6.038l.562.727h-6.397l.183.65h6.717A12.003 12.003 0 0 0 24 12.75 11.977 11.977 0 0 0 11.999.747zm3.654 19.104.182.65h5.326c.173-.204.353-.433.513-.65zm.385 1.377.18.65h3.563c.233-.198.485-.428.712-.65zm.383 1.377.182.648h1.203c.356-.204.685-.412 1.042-.648z',
27
+ },
28
+ gitea: {
29
+ label: 'Gitea',
30
+ host: 'gitea.com',
31
+ path: 'M4.209 4.603c-.247 0-.525.02-.84.088-.333.07-1.28.283-2.054 1.027C-.403 7.25.035 9.685.089 10.052c.065.446.263 1.687 1.21 2.768 1.749 2.141 5.513 2.092 5.513 2.092s.462 1.103 1.168 2.119c.955 1.263 1.936 2.248 2.89 2.367 2.406 0 7.212-.004 7.212-.004s.458.004 1.08-.394c.535-.324 1.013-.893 1.013-.893s.492-.527 1.18-1.73c.21-.37.385-.729.538-1.068 0 0 2.107-4.471 2.107-8.823-.042-1.318-.367-1.55-.443-1.627-.156-.156-.366-.153-.366-.153s-4.475.252-6.792.306c-.508.011-1.012.023-1.512.027v4.474l-.634-.301c0-1.39-.004-4.17-.004-4.17-1.107.016-3.405-.084-3.405-.084s-5.399-.27-5.987-.324c-.187-.011-.401-.032-.648-.032zm.354 1.832h.111s.271 2.269.6 3.597C5.549 11.147 6.22 13 6.22 13s-.996-.119-1.641-.348c-.99-.324-1.409-.714-1.409-.714s-.73-.511-1.096-1.52C1.444 8.73 2.021 7.7 2.021 7.7s.32-.859 1.47-1.145c.395-.106.863-.12 1.072-.12zm8.33 2.554c.26.003.509.127.509.127l.868.422-.529 1.075a.686.686 0 0 0-.614.359.685.685 0 0 0 .072.756l-.939 1.924a.69.69 0 0 0-.66.527.687.687 0 0 0 .347.763.686.686 0 0 0 .867-.206.688.688 0 0 0-.069-.882l.916-1.874a.667.667 0 0 0 .237-.02.657.657 0 0 0 .271-.137 8.826 8.826 0 0 1 1.016.512.761.761 0 0 1 .286.282c.073.21-.073.569-.073.569-.087.29-.702 1.55-.702 1.55a.692.692 0 0 0-.676.477.681.681 0 1 0 1.157-.252c.073-.141.141-.282.214-.431.19-.397.515-1.16.515-1.16.035-.066.218-.394.103-.814-.095-.435-.48-.638-.48-.638-.467-.301-1.116-.58-1.116-.58s0-.156-.042-.27a.688.688 0 0 0-.148-.241l.516-1.062 2.89 1.401s.48.218.583.619c.073.282-.019.534-.069.657-.24.587-2.1 4.317-2.1 4.317s-.232.554-.748.588a1.065 1.065 0 0 1-.393-.045l-.202-.08-4.31-2.1s-.417-.218-.49-.596c-.083-.31.104-.691.104-.691l2.073-4.272s.183-.37.466-.497a.855.855 0 0 1 .35-.077z',
32
+ },
33
+ forgejo: {
34
+ label: 'Forgejo',
35
+ host: null,
36
+ path: 'M16.7773 0c1.6018 0 2.9004 1.2986 2.9004 2.9005s-1.2986 2.9004-2.9004 2.9004c-1.0854 0-2.0315-.596-2.5288-1.4787H12.91c-2.3322 0-4.2272 1.8718-4.2649 4.195l-.0007 2.1175a7.0759 7.0759 0 0 1 4.148-1.4205l.1176-.001 1.3385.0002c.4973-.8827 1.4434-1.4788 2.5288-1.4788 1.6018 0 2.9004 1.2986 2.9004 2.9005s-1.2986 2.9004-2.9004 2.9004c-1.0854 0-2.0315-.596-2.5288-1.4787H12.91c-2.3322 0-4.2272 1.8718-4.2649 4.195l-.0007 2.319c.8827.4973 1.4788 1.4434 1.4788 2.5287 0 1.602-1.2986 2.9005-2.9005 2.9005-1.6018 0-2.9004-1.2986-2.9004-2.9005 0-1.0853.596-2.0314 1.4788-2.5287l-.0002-9.9831c0-3.887 3.1195-7.0453 6.9915-7.108l.1176-.001h1.3385C14.7458.5962 15.692 0 16.7773 0ZM7.2227 19.9052c-.6596 0-1.1943.5347-1.1943 1.1943s.5347 1.1943 1.1943 1.1943 1.1944-.5347 1.1944-1.1943-.5348-1.1943-1.1944-1.1943Zm9.5546-10.4644c-.6596 0-1.1944.5347-1.1944 1.1943s.5348 1.1943 1.1944 1.1943c.6596 0 1.1943-.5347 1.1943-1.1943s-.5347-1.1943-1.1943-1.1943Zm0-7.7346c-.6596 0-1.1944.5347-1.1944 1.1943s.5348 1.1943 1.1944 1.1943c.6596 0 1.1943-.5347 1.1943-1.1943s-.5347-1.1943-1.1943-1.1943Z',
37
+ },
38
+ bitbucket: {
39
+ label: 'Bitbucket',
40
+ host: 'bitbucket.org',
41
+ path: 'M.778 1.213a.768.768 0 00-.768.892l3.263 19.81c.084.5.515.868 1.022.873H19.95a.772.772 0 00.77-.646l3.27-20.03a.768.768 0 00-.768-.891zM14.52 15.53H9.522L8.17 8.466h7.561z',
42
+ },
43
+ sourcehut: {
44
+ label: 'SourceHut',
45
+ host: 'sr.ht',
46
+ path: 'M12 0C5.371 0 0 5.371 0 12s5.371 12 12 12 12-5.371 12-12S18.629 0 12 0Zm0 21.677A9.675 9.675 0 0 1 2.323 12 9.675 9.675 0 0 1 12 2.323 9.675 9.675 0 0 1 21.677 12 9.675 9.675 0 0 1 12 21.677Z',
47
+ },
48
+ }
49
+
50
+ /** Matches a repository URL to a bundled forge icon, if we recognise the host. */
51
+ export function forgeForUrl(url: string): string | null {
52
+ const host = url.match(/^https?:\/\/([^/]+)/)?.[1]
53
+ if (!host) return null
54
+ for (const [name, forge] of Object.entries(FORGES)) {
55
+ if (forge.host && (host === forge.host || host.endsWith('.' + forge.host))) {
56
+ return name
57
+ }
58
+ }
59
+ return null
60
+ }
@@ -0,0 +1,4 @@
1
+ export function ucfirst(str: string): string {
2
+ if (str.length === 0) return str
3
+ return str.charAt(0).toUpperCase() + str.slice(1)
4
+ }
@@ -0,0 +1,75 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import { readFileSync } from 'node:fs'
3
+ import { join, posix } from 'node:path'
4
+
5
+ const git = (args: string[], cwd: string): string | null => {
6
+ try {
7
+ return execFileSync('git', args, {
8
+ cwd,
9
+ encoding: 'utf8',
10
+ stdio: ['ignore', 'pipe', 'ignore'],
11
+ }).trim()
12
+ } catch {
13
+ return null
14
+ }
15
+ }
16
+
17
+ /** `git@host:owner/repo.git` and `https://host/owner/repo.git` both become
18
+ * `https://host/owner/repo`. */
19
+ export function normaliseRemote(remote: string): string | null {
20
+ const ssh = remote.match(/^[\w.-]+@([\w.-]+):(.+?)(?:\.git)?$/)
21
+ if (ssh) return `https://${ssh[1]}/${ssh[2]}`
22
+
23
+ const https = remote.match(/^https?:\/\/(?:[^@/]+@)?([\w.-]+)\/(.+?)(?:\.git)?$/)
24
+ if (https) return `https://${https[1]}/${https[2]}`
25
+
26
+ return null
27
+ }
28
+
29
+ export interface RepoInfo {
30
+ /** Browsable base, e.g. https://github.com/owner/repo */
31
+ url: string
32
+ branch: string
33
+ /** Path from the repository root to the Astro project, "" at the root. */
34
+ prefix: string
35
+ }
36
+
37
+ /** Returns null outside a repository, in a tarball, or without an origin. */
38
+ export function inferRepo(cwd: string = process.cwd()): RepoInfo | null {
39
+ const remote = git(['remote', 'get-url', 'origin'], cwd)
40
+ if (!remote) return null
41
+
42
+ const url = normaliseRemote(remote)
43
+ if (!url) return null
44
+
45
+ return {
46
+ url,
47
+ branch: git(['rev-parse', '--abbrev-ref', 'HEAD'], cwd) || 'main',
48
+ prefix: git(['rev-parse', '--show-prefix'], cwd) ?? '',
49
+ }
50
+ }
51
+
52
+ /** Ends in a slash. `docsDir` resolves against the repository root, not the
53
+ * Astro project, so a site in a subdirectory still links correctly. */
54
+ export function editBaseFrom(repo: RepoInfo, docsDir: string): string {
55
+ // Normalised: a section can sit outside the project, as `../packages/x/docs`.
56
+ const path = posix.normalize(`${repo.prefix}${docsDir}`).replace(/^\/+|\/+$/g, '')
57
+ return `${repo.url}/edit/${repo.branch}/${path}/`
58
+ }
59
+
60
+ /** `:path` is substituted when present, otherwise the file is appended. */
61
+ export function editUrl(base: string, filePath: string): string {
62
+ return base.includes(':path') ? base.replace(':path', filePath) : base.replace(/\/?$/, '/') + filePath
63
+ }
64
+
65
+ export function inferDescription(cwd: string = process.cwd()): string | null {
66
+ try {
67
+ const pkg = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8')) as {
68
+ description?: unknown
69
+ }
70
+
71
+ return typeof pkg.description === 'string' && pkg.description ? pkg.description : null
72
+ } catch {
73
+ return null
74
+ }
75
+ }
@@ -0,0 +1,59 @@
1
+ import type { SiteResolvedConfig } from './config.ts'
2
+ import type { SiteStylesheets } from './virtual.ts'
3
+ import type { AstroIntegration, AstroUserConfig } from 'astro'
4
+ import { createRequire } from 'node:module'
5
+ import { join } from 'node:path'
6
+ import { fileURLToPath } from 'node:url'
7
+ import { fonts } from './fonts.ts'
8
+ import { siteVirtualPlugin } from './virtual.ts'
9
+
10
+ type SetupParams = Parameters<NonNullable<AstroIntegration['hooks']['astro:config:setup']>>[0]
11
+ type VitePlugins = NonNullable<NonNullable<AstroUserConfig['vite']>['plugins']>
12
+
13
+ const NOT_INSTALLED = new Set(['MODULE_NOT_FOUND', 'ERR_PACKAGE_PATH_NOT_EXPORTED'])
14
+
15
+ /** The site's own `@tailwindcss/vite`, unless it already registered one. */
16
+ export function loadTailwindPlugin(root: string, registered: VitePlugins | undefined): VitePlugins {
17
+ const plugins = ([registered] as unknown[]).flat(Infinity) as ({
18
+ name?: string
19
+ } | null)[]
20
+ if (plugins.some((p) => p?.name?.startsWith('@tailwindcss/vite'))) return []
21
+
22
+ const load = createRequire(join(root, 'package.json'))
23
+ let tailwindcss: () => VitePlugins
24
+ try {
25
+ load.resolve('tailwindcss/package.json')
26
+ ;({ default: tailwindcss } = load('@tailwindcss/vite') as {
27
+ default: () => VitePlugins
28
+ })
29
+ } catch (error) {
30
+ if (!NOT_INSTALLED.has((error as { code?: string }).code ?? '')) throw error
31
+ throw new Error(
32
+ 'jaad: `tailwind: true` needs Tailwind in your project:\n npm i -D tailwindcss @tailwindcss/vite',
33
+ { cause: error },
34
+ )
35
+ }
36
+ return tailwindcss()
37
+ }
38
+
39
+ /** The virtual modules, Tailwind when asked for, and the fonts. `config` is
40
+ * what `virtual:jaad/config` serves. */
41
+ export function setupSite(
42
+ { config: astroConfig, updateConfig }: SetupParams,
43
+ config: SiteResolvedConfig,
44
+ stylesheets: SiteStylesheets,
45
+ ): void {
46
+ updateConfig({
47
+ vite: {
48
+ plugins: [
49
+ siteVirtualPlugin(config, stylesheets),
50
+ ...(config.tailwind
51
+ ? [loadTailwindPlugin(fileURLToPath(astroConfig.root), astroConfig.vite.plugins)]
52
+ : []),
53
+ ],
54
+ // Package .astro sources must reach the Astro compiler.
55
+ ssr: { noExternal: ['@jaamd/jaad'] },
56
+ },
57
+ fonts,
58
+ })
59
+ }
@@ -0,0 +1,41 @@
1
+ ---
2
+ import type { ComponentProps } from 'astro/types'
3
+ import config from 'virtual:jaad/config'
4
+ import Footer from '../components/Footer.astro'
5
+ import Head from '../components/Head.astro'
6
+ import Header from '../components/Header.astro'
7
+ import '../../../dist/jaad.css'
8
+ import 'virtual:jaad/theme.css'
9
+ import 'virtual:jaad/bridge.css'
10
+ import 'virtual:jaad/user.css'
11
+ import 'virtual:jaad/tailwind.css'
12
+
13
+ interface Props {
14
+ title?: string
15
+ description?: string
16
+ bare?: boolean
17
+ /** Added to the body. */
18
+ class?: string
19
+ /** What the header offers: translations and search. */
20
+ header: ComponentProps<typeof Header>
21
+ }
22
+
23
+ const { title, description, bare = false, class: className, header } = Astro.props
24
+
25
+ const pageTitle = title ? `${title} | ${config.title}` : config.title
26
+ const pageDescription = description ?? config.description ?? config.title
27
+ ---
28
+
29
+ <!doctype html>
30
+ <html lang={config.lang} class={config.appearance === 'dark' ? 'dark' : undefined}>
31
+ <head>
32
+ <Head title={pageTitle} description={pageDescription} />
33
+ </head>
34
+ <body class:list={['jaad-body', className]}>
35
+ <Header {...header} />
36
+ <main class={bare ? 'jaad-main-bare' : 'jaad-main'}>
37
+ <slot />
38
+ </main>
39
+ <Footer />
40
+ </body>
41
+ </html>