uniweb 0.2.31 → 0.2.34

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
@@ -324,7 +324,7 @@ my-project/
324
324
  └── src/
325
325
  ├── styles.css # Tailwind CSS v4
326
326
  ├── meta.js # Foundation metadata
327
- ├── runtime.js # (optional) Custom Layout, props
327
+ ├── exports.js # (optional) Custom Layout, props
328
328
  └── components/
329
329
  └── Section/
330
330
  ├── index.jsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uniweb",
3
- "version": "0.2.31",
3
+ "version": "0.2.34",
4
4
  "description": "Create structured Vite + React sites with content/code separation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -36,9 +36,9 @@
36
36
  "js-yaml": "^4.1.0",
37
37
  "prompts": "^2.4.2",
38
38
  "tar": "^7.0.0",
39
- "@uniweb/build": "0.1.15",
40
- "@uniweb/core": "0.1.7",
39
+ "@uniweb/build": "0.1.19",
40
+ "@uniweb/core": "0.1.8",
41
41
  "@uniweb/kit": "0.1.4",
42
- "@uniweb/runtime": "0.2.8"
42
+ "@uniweb/runtime": "0.2.10"
43
43
  }
44
44
  }
@@ -279,6 +279,46 @@ async function generateLocalizedHtml(projectDir, i18nConfig) {
279
279
  }
280
280
  }
281
281
 
282
+ /**
283
+ * Resolve foundation directory based on site config and project structure
284
+ *
285
+ * For single projects: ../foundation
286
+ * For multi projects: ../../foundations/{name}
287
+ */
288
+ function resolveFoundationDir(projectDir, siteConfig) {
289
+ const foundationName = siteConfig?.foundation
290
+
291
+ // Check if we're in a multi-site structure (site is under sites/)
292
+ const parentDir = join(projectDir, '..')
293
+ const grandParentDir = join(projectDir, '..', '..')
294
+ const isMultiSite = parentDir.endsWith('/sites') || parentDir.endsWith('\\sites')
295
+
296
+ if (isMultiSite && foundationName) {
297
+ // Multi-site: look for foundations/{name}
298
+ const multiFoundationDir = join(grandParentDir, 'foundations', foundationName)
299
+ if (existsSync(multiFoundationDir)) {
300
+ return multiFoundationDir
301
+ }
302
+ }
303
+
304
+ // Single site: ../foundation
305
+ const singleFoundationDir = join(projectDir, '..', 'foundation')
306
+ if (existsSync(singleFoundationDir)) {
307
+ return singleFoundationDir
308
+ }
309
+
310
+ // Fallback: try to find by foundation name in parent
311
+ if (foundationName) {
312
+ const namedFoundationDir = join(parentDir, foundationName)
313
+ if (existsSync(namedFoundationDir)) {
314
+ return namedFoundationDir
315
+ }
316
+ }
317
+
318
+ // Ultimate fallback
319
+ return singleFoundationDir
320
+ }
321
+
282
322
  /**
283
323
  * Build a site
284
324
  */
