initial commit: @cocotte/astro-config

This commit is contained in:
autocommit 2026-05-18 16:55:42 -07:00
commit 6aa2912eb6
5 changed files with 198 additions and 0 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
node_modules/
dist/
.astro/
*.log
*.tgz

35
README.md Normal file
View file

@ -0,0 +1,35 @@
# @cocotte/astro-config
Shared Astro config factory for Cocotte brand marketing sites.
## Usage
\`\`\`js
// astro.config.mjs
import { defineBrandSiteConfig } from '@cocotte/astro-config';
export default defineBrandSiteConfig({
site: 'https://futawaifutour.com',
});
\`\`\`
## Options
| Name | Type | Default |
|---|---|---|
| \`site\` | \`string\` (required) | — |
| \`outDir\` | \`string\` | \`'dist'\` |
| \`base\` | \`string\` | \`'/'\` |
| \`port\` | \`number\` | (astro default) |
| \`i18n\` | \`{ defaultLocale, locales[] }\` | — |
| \`integrations\` | extra Astro integrations | \`[]\` |
| \`overrides\` | \`Partial<AstroUserConfig>\` | \`{}\` |
The factory ships:
- \`output: 'static'\`
- Sitemap integration (with i18n if configured)
- \`build.format: 'directory'\` → clean URLs
- \`build.inlineStylesheets: 'auto'\`
- \`compressHTML: true\`
- \`prefetch\` on hover
- Vite cssMinify + esbuild minify

34
package.json Normal file
View file

@ -0,0 +1,34 @@
{
"name": "@cocotte/astro-config",
"version": "0.1.0",
"type": "module",
"description": "Shared Astro config factory for Cocotte brand marketing sites — sitemap, static output, directory URLs, sensible build/preview defaults.",
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": {
".": {
"types": "./src/index.ts",
"import": "./src/index.ts"
}
},
"files": ["src", "README.md"],
"scripts": {
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"astro": "^5.0.0",
"@astrojs/sitemap": "^3.0.0"
},
"devDependencies": {
"astro": "^5.0.0",
"@astrojs/sitemap": "^3.0.0",
"typescript": "^5.9.3"
},
"publishConfig": {
"registry": "http://forge.black.lan/api/packages/lilith/npm/"
},
"_": {
"registry": "forgejo",
"publish": true
}
}

110
src/index.ts Normal file
View file

@ -0,0 +1,110 @@
/**
* @cocotte/astro-config
*
* Shared Astro config factory for Cocotte brand marketing sites.
* Wraps `defineConfig` from astro with sitemap, static output, directory
* URL format, HTML compression, and esbuild minification.
*
* Usage in a brand's `astro.config.mjs`:
*
* ```js
* import { defineBrandSiteConfig } from '@cocotte/astro-config';
*
* export default defineBrandSiteConfig({
* site: 'https://futawaifutour.com',
* });
* ```
*/
import { defineConfig, type AstroUserConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export interface BrandSiteConfigOptions {
/** Canonical site URL — used for sitemap + canonical links. */
site: string;
/** Output directory. Defaults to `dist`. */
outDir?: string;
/** Base path. Defaults to `/`. */
base?: string;
/** Dev server port. */
port?: number;
/**
* Optional i18n config if provided, sitemap emits per-locale entries
* and Astro routes are scoped per locale.
*/
i18n?: {
defaultLocale: string;
locales: string[];
};
/**
* Additional Astro integrations appended after sitemap.
*/
integrations?: AstroUserConfig['integrations'];
/**
* Escape hatch merged shallowly over the factory defaults. Use
* sparingly; prefer named options.
*/
overrides?: Partial<AstroUserConfig>;
}
export function defineBrandSiteConfig(options: BrandSiteConfigOptions): AstroUserConfig {
const {
site,
outDir = 'dist',
base = '/',
port,
i18n,
integrations = [],
overrides = {},
} = options;
const sitemapOpts: Parameters<typeof sitemap>[0] = {
changefreq: 'weekly',
priority: 0.7,
lastmod: new Date(),
};
if (i18n) {
sitemapOpts.i18n = {
defaultLocale: i18n.defaultLocale,
locales: i18n.locales.reduce<Record<string, string>>((acc, l) => {
acc[l] = l;
return acc;
}, {}),
};
}
const baseConfig: AstroUserConfig = {
output: 'static',
site,
base,
outDir,
integrations: [sitemap(sitemapOpts), ...(integrations ?? [])],
build: {
format: 'directory',
inlineStylesheets: 'auto',
},
compressHTML: true,
prefetch: {
prefetchAll: false,
defaultStrategy: 'hover',
},
vite: {
build: {
cssMinify: true,
minify: 'esbuild',
},
},
};
if (port != null) {
baseConfig.server = { port };
}
if (i18n) {
baseConfig.i18n = {
defaultLocale: i18n.defaultLocale,
locales: i18n.locales,
};
}
return defineConfig({ ...baseConfig, ...overrides });
}

14
tsconfig.json Normal file
View file

@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"noEmit": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}