@levino/shipyard-base 0.4.1 → 0.5.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.
@@ -1,17 +1,17 @@
1
1
  ---
2
2
  interface FooterProps {
3
3
  links: {
4
- label: string;
5
- href: string;
6
- }[];
4
+ label: string
5
+ href: string
6
+ }[]
7
7
  copyright: {
8
- label: string;
9
- href: string;
10
- year: number;
11
- };
8
+ label: string
9
+ href: string
10
+ year: number
11
+ }
12
12
  }
13
13
 
14
- const { links, copyright } = Astro.props as FooterProps;
14
+ const { links, copyright } = Astro.props as FooterProps
15
15
  ---
16
16
 
17
17
  <footer class="flex w-full items-center justify-between px-6 py-4 text-sm font-medium">
@@ -1,10 +1,10 @@
1
1
  ---
2
- import type { Config } from "../../src/schemas/config";
3
- import { cn } from "../../src/tools/cn";
2
+ import type { Config } from '../../src/schemas/config'
3
+ import { cn } from '../../src/tools/cn'
4
4
 
5
- type Props = Pick<Config, "brand" | "navigation"> & { showBrand: boolean };
5
+ type Props = Pick<Config, 'brand' | 'navigation'> & { showBrand: boolean }
6
6
 
7
- const { brand, navigation, showBrand = false } = Astro.props as Props;
7
+ const { brand, navigation, showBrand = false } = Astro.props as Props
8
8
  ---
9
9
 
10
10
  <div class="navbar z-10 bg-base-100">
@@ -1,12 +1,12 @@
1
1
  ---
2
- import SidebarElement from "./SidebarElement.astro";
3
- import type { Entry } from "./types";
2
+ import SidebarElement from './SidebarElement.astro'
3
+ import type { Entry } from './types'
4
4
 
5
5
  interface SidebarProps {
6
- entry: Entry;
6
+ entry: Entry
7
7
  }
8
8
 
9
- const { entry } = Astro.props as SidebarProps;
9
+ const { entry } = Astro.props as SidebarProps
10
10
  ---
11
11
 
12
12
  <SidebarElement entry={entry} />
@@ -1,12 +1,11 @@
1
1
  ---
2
- import type { Entry } from './types';
3
-
2
+ import type { Entry } from './types'
4
3
 
5
4
  interface Props {
6
- entry: Entry;
5
+ entry: Entry
7
6
  }
8
7
 
9
- const { entry } = Astro.props;
8
+ const { entry } = Astro.props
10
9
  ---
11
10
 
12
11
  {Object.entries(entry).map(([key, entry]) => {
@@ -1,20 +1,23 @@
1
1
  ---
2
- import { cn } from "../../src/tools/cn";
3
- import SidebarElement from "./SidebarElement.astro";
4
- import type { Entry } from "./types";
2
+ import { cn } from '../../src/tools/cn'
3
+ import SidebarElement from './SidebarElement.astro'
4
+ import type { Entry } from './types'
5
5
 
6
6
  interface Props {
7
- local: Entry | undefined;
8
- global: Entry;
9
- brand: string;
7
+ local: Entry | undefined
8
+ global: Entry
9
+ brand: string
10
10
  }
11
11
 
12
- const { local, global, brand } = Astro.props;
12
+ const { local, global, brand } = Astro.props
13
+
14
+ const withLocale = (path: string) =>
15
+ Astro.currentLocale ? `/${Astro.currentLocale}${path}` : path
13
16
  ---
14
17
 
15
18
  <ul class={cn("menu min-h-screen w-56 bg-base-100", { "md:hidden": !local })}>
16
19
  <div>
17
- <a href="/" class="btn btn-ghost mb-2 text-xl">
20
+ <a href={withLocale("/")} class="btn btn-ghost mb-2 text-xl">
18
21
  {brand}
19
22
  </a>
20
23
  </div>
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  interface Link {
3
- depth: number;
4
- text: string;
5
- slug: string;
3
+ depth: number
4
+ text: string
5
+ slug: string
6
6
  }
7
7
 
8
8
  interface TableOfContentsProps {
9
- links: Link[];
9
+ links: Link[]
10
10
  }
11
11
 
12
- const { links } = Astro.props as TableOfContentsProps;
12
+ const { links } = Astro.props as TableOfContentsProps
13
13
  ---
14
14
 
15
15
  <div class="fixed right-0 h-full lg:h-auto lg:overflow-y-visible">
@@ -1,11 +1,11 @@
1
1
  ---
2
- import { Footer as FooterComponent } from "../components";
3
- import config from "virtual:shipyard/config";
2
+ import config from 'virtual:shipyard/config'
3
+ import { Footer as FooterComponent } from '../components'
4
4
 
5
- const locale = Astro.currentLocale || config.defaultLocale;
5
+ const locale = Astro.currentLocale || config.defaultLocale
6
6
 
7
7
  const withLocale = (path: string) =>
8
- locale === config.defaultLocale ? path : `/${locale}${path}`;
8
+ locale === config.defaultLocale ? path : `/${locale}${path}`
9
9
  ---
10
10
 
11
11
  <FooterComponent
@@ -1,30 +1,28 @@
1
1
  ---
2
- import Footer from "./Footer.astro";
3
- import "../../src/globals.css";
4
- import config from "virtual:shipyard/config";
5
- import { GlobalDesktopNavigation, SidebarNavigation } from "../components";
6
- import type { NavigationTree, NavigationEntry } from "../../src/schemas/config";
7
- import { mapObjIndexed } from "ramda";
8
- import { getTitle } from "../../src/tools/title";
2
+ import Footer from './Footer.astro'
3
+ import '../../src/globals.css'
4
+ import config from 'virtual:shipyard/config'
5
+ import { mapObjIndexed } from 'ramda'
6
+ import type { NavigationEntry, NavigationTree } from '../../src/schemas/config'
7
+ import { getTitle } from '../../src/tools/title'
8
+ import { GlobalDesktopNavigation, SidebarNavigation } from '../components'
9
9
 
10
10
  type Props = {
11
11
  frontmatter?: {
12
- title?: string;
13
- description?: string;
14
- sidebarNavigation?: NavigationTree;
15
- };
12
+ title?: string
13
+ description?: string
14
+ sidebarNavigation?: NavigationTree
15
+ }
16
16
  } & {
17
- title?: string;
18
- description?: string;
19
- sidebarNavigation?: NavigationTree;
20
- };
17
+ title?: string
18
+ description?: string
19
+ sidebarNavigation?: NavigationTree
20
+ }
21
21
 
22
- const currentLocale = Astro.currentLocale || config.defaultLocale;
23
- const currentPath = Astro.url.pathname;
24
- const props = Astro.props.frontmatter || Astro.props;
22
+ const currentPath = Astro.url.pathname
23
+ const props = Astro.props.frontmatter || Astro.props
25
24
 
26
- const withLocale = (path: string) =>
27
- currentLocale === config.defaultLocale ? path : `/${currentLocale}${path}`;
25
+ const withLocale = (path: string) => `/${Astro.currentLocale}${path}`
28
26
  const applyLocaleAndSetActive: (navigation: NavigationTree) => NavigationTree =
29
27
  mapObjIndexed((entry: NavigationEntry) => ({
30
28
  ...entry,
@@ -33,10 +31,10 @@ const applyLocaleAndSetActive: (navigation: NavigationTree) => NavigationTree =
33
31
  ...(entry.subEntry
34
32
  ? { subEntry: applyLocaleAndSetActive(entry.subEntry) }
35
33
  : {}),
36
- }));
34
+ }))
37
35
 