@@ -330,7 +370,7 @@ async function buildSite(projectDir, options = {}) {
330
370
  const { prerenderSite } = await import('@uniweb/build/prerender')
331
371
 
332
372
  const result = await prerenderSite(projectDir, {
333
- foundationDir: foundationDir || join(projectDir, '..', 'foundation'),
373
+ foundationDir: foundationDir || resolveFoundationDir(projectDir, siteConfig),
334
374
  onProgress: (msg) => log(` ${colors.dim}${msg}${colors.reset}`)
335
375
  })
336
376
 
@@ -58,7 +58,7 @@ export function clearMissingVersions() {
58
58
  function registerPartials() {
59
59
  if (partialsRegistered) return
60
60
 
61
- const partialsDir = path.join(__dirname, '..', 'partials')
61
+ const partialsDir = path.join(__dirname, '..', '..', 'partials')
62
62
 
63
63
  if (!existsSync(partialsDir)) {
64
64
  partialsRegistered = true
@@ -1,148 +1 @@
1
- # CLAUDE.md - AI Assistant Instructions
2
-
3
- This file provides guidance for AI assistants working with this Uniweb project.
4
-
5
- ## Project Overview
6
-
7
- This is a **Uniweb** project - a component web platform that separates content from code.
8
-
9
- ```
10
- {{projectName}}/
11
- ├── foundation/ # React component library (code)
12
- ├── site/ # Content and pages (markdown)
13
- ├── package.json # Root workspace config
14
- └── pnpm-workspace.yaml
15
- ```
16
-
17
- ## Quick Commands
18
-
19
- ```bash
20
- # Install dependencies
21
- pnpm install
22
-
23
- # Start development server (site with foundation)
24
- pnpm dev
25
-
26
- # Build foundation (generates dist/foundation.js and schema.json)
27
- cd foundation && pnpm build
28
-
29
- # Build site for production (outputs to site/dist/)
30
- cd site && pnpm build
31
- ```
32
-
33
- ## Key Files
34
-
35
- **Site:**
36
- - `site/vite.config.js` - 3-line config using `defineSiteConfig()` from `@uniweb/build/site`
37
- - `site/main.js` - Entry point using `start()` from `@uniweb/runtime`
38
- - `site/site.yml` - Site configuration (foundation path, title, i18n)
39
- - `site/pages/` - Content pages (file-based routing)
40
-
41
- **Foundation:**
42
- - `foundation/vite.config.js` - 3-line config using `defineFoundationConfig()` from `@uniweb/build`
43
- - `foundation/src/styles.css` - Tailwind CSS v4 theme
44
- - `foundation/src/components/*/meta.js` - Component metadata (makes component exposed)
45
- - `foundation/src/runtime.js` - (optional) Custom Layout and foundation props
46
- - `foundation/src/_entry.generated.js` - Auto-generated at build/dev time
47
-
48
- ## Architecture
49
-
50
- ### Foundation Package (`/foundation`)
51
-
52
- The **foundation** is a React component library. Components with a `meta.js` file are **exposed** (available to content creators via `type:` in frontmatter). Exposed components:
53
-
54
- 1. Receive structured content parsed from markdown
55
- 2. Have configurable parameters (theme, layout, etc.)
56
- 3. Render content according to their design
57
-
58
- Internal components (no `meta.js`) are regular React components used within exposed components.
59
-
60
- **Key directories:**
61
- - `src/components/*/` - Component implementations
62
- - `src/components/*/meta.js` - Component metadata (makes component exposed)
63
- - `src/styles.css` - Global Tailwind styles
64
-
65
- ### Site Package (`/site`)
66
-
67
- The **site** contains content written in markdown. The runtime loads the foundation and renders content based on component selections.
68
-
69
- **Key directories:**
70
- - `pages/` - Content pages organized in folders
71
- - `pages/[page-name]/page.yml` - Page metadata
72
- - `pages/[page-name]/*.md` - Content sections
73
-
74
- ## Content Authoring
75
-
76
- ### Section File Format
77
-
78
- ```markdown
79
- ---
80
- type: ComponentName
81
- theme: dark
82
- layout: center
83
- ---
84
-
85
- # Main Headline
86
-
87
- Description paragraph.
88
-
89
- [Call to Action](#link)
90
- ```
91
-
92
- ### Content Structure
93
-
94
- The semantic parser extracts content into:
95
-
96
- - **`content.main.header`**: title, pretitle, subtitle
97
- - **`content.main.body`**: paragraphs, links, imgs, lists
98
- - **`content.items`**: Content groups from H3 headings
99
-
100
- ## Component Development
101
-
102
- ### Component Interface
103
-
104
- ```jsx
105
- function MyComponent({ content, params, block, website }) {
106
- const { title } = content.main?.header || {}
107
- const { paragraphs = [] } = content.main?.body || {}
108
- // ...
109
- }
110
- ```
111
-
112
- ### Using @uniweb/kit
113
-
114
- ```jsx
115
- import { H1, P, Link, cn } from '@uniweb/kit'
116
- ```
117
-
118
- ### Component Metadata (`meta.js`)
119
-
120
- ```javascript
121
- export default {
122
- title: 'Component Name',
123
- description: 'What the component does',
124
- category: 'Content',
125
- elements: { /* content elements */ },
126
- properties: { /* configurable params */ },
127
- }
128
- ```
129
-
130
- ## Tailwind CSS v4
131
-
132
- This project uses Tailwind CSS v4 with the Vite plugin.
133
-
134
- **Theme customization** (`foundation/src/styles.css`):
135
-
136
- ```css
137
- @import "tailwindcss";
138
- @source "./components/**/*.{js,jsx}";
139
- @theme {
140
- --color-primary: #3b82f6;
141
- }
142
- ```
143
-
144
- ## Resources
145
-
146
- - [Uniweb Documentation](https://github.com/uniweb/uniweb)
147
- - [@uniweb/kit Documentation](https://www.npmjs.com/package/@uniweb/kit)
148
- - [Tailwind CSS v4](https://tailwindcss.com/docs)
1
+ {{> claude-md}}
@@ -1,100 +1 @@
1
- # CLAUDE.md - AI Assistant Instructions
2
-
3
- This file provides guidance for AI assistants working with this Uniweb multi-site workspace.
4
-
5
- ## Project Overview
6
-
7
- This is a **Uniweb multi-site workspace** - supporting multiple sites and foundations.
8
-
9
- ```
10
- {{projectName}}/
11
- ├── foundations/ # Shared component libraries
12
- │ └── default/ # Default foundation
13
- ├── sites/ # Content sites
14
- │ └── main/ # Main site
15
- ├── package.json # Root workspace config
16
- └── pnpm-workspace.yaml
17
- ```
18
-
19
- ## Quick Commands
20
-
21
- ```bash
22
- # Install dependencies
23
- pnpm install
24
-
25
- # Start main site development
26
- pnpm dev
27
-
28
- # Start all sites in parallel
29
- pnpm dev:all
30
-
31
- # Build main site
32
- pnpm build
33
-
34
- # Build all sites
35
- pnpm build:all
36
- ```
37
-
38
- ## Adding New Sites
39
-
40
- 1. Copy an existing site directory:
41
- ```bash
42
- cp -r sites/main sites/newsite
43
- ```
44
-
45
- 2. Update `sites/newsite/package.json` with a unique name
46
-
47
- 3. Update `sites/newsite/site.yml` with site configuration
48
-
49
- 4. Run `pnpm install` to link the new site
50
-
51
- ## Adding New Foundations
52
-
53
- 1. Copy an existing foundation:
54
- ```bash
55
- cp -r foundations/default foundations/newfoundation
56
- ```
57
-
58
- 2. Update `foundations/newfoundation/package.json` with a unique name
59
-
60
- 3. In your site's `site.yml`, reference the foundation:
61
- ```yaml
62
- foundation: newfoundation
63
- ```
64
-
65
- 4. In your site's `package.json`, add the dependency:
66
- ```json
67
- "dependencies": {
68
- "newfoundation": "file:../../foundations/newfoundation"
69
- }
70
- ```
71
-
72
- ## Key Files
73
-
74
- **Sites:**
75
- - `sites/*/vite.config.js` - 3-line config using `defineSiteConfig()` from `@uniweb/build/site`
76
- - `sites/*/main.js` - Entry point using `start()` from `@uniweb/runtime`
77
- - `sites/*/site.yml` - Site configuration (foundation reference, title, i18n)
78
- - `sites/*/pages/` - Content pages (file-based routing)
79
-
80
- **Foundations:**
81
- - `foundations/*/vite.config.js` - 3-line config using `defineFoundationConfig()` from `@uniweb/build`
82
- - `foundations/*/src/styles.css` - Tailwind CSS v4 theme
83
- - `foundations/*/src/components/*/meta.js` - Component metadata (makes component exposed)
84
- - `foundations/*/src/runtime.js` - (optional) Custom Layout and foundation props
85
-
86
- ## Architecture
87
-
88
- ### Foundations (`/foundations/*`)
89
-
90
- Each foundation is a React component library. Sites can share foundations or have their own.
91
-
92
- ### Sites (`/sites/*`)
93
-
94
- Each site contains content in markdown. A site references one foundation for its components.
95
-
96
- ## Resources
97
-
98
- - [Uniweb Documentation](https://github.com/uniweb/uniweb)
99
- - [@uniweb/kit Documentation](https://www.npmjs.com/package/@uniweb/kit)
100
- - [Tailwind CSS v4](https://tailwindcss.com/docs)
1
+ {{> claude-md}}
@@ -1,15 +1,8 @@
1
1
  # {{projectName}}
2
2
 
3
- A multi-site workspace built with [Uniweb](https://github.com/uniweb/uniweb) — a component web platform that separates content from code.
3
+ A multi-site workspace built with [Uniweb](https://github.com/uniweb/cli) — a component web platform that separates content from code.
4
4
 
5
- ## Quick Start
6
-
7
- ```bash
8
- pnpm install # Install dependencies
9
- pnpm dev # Start main site development
10
- ```
11
-
12
- Visit `http://localhost:5173` to see your site.
5
+ {{> quick-start}}
13
6
 
14
7
  ## Project Structure
15
8
 
@@ -33,6 +26,8 @@ Visit `http://localhost:5173` to see your site.
33
26
  └── README.md # This file
34
27
  ```
35
28
 
29
+ {{> components-docs}}
30
+
36
31
  ## Commands
37
32
 
38
33
  ```bash
@@ -85,12 +80,6 @@ This allows:
85
80
  - Single source of truth for design
86
81
  - Foundation updates propagate to all sites
87
82
 
88
- ## AI Assistance
89
-
90
- See [CLAUDE.md](./CLAUDE.md) for detailed instructions that AI assistants can use.
91
-
92
- ## Learn More
83
+ {{> ai-assistance}}
93
84
 
94
- - [Uniweb Documentation](https://github.com/uniweb/uniweb)
95
- - [@uniweb/kit Components](https://www.npmjs.com/package/@uniweb/kit)
96
- - [Tailwind CSS v4](https://tailwindcss.com)
85
+ {{> learn-more}}
@@ -14,7 +14,8 @@
14
14
  "dev": "vite",
15
15
  "build": "uniweb build",
16
16
  "build:vite": "vite build",
17
- "preview": "vite preview"
17
+ "preview": "vite preview",
18
+ "docs": "uniweb docs"
18
19
  },
19
20
  "peerDependencies": {
20
21
  "react": "^18.0.0 || ^19.0.0",
@@ -0,0 +1,13 @@
1
+ // Auto-generated foundation entry point
2
+ // DO NOT EDIT - This file is regenerated during build
3
+
4
+ import './styles.css'
5
+ import Section from './components/Section/index.jsx'
6
+
7
+ export const components = { Section }
8
+
9
+ export { Section }
10
+
11
+ export const capabilities = null
12
+
13
+ export const meta = {}
@@ -0,0 +1,11 @@
1
+ {{> exports-js}}
2
+
3
+ // import Layout from './components/Layout'
4
+
5
+ export default {
6
+ // Uncomment to use a custom page layout:
7
+ // Layout,
8
+
9
+ // Foundation-wide props (accessible via website.foundationProps):
10
+ props: {},
11
+ }
@@ -1,15 +1,8 @@
1
1
  # {{projectName}}
2
2
 
3
- A website built with [Uniweb](https://github.com/uniweb/uniweb) — a component web platform that separates content from code.
3
+ A website built with [Uniweb](https://github.com/uniweb/cli) — a component web platform that separates content from code.
4
4
 
5
- ## Quick Start
6
-
7
- ```bash
8
- pnpm install # Install dependencies
9
- pnpm dev # Start development server
10
- ```
11
-
12
- Visit `http://localhost:5173` to see your site.
5
+ {{> quick-start}}
13
6
 
14
7
  ## Project Structure
15
8
 
@@ -49,10 +42,7 @@ Your content here.
49
42
  [Call to Action](#)
50
43
  ```
51
44
 
52
- **Page structure:**
53
- - Create folder: `site/pages/about/`
54
- - Add `page.yml` with title and metadata
55
- - Add sections: `1-intro.md`, `2-team.md`, etc.
45
+ {{> adding-pages}}
56
46
 
57
47
  ## Component Development
58
48
 
@@ -78,6 +68,8 @@ export default Hero
78
68
 
79
69
  Exposed components (selectable via `type:` in frontmatter) need a `meta.js` file.
80
70
 
71
+ {{> components-docs}}
72
+
81
73
  ## Building
82
74
 
83
75
  ```bash
@@ -90,12 +82,6 @@ cd site && pnpm build
90
82
 
91
83
  Deploy `site/dist/` to any static host (Vercel, Netlify, Cloudflare Pages, etc.)
92
84
 
93
- ## AI Assistance
94
-
95
- See [CLAUDE.md](./CLAUDE.md) for detailed instructions that AI assistants can use.
96
-
97
- ## Learn More
85
+ {{> ai-assistance}}
98
86
 
99
- - [Uniweb Documentation](https://github.com/uniweb/uniweb)
100
- - [@uniweb/kit Components](https://www.npmjs.com/package/@uniweb/kit)
101
- - [Tailwind CSS v4](https://tailwindcss.com)
87
+ {{> learn-more}}
@@ -14,7 +14,8 @@
14
14
  "dev": "vite",
15
15
  "build": "uniweb build",
16
16
  "build:vite": "vite build",
17
- "preview": "vite preview"
17
+ "preview": "vite preview",
18
+ "docs": "uniweb docs"
18
19
  },
19
20
  "peerDependencies": {
20
21
  "react": "^18.0.0 || ^19.0.0",
@@ -0,0 +1,13 @@
1
+ // Auto-generated foundation entry point
2
+ // DO NOT EDIT - This file is regenerated during build
3
+
4
+ import './styles.css'
5
+ import Section from './components/Section/index.jsx'
6
+
7
+ export const components = { Section }
8
+
9
+ export { Section }
10
+
11
+ export const capabilities = null
12
+
13
+ export const meta = {}
@@ -0,0 +1,11 @@
1
+ {{> exports-js}}
2
+
3
+ // import Layout from './components/Layout'
4
+
5
+ export default {
6
+ // Uncomment to use a custom page layout:
7
+ // Layout,
8
+
9
+ // Foundation-wide props (accessible via website.foundationProps):
10
+ props: {},
11
+ }
@@ -66,5 +66,5 @@ uniweb create myproject --template github:user/repo
66
66
 
67
67
  ## Resources
68
68
 
69
- - [Uniweb Documentation](https://github.com/uniweb/uniweb)
69
+ - [Uniweb Documentation](https://github.com/uniweb/cli)
70
70
  - [@uniweb/kit Documentation](https://www.npmjs.com/package/@uniweb/kit)
@@ -0,0 +1,14 @@
1
+ // Auto-generated foundation entry point
2
+ // DO NOT EDIT - This file is regenerated during build
3
+
4
+ import './styles.css'
5
+ import Features from './components/Features/index.jsx'
6
+ import Hero from './components/Hero/index.jsx'
7
+
8
+ export const components = { Features, Hero }
9
+
10
+ export { Features, Hero }
11
+
12
+ export const runtime = null
13
+
14
+ export const meta = {}
@@ -1,110 +0,0 @@
1
- ## Search Functionality
2
-
3
- Uniweb sites support full-text search out of the box. Search indexes are generated automatically at build time.
4
-
5
- ### Enabling Search in Your Foundation
6
-
7
- To add search to your site, your foundation needs the **Fuse.js** library:
8
-
9
- ```bash
10
- cd foundation
11
- pnpm add fuse.js
12
- ```
13
-
14
- Then use the search helpers from `@uniweb/kit`:
15
-
16
- ```jsx
17
- import { useSearch } from '@uniweb/kit/search'
18
-
19
- function SearchComponent({ website }) {
20
- const { query, results, isLoading, clear } = useSearch(website)
21
-
22
- return (
23
- <div>
24
- <input
25
- type="search"
26
- placeholder="Search..."
27
- onChange={e => query(e.target.value)}
28
- />
29
- {isLoading && <span>Searching...</span>}
30
- <ul>
31
- {results.map(result => (
32
- <li key={result.id}>
33
- <a href={result.href}>{result.title}</a>
34
- <p dangerouslySetInnerHTML=\{{ __html: result.snippetHtml }} />
35
- </li>
36
- ))}
37
- </ul>
38
- </div>
39
- )
40
- }
41
- ```
42
-
43
- ### Search Configuration
44
-
45
- Search is enabled by default. To customize, add to `site/site.yml`:
46
-
47
- ```yaml
48
- search:
49
- enabled: true
50
- exclude:
51
- routes: [/admin, /private] # Don't index these routes
52
- components: [Debug] # Don't index these component types
53
- ```
54
-
55
- ### How It Works
56
-
57
- 1. **Build time**: Uniweb extracts text from all pages and sections
58
- 2. **Output**: A `search-index.json` file is generated in `dist/`
59
- 3. **Runtime**: Components fetch and search the index client-side
60
- 4. **Multi-locale**: Each locale gets its own search index
61
-
62
- ### Search API
63
-
64
- The `website` object provides these methods:
65
-
66
- ```javascript
67
- // Check if search is available
68
- website.isSearchEnabled() // Returns boolean
69
-
70
- // Get the URL for the search index
71
- website.getSearchIndexUrl() // "/search-index.json" or "/es/search-index.json"
72
-
73
- // Get full search configuration
74
- website.getSearchConfig() // { enabled, indexUrl, locale, include, exclude }
75
- ```
76
-
77
- ### Search Result Format
78
-
79
- Results from `useSearch()` include:
80
-
81
- | Field | Description |
82
- |-------|-------------|
83
- | `id` | Unique result identifier |
84
- | `type` | `"page"` or `"section"` |
85
- | `route` | Page route |
86
- | `href` | Full link including anchor |
87
- | `title` | Result title |
88
- | `pageTitle` | Parent page title (for sections) |
89
- | `snippetHtml` | Excerpt with `<mark>` highlighted matches |
90
- | `snippetText` | Plain text excerpt |
91
-
92
- ### Without @uniweb/kit
93
-
94
- If you prefer not to use the kit helpers, you can fetch the index directly:
95
-
96
- ```javascript
97
- // Fetch the search index
98
- const response = await fetch(website.getSearchIndexUrl())
99
- const index = await response.json()
100
-
101
- // Use with Fuse.js directly
102
- import Fuse from 'fuse.js'
103
- const fuse = new Fuse(index.entries, {
104
- keys: ['title', 'content'],
105
- threshold: 0.35,
106
- includeMatches: true
107
- })
108
-
109
- const results = fuse.search('your query')
110
- ```
@@ -1,32 +0,0 @@
1
- /**
2
- * Default Foundation Entry Point
3
- */
4
-
5
- import Section from './components/Section/index.jsx'
6
-
7
- const components = {
8
- Section,
9
- }
10
-
11
- export function getComponent(name) {
12
- return components[name]
13
- }
14
-
15
- export function listComponents() {
16
- return Object.keys(components)
17
- }
18
-
19
- export function getSchema(name) {
20
- return components[name]?.schema
21
- }
22
-
23
- export function getAllSchemas() {
24
- const schemas = {}
25
- for (const [name, component] of Object.entries(components)) {
26
- if (component.schema) schemas[name] = component.schema
27
- }
28
- return schemas
29
- }
30
-
31
- export { Section }
32
- export default { getComponent, listComponents, getSchema, getAllSchemas, components }