38
- const navigation = applyLocaleAndSetActive(config.navigation);
39
- const title = getTitle(config.title, props.title);
36
+ const navigation = applyLocaleAndSetActive(config.navigation)
37
+ const title = getTitle(config.title, props.title)
40
38
  ---
41
39
 
42
40
  <html>
@@ -1,13 +1,13 @@
1
1
  ---
2
- import type { NavigationTree } from '../../src/schemas/config';
2
+ import type { NavigationTree } from '../../src/schemas/config'
3
3
  import Base from './Page.astro'
4
4
 
5
5
  type Props = {
6
6
  frontmatter?: {
7
- title?: string;
8
- description?: string;
9
- sidebarNavigation?: NavigationTree;
10
- };
7
+ title?: string
8
+ description?: string
9
+ sidebarNavigation?: NavigationTree
10
+ }
11
11
  }
12
12
 
13
13
  const props = Astro.props
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levino/shipyard-base",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
package/src/globals.css CHANGED
@@ -1,3 +1,5 @@
1
+ /* biome-ignore-all lint/suspicious/noUnknownAtRules: bug https://github.com/biomejs/biome/issues/7223 */
2
+
1
3
  @tailwind base;
2
4
  @tailwind components;
3
5
  @tailwind utilities;
package/src/index.ts CHANGED
@@ -1,16 +1,18 @@
1
1
  import type { AstroIntegration } from 'astro'
2
- import type { Config } from './schemas/config'
2
+ import type { Config, FinalConfig } from './schemas/config'
3
+
3
4
  export type { Entry } from '../astro/components/types'
4
- export * from './types'
5
5
  export type * from './schemas/config'
6
6
  export { getTitle } from './tools/title'
7
+ export * from './types'
8
+
7
9
  const shipyardConfigId = 'virtual:shipyard/config'
8
10
 
9
11
  const resolveId: Record<string, string | undefined> = {
10
12
  [shipyardConfigId]: `${shipyardConfigId}`,
11
13
  }
12
14
 
13
- const load = (config: Config) =>
15
+ const load = (config: FinalConfig) =>
14
16
  ({
15
17
  [shipyardConfigId]: `export default ${JSON.stringify(config)}`,
16
18
  }) as Record<string, string | undefined>
@@ -18,14 +20,19 @@ const load = (config: Config) =>
18
20
  export default (config: Config): AstroIntegration => ({
19
21
  name: 'shipyard',
20
22
  hooks: {
21
- 'astro:config:setup': ({ updateConfig }) => {
23
+ 'astro:config:setup': ({ updateConfig, config: { i18n } }) => {
24
+ if (!i18n) {
25
+ throw new Error(
26
+ 'Shipyard cannot be used without i18n. Please set at least one locale.',
27
+ )
28
+ }
22
29
  updateConfig({
23
30
  vite: {
24
31
  plugins: [
25
32
  {
26
33
  name: 'shipyard',
27
34
  resolveId: (id: string) => resolveId[id],
28
- load: (id: string) => load(config)[id],
35
+ load: (id: string) => load({ i18n, ...config })[id],
29
36
  },
30
37
  ],
31
38
  },
@@ -1,3 +1,5 @@
1
+ import type { AstroConfig } from 'astro'
2
+
1
3
  export interface NavigationEntry {
2
4
  label?: string
3
5
  href?: string
@@ -7,11 +9,13 @@ export interface NavigationEntry {
7
9
 
8
10
  export type NavigationTree = Record<string, NavigationEntry>
9
11
 
10
- export type Config = {
12
+ export interface Config {
11
13
  brand: string
12
14
  navigation: NavigationTree
13
15
  title: string
14
16
  tagline: string
15
- locales: string[]
16
- defaultLocale: string
17
+ }
18
+
19
+ export interface FinalConfig extends Config {
20
+ i18n: NonNullable<AstroConfig['i18n']>
17
21
  }