lightnet 3.12.2 → 4.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 (110) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/__e2e__/basics-fixture.ts +9 -63
  3. package/__e2e__/fixtures/basics/astro.config.mjs +7 -12
  4. package/__e2e__/fixtures/basics/node_modules/.bin/astro +4 -4
  5. package/__e2e__/fixtures/basics/node_modules/.bin/tailwind +2 -2
  6. package/__e2e__/fixtures/basics/node_modules/.bin/tailwindcss +2 -2
  7. package/__e2e__/fixtures/basics/node_modules/.bin/tsc +2 -2
  8. package/__e2e__/fixtures/basics/node_modules/.bin/tsserver +2 -2
  9. package/__e2e__/fixtures/basics/package.json +6 -5
  10. package/__e2e__/fixtures/basics/src/content/categories/christian-living.json +4 -1
  11. package/__e2e__/fixtures/basics/src/content/categories/teens.json +4 -1
  12. package/__e2e__/fixtures/basics/src/content/categories/theology.json +4 -1
  13. package/__e2e__/fixtures/basics/src/content/media/faithful-freestyle--en.json +6 -2
  14. package/__e2e__/fixtures/basics/src/content/media/how-to-kickflip--de.json +6 -1
  15. package/__e2e__/fixtures/basics/src/content/media/skate-sounds--en.json +8 -2
  16. package/__e2e__/fixtures/basics/src/content/media-collections/how-to-articles.json +5 -1
  17. package/__e2e__/fixtures/basics/src/content/media-types/audio.json +5 -2
  18. package/__e2e__/fixtures/basics/src/content/media-types/book.json +10 -4
  19. package/__e2e__/fixtures/basics/src/content/media-types/video.json +5 -2
  20. package/__e2e__/fixtures/basics/src/pages/[locale]/index.astro +0 -1
  21. package/__e2e__/fixtures/basics/src/translations/de.yml +0 -8
  22. package/__e2e__/fixtures/basics/src/translations/en.yml +0 -8
  23. package/__e2e__/global.teardown.ts +2 -2
  24. package/__tests__/astro-integration/config.spec.ts +364 -0
  25. package/__tests__/astro-integration/integration.spec.ts +125 -0
  26. package/__tests__/astro-integration/tailwind.spec.ts +36 -0
  27. package/__tests__/content/content-schema.spec.ts +109 -0
  28. package/__tests__/content/get-media-collections.spec.ts +72 -0
  29. package/__tests__/content/query-media-items.spec.ts +213 -0
  30. package/__tests__/i18n/resolve-current-locale.spec.ts +65 -0
  31. package/__tests__/i18n/translate-map.spec.ts +19 -0
  32. package/__tests__/i18n/translate.spec.ts +91 -0
  33. package/__tests__/pages/details-page/create-content-metadata.spec.ts +43 -25
  34. package/__tests__/pages/details-page/get-translations.spec.ts +56 -0
  35. package/__tests__/utils/paths.spec.ts +116 -0
  36. package/__tests__/utils/urls.spec.ts +9 -4
  37. package/exports/content.ts +7 -2
  38. package/exports/i18n.ts +0 -1
  39. package/exports/index.ts +1 -5
  40. package/exports/utils.ts +0 -1
  41. package/package.json +16 -12
  42. package/src/astro-integration/config.ts +60 -49
  43. package/src/astro-integration/integration.ts +13 -24
  44. package/src/astro-integration/tailwind.ts +86 -0
  45. package/src/astro-integration/validators/validate-inline-translations.ts +51 -0
  46. package/src/astro-integration/validators/validate-languages.ts +39 -0
  47. package/src/astro-integration/virtual.d.ts +8 -6
  48. package/src/astro-integration/vite-plugin-lightnet-config.ts +29 -9
  49. package/src/components/CarouselSection.astro +7 -11
  50. package/src/components/CategoriesSection.astro +2 -2
  51. package/src/components/HighlightSection.astro +4 -7
  52. package/src/components/Icon.tsx +2 -2
  53. package/src/components/MediaGallerySection.astro +88 -68
  54. package/src/components/MediaList.astro +9 -7
  55. package/src/components/SearchInput.astro +7 -4
  56. package/src/components/Section.astro +7 -5
  57. package/src/components/VideoPlayer.astro +2 -3
  58. package/src/content/content-schema.ts +129 -142
  59. package/src/content/get-categories.ts +52 -28
  60. package/src/content/get-languages.ts +29 -8
  61. package/src/content/get-media-collections.ts +43 -0
  62. package/src/content/get-media-types.ts +41 -7
  63. package/src/content/query-media-items.ts +23 -13
  64. package/src/i18n/bcp-47.ts +8 -0
  65. package/src/i18n/get-locale-paths.ts +1 -3
  66. package/src/i18n/locals.d.ts +21 -3
  67. package/src/i18n/locals.ts +18 -11
  68. package/src/i18n/resolve-current-locale.ts +18 -0
  69. package/src/i18n/resolve-language.ts +10 -5
  70. package/src/i18n/translate-map.ts +70 -0
  71. package/src/i18n/translate.ts +68 -47
  72. package/src/layouts/Page.astro +5 -3
  73. package/src/layouts/components/LanguagePicker.astro +22 -17
  74. package/src/layouts/components/Menu.astro +2 -5
  75. package/src/layouts/components/MenuItem.astro +1 -1
  76. package/src/layouts/components/PageNavigation.astro +29 -29
  77. package/src/layouts/components/PageTitle.astro +23 -7
  78. package/src/pages/404Route.astro +2 -1
  79. package/src/pages/RootRoute.astro +6 -1
  80. package/src/pages/details-page/DefaultDetailsPage.astro +9 -2
  81. package/src/pages/details-page/DetailsPageRoute.astro +1 -2
  82. package/src/pages/details-page/components/AudioPanel.astro +7 -3
  83. package/src/pages/details-page/components/AudioPlayer.astro +2 -2
  84. package/src/pages/details-page/components/ContentSection.astro +67 -44
  85. package/src/pages/details-page/components/MediaCollection.astro +8 -4
  86. package/src/pages/details-page/components/MediaCollectionsSection.astro +3 -6
  87. package/src/pages/details-page/components/main-details/EditButton.astro +22 -10
  88. package/src/pages/details-page/components/main-details/OpenButton.astro +17 -12
  89. package/src/pages/details-page/components/main-details/ShareButton.astro +3 -2
  90. package/src/pages/details-page/components/more-details/Categories.astro +5 -3
  91. package/src/pages/details-page/components/more-details/Languages.astro +12 -7
  92. package/src/pages/details-page/utils/create-content-metadata.ts +24 -9
  93. package/src/pages/details-page/utils/get-translations.ts +6 -0
  94. package/src/pages/search-page/components/LoadingSkeleton.tsx +6 -5
  95. package/src/pages/search-page/components/SearchFilter.astro +10 -21
  96. package/src/pages/search-page/components/SearchFilter.tsx +2 -2
  97. package/src/pages/search-page/components/SearchList.astro +10 -7
  98. package/src/pages/search-page/components/SearchListItem.tsx +5 -4
  99. package/src/pages/search-page/hooks/use-search.ts +5 -2
  100. package/src/utils/lazy.ts +20 -0
  101. package/src/utils/paths.ts +40 -3
  102. package/src/utils/urls.ts +1 -2
  103. package/src/utils/verify-schema.ts +12 -10
  104. package/tailwind.config.ts +1 -25
  105. package/vitest.config.js +18 -2
  106. package/src/astro-integration/project-context.ts +0 -5
  107. package/src/content/compare-media-collection-items.ts +0 -24
  108. package/src/i18n/resolve-default-locale.ts +0 -19
  109. package/src/i18n/resolve-locales.ts +0 -5
  110. package/src/pages/details-page/utils/get-collection-items.ts +0 -29
@@ -2,35 +2,26 @@
2
2
  import config from "virtual:lightnet/config"
3
3
 
4
4
  import { getUsedCategories } from "../../../content/get-categories"
5
- import { contentLanguages } from "../../../content/get-languages"
6
- import { getMediaTypes } from "../../../content/get-media-types"
5
+ import { getUsedLanguages } from "../../../content/get-languages"
6
+ import { getUsedMediaTypes } from "../../../content/get-media-types"
7
7
  import { prepareI18nConfig } from "../../../i18n/react/prepare-i18n-config"
8
8
  import SearchFilterReact from "./SearchFilter.tsx"
9
9
 
10
- const { t, currentLocale } = Astro.locals.i18n
10
+ const { currentLocale, tMap } = Astro.locals.i18n
11
11
 
12
- const sortByLabelText = (array: { id: string; labelText: string }[]) =>
13
- array.sort((a, b) => a.labelText.localeCompare(b.labelText, currentLocale))
14
-
15
- const categories = (await getUsedCategories(currentLocale, t)).map(
12
+ const categories = (await getUsedCategories(currentLocale, tMap)).map(
16
13
  ({ id, labelText }) => ({ id, labelText }),
17
14
  )
18
15
 
19
- const mediaTypes = sortByLabelText(
20
- (await getMediaTypes()).map((type) => ({
21
- id: type.id,
22
- labelText: t(type.data.label),
23
- })),
16
+ const mediaTypes = (await getUsedMediaTypes(currentLocale, tMap)).map(
17
+ ({ id, labelText }) => ({ id, labelText }),
24
18
  )
25
19
 
26
- const languages = sortByLabelText(
27
- contentLanguages.map((language) => ({
28
- id: language.code,
29
- labelText: t(language.label),
30
- })),
20
+ const languages = (await getUsedLanguages(currentLocale, tMap)).map(
21
+ ({ code: id, labelText }) => ({ id, labelText }),
31
22
  )
32
23
 
33
- const languageFilterEnabled = contentLanguages.length > 1
24
+ const languageFilterEnabled = languages.length > 1
34
25
  const typesFilterEnabled = mediaTypes.length > 1
35
26
  // Not every media item has a category. So it makes
36
27
  // sense to have the filter when there is only one category.
@@ -38,9 +29,7 @@ const categoriesFilterEnabled = categories.length > 0
38
29
 
39
30
  const filterByLocale = !!config.searchPage?.filterByLocale
40
31
  let initialLanguageFilter: string | undefined = undefined
41
- const hasContentLanguage = contentLanguages.find(
42
- ({ code }) => code === currentLocale,
43
- )
32
+ const hasContentLanguage = languages.find(({ id }) => id === currentLocale)
44
33
  if (
45
34
  filterByLocale &&
46
35
  currentLocale &&
@@ -1,6 +1,6 @@
1
+ import { SearchIcon } from "lucide-react"
1
2
  import { useRef } from "react"
2
3
 
3
- import Icon from "../../../components/Icon"
4
4
  import { createI18n, type I18nConfig } from "../../../i18n/react/i18n-context"
5
5
  import { useDebounce } from "../hooks/use-debounce"
6
6
  import { useSearchQueryParam } from "../hooks/use-search-query-param"
@@ -57,7 +57,7 @@ export default function SearchFilter({
57
57
  onInput={(e) => debouncedSetSearch(e.currentTarget.value)}
58
58
  onKeyDown={(e) => e.key === "Enter" && searchInput.current?.blur()}
59
59
  />
60
- <Icon className="text-xl mdi--magnify" ariaLabel="" />
60
+ <SearchIcon className="shrink-0 text-gray-700" />
61
61
  </label>
62
62
  <div className="mb-8 grid grid-cols-1 gap-2 sm:grid-cols-3 sm:gap-6 md:mb-10">
63
63
  {languageFilterEnabled && (
@@ -2,15 +2,15 @@
2
2
  import { getCollection } from "astro:content"
3
3
 
4
4
  import { getUsedCategories } from "../../../content/get-categories"
5
- import { contentLanguages } from "../../../content/get-languages"
5
+ import { getUsedLanguages } from "../../../content/get-languages"
6
6
  import { getMediaTypes } from "../../../content/get-media-types"
7
7
  import { prepareI18nConfig } from "../../../i18n/react/prepare-i18n-config"
8
8
  import SearchListReact from "./SearchList.tsx"
9
9
 
10
- const { t, currentLocale } = Astro.locals.i18n
10
+ const { currentLocale, tMap } = Astro.locals.i18n
11
11
 
12
12
  const categories: Record<string, string> = {}
13
- for (const { id, labelText } of await getUsedCategories(currentLocale, t)) {
13
+ for (const { id, labelText } of await getUsedCategories(currentLocale, tMap)) {
14
14
  categories[id] = labelText
15
15
  }
16
16
 
@@ -18,23 +18,26 @@ const mediaTypes = Object.fromEntries(
18
18
  (await getMediaTypes()).map((type) => [
19
19
  type.id,
20
20
  {
21
- labelText: t(type.data.label),
21
+ labelText: tMap(type.data.label, {
22
+ path: ["media-types", type.id, "label"],
23
+ }),
22
24
  icon: type.data.icon,
23
25
  coverImageStyle: type.data.coverImageStyle,
24
26
  },
25
27
  ]),
26
28
  )
27
29
 
30
+ const contentLanguagesList = await getUsedLanguages(currentLocale, tMap)
28
31
  const languages = Object.fromEntries(
29
- contentLanguages.map((language) => [
32
+ contentLanguagesList.map((language) => [
30
33
  language.code,
31
- { direction: language.direction, labelText: t(language.label) },
34
+ { direction: language.direction, labelText: language.labelText },
32
35
  ]),
33
36
  )
34
37
 
35
38
  const mediaItemsTotal = (await getCollection("media")).length
36
39
 
37
- const showLanguage = contentLanguages.length > 1
40
+ const showLanguage = contentLanguagesList.length > 1
38
41
 
39
42
  const i18nConfig = prepareI18nConfig(Astro.locals.i18n, [
40
43
  "ln.search.no-results",
@@ -1,3 +1,5 @@
1
+ import { ChevronRightIcon } from "lucide-react"
2
+
1
3
  import CoverImageDecorator from "../../../components/CoverImageDecorator"
2
4
  import Icon from "../../../components/Icon"
3
5
  import { useI18n } from "../../../i18n/react/use-i18n"
@@ -32,6 +34,7 @@ export default function SearchListItem({
32
34
  }: Props) {
33
35
  const { currentLocale, direction } = useI18n()
34
36
  const coverImageStyle = mediaTypes[item.type].coverImageStyle
37
+ const iconDirectionClass = direction === "rtl" ? "scale-x-[-1]" : ""
35
38
  return (
36
39
  <a
37
40
  href={detailsPagePath(currentLocale, {
@@ -98,10 +101,8 @@ export default function SearchListItem({
98
101
  </p>
99
102
  </div>
100
103
  </div>
101
- <Icon
102
- className="my-auto me-4 ms-2 hidden shrink-0 text-2xl text-gray-300 mdi--chevron-right sm:block md:group-hover:text-primary"
103
- flipIcon={direction === "rtl"}
104
- ariaLabel=""
104
+ <ChevronRightIcon
105
+ className={`my-auto me-4 ms-2 hidden shrink-0 text-gray-300 sm:block md:group-hover:text-primary ${iconDirectionClass}`}
105
106
  />
106
107
  </a>
107
108
  )
@@ -1,6 +1,7 @@
1
1
  import Fuse from "fuse.js"
2
2
  import { useEffect, useMemo, useRef, useState } from "react"
3
3
 
4
+ import { pathWithBase } from "../../../utils/paths"
4
5
  import type { SearchItem, SearchResponse } from "../api/search-response"
5
6
  import { observeSearchQuery, type SearchQuery } from "../utils/search-query"
6
7
 
@@ -10,6 +11,8 @@ interface Context {
10
11
  languages: Record<string, { labelText: string }>
11
12
  }
12
13
 
14
+ const SEARCH_API_PATH = pathWithBase("/api/internal/search.json")
15
+
13
16
  export function useSearch({ categories, mediaTypes, languages }: Context) {
14
17
  const fuse = useRef<Fuse<SearchItem>>(undefined)
15
18
  const [allItems, setAllItems] = useState<SearchItem[]>([])
@@ -28,10 +31,10 @@ export function useSearch({ categories, mediaTypes, languages }: Context) {
28
31
  })
29
32
  const fetchData = async () => {
30
33
  try {
31
- const response = await fetch("/api/internal/search.json")
34
+ const response = await fetch(SEARCH_API_PATH)
32
35
  if (!response.ok) {
33
36
  throw new Error(
34
- "Was not able to load search results from /api/internal/search.json.",
37
+ `Was not able to load search results from ${SEARCH_API_PATH}.`,
35
38
  )
36
39
  }
37
40
  const { items }: SearchResponse = await response.json()
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Creates a lazily initialized value and caches the computed result after the
3
+ * first access.
4
+ *
5
+ * @param compute Function that produces the value when `get()` is called for
6
+ * the first time.
7
+ * @returns An object with a `get()` method that returns the cached value.
8
+ */
9
+ export const lazy = <TReturn>(compute: () => TReturn) => {
10
+ let initialized = false
11
+ let value: TReturn
12
+ const get = () => {
13
+ if (!initialized) {
14
+ value = compute()
15
+ initialized = true
16
+ }
17
+ return value
18
+ }
19
+ return { get }
20
+ }
@@ -1,3 +1,38 @@
1
+ /**
2
+ * Prefix a site-internal path with Astro's configured base path.
3
+ *
4
+ * This helper trims any trailing slash from `BASE_URL`, ensures the input
5
+ * path starts with a leading slash, and concatenates the two values.
6
+ * Absolute URLs are out of scope for this helper.
7
+ *
8
+ * @param path internal path such as "/en/media", "/api/internal/search.json", or "/"
9
+ * @returns base-aware internal path
10
+ */
11
+ export function pathWithBase(path: string) {
12
+ const normalizedBase = import.meta.env.BASE_URL.replace(/\/+$/, "")
13
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`
14
+ return `${normalizedBase}${normalizedPath}`
15
+ }
16
+
17
+ /**
18
+ * Remove Astro's configured base path from a pathname when present.
19
+ *
20
+ * @param pathname pathname such as "/docs/en/media" or "/en/media"
21
+ * @param base Astro base path. Defaults to `import.meta.env.BASE_URL`.
22
+ * @returns pathname without the base prefix
23
+ */
24
+ export function pathWithoutBase(
25
+ pathname: string,
26
+ base = import.meta.env.BASE_URL,
27
+ ) {
28
+ const normalizedBase = base !== "/" ? base.replace(/\/+$/, "") : ""
29
+
30
+ return normalizedBase &&
31
+ (pathname === normalizedBase || pathname.startsWith(`${normalizedBase}/`))
32
+ ? pathname.slice(normalizedBase.length) || "/"
33
+ : pathname
34
+ }
35
+
1
36
  /**
2
37
  * Build path to media item page.
3
38
  *
@@ -9,7 +44,7 @@ export function detailsPagePath(
9
44
  locale: string | undefined,
10
45
  { id }: { id: string },
11
46
  ) {
12
- return `/${locale}/media/${id}`
47
+ return pathWithBase(`/${locale}/media/${id}`)
13
48
  }
14
49
 
15
50
  /**
@@ -42,7 +77,7 @@ export function searchPagePath(
42
77
  searchParams.append("type", filter.type)
43
78
  }
44
79
  const query = searchParams.size ? `?${searchParams.toString()}` : ""
45
- return `/${locale}/media${query}`
80
+ return pathWithBase(`/${locale}/media${query}`)
46
81
  }
47
82
 
48
83
  /**
@@ -56,5 +91,7 @@ export function searchPagePath(
56
91
  * @returns resolved path. Eg. '/en/about' for input "en" and "/about"
57
92
  */
58
93
  export function localizePath(locale: string | undefined, path: string) {
59
- return `${locale ? `/${locale}` : ""}/${path.replace(/^\//, "")}`
94
+ return pathWithBase(
95
+ `${locale ? `/${locale}` : ""}/${path.replace(/^\//, "")}`,
96
+ )
60
97
  }
package/src/utils/urls.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import config from "virtual:lightnet/config"
2
- import projectContext from "virtual:lightnet/project-context"
3
2
 
4
3
  /**
5
4
  * Test if a given url is outside this site.
@@ -21,7 +20,7 @@ export function isExternalUrl(url: string) {
21
20
  if (config.internalDomains.includes(parsedUrl.hostname)) {
22
21
  return false
23
22
  }
24
- const { site } = projectContext
23
+ const { SITE: site } = import.meta.env
25
24
  if (!site) {
26
25
  return true
27
26
  }
@@ -8,10 +8,11 @@ export async function verifySchemaAsync<T extends z.Schema>(
8
8
  hint: string | ((id: string | undefined) => string),
9
9
  ): Promise<z.output<T>> {
10
10
  const parsed = await schema.safeParseAsync(toVerify)
11
- if (!parsed.success) {
12
- throwParseError(toVerify, errorMessage, hint, parsed)
11
+ if (parsed.success) {
12
+ return parsed.data
13
13
  }
14
- return parsed.data
14
+
15
+ throwParseError(toVerify, errorMessage, hint, parsed)
15
16
  }
16
17
 
17
18
  export function verifySchema<T extends z.Schema>(
@@ -21,24 +22,25 @@ export function verifySchema<T extends z.Schema>(
21
22
  hint: string | ((id: string | undefined) => string),
22
23
  ): z.output<T> {
23
24
  const parsed = schema.safeParse(toVerify, {})
24
- if (!parsed.success) {
25
- throwParseError(toVerify, errorMessage, hint, parsed)
25
+ if (parsed.success) {
26
+ return parsed.data
26
27
  }
27
- return parsed.data
28
+
29
+ throwParseError(toVerify, errorMessage, hint, parsed)
28
30
  }
29
31
 
30
32
  function throwParseError(
31
33
  toVerify: unknown,
32
34
  errorMessage: string | ((id: string | undefined) => string),
33
35
  hint: string | ((id: string | undefined) => string),
34
- parsed: z.SafeParseError<unknown>,
35
- ) {
36
+ parsed: z.ZodSafeParseError<unknown>,
37
+ ): never {
36
38
  const id = z.object({ id: z.string() }).safeParse(toVerify).data?.id
37
39
  const message =
38
40
  typeof errorMessage === "string" ? errorMessage : errorMessage(id)
39
41
  const hintFinal = typeof hint === "string" ? hint : hint(id)
40
- const issues = parsed.error.errors
41
- .map((e) => `- ${e.path.join(".")}: ${e.message}`)
42
+ const issues = parsed.error.issues
43
+ .map((issue) => `- ${issue.path.join(".")}: ${issue.message}`)
42
44
  .join("\n")
43
45
  throw new AstroError(message, `${hintFinal}\n\n${issues}`)
44
46
  }
@@ -1,6 +1,5 @@
1
1
  import { addIconSelectors } from "@iconify/tailwind"
2
2
  import typography from "@tailwindcss/typography"
3
- import daisyui from "daisyui"
4
3
  import type { Config } from "tailwindcss"
5
4
 
6
5
  const DEFAULT_COLOR_PRIMARY = "#E6B15C"
@@ -27,30 +26,7 @@ export function lightnetStyles({
27
26
  },
28
27
  },
29
28
  },
30
- daisyui: {
31
- themes: [
32
- {
33
- lightnet: {
34
- primary,
35
- secondary: primary,
36
- accent: primary,
37
- neutral: "#030712",
38
- error: "#9f1239",
39
- "base-100": "#f9fafb",
40
-
41
- "--rounded-box": "0.375rem", // border radius rounded-box utility class, used in card and other large boxes
42
- "--rounded-btn": "0.375rem", // border radius rounded-btn utility class, used in buttons and similar element
43
- "--rounded-badge": "0.375rem", // border radius rounded-badge utility class, used in badges and similar
44
- "--tab-radius": "0.375rem", // border radius of tabs
45
- },
46
- },
47
- ],
48
- base: false, // applies background color and foreground color for root element by default
49
- utils: true, // adds responsive and modifier utility classes
50
- logs: false, // Shows info about daisyUI version and used config in the console when building your CSS
51
- prefix: "dy-",
52
- },
53
- plugins: [typography, daisyui, addIconSelectors(["mdi"])],
29
+ plugins: [typography, addIconSelectors(["mdi", "lucide"])],
54
30
  }
55
31
  }
56
32
 
package/vitest.config.js CHANGED
@@ -9,9 +9,25 @@ export default defineConfig({
9
9
  plugins: [
10
10
  vitePluginLightnetConfig(
11
11
  {
12
- title: "Sk8 Ministries",
12
+ title: { en: "Sk8 Ministries" },
13
13
  logo: { src: "./logo.svg" },
14
- languages: [{ code: "en", label: "English" }],
14
+ languages: [
15
+ {
16
+ code: "en",
17
+ label: { en: "English" },
18
+ isDefaultSiteLanguage: true,
19
+ isSiteLanguage: true,
20
+ fallbackLanguages: [],
21
+ },
22
+ {
23
+ code: "de",
24
+ label: { en: "German" },
25
+ isSiteLanguage: true,
26
+ fallbackLanguages: ["en"],
27
+ },
28
+ ],
29
+ locales: ["en", "de"],
30
+ defaultLocale: "en",
15
31
  internalDomains: [],
16
32
  },
17
33
  { site: "https://sk8-ministries.dev" },
@@ -1,5 +0,0 @@
1
- export type ProjectContext = {
2
- root: URL
3
- srcDir: URL
4
- site?: string
5
- }
@@ -1,24 +0,0 @@
1
- import type { MediaItemEntry } from "./content-schema"
2
-
3
- export function compareMediaCollectionItems(
4
- item1: MediaItemEntry,
5
- item2: MediaItemEntry,
6
- collectionId: string,
7
- ) {
8
- const getIndex = (item: MediaItemEntry) =>
9
- item.data.collections?.find(
10
- ({ collection }) => collection.id === collectionId,
11
- )?.index
12
- const index1 = getIndex(item1)
13
- const index2 = getIndex(item2)
14
- if (index1 === index2) {
15
- return item1.id.localeCompare(item2.id)
16
- }
17
- if (index1 === undefined && index2 !== undefined) {
18
- return 1
19
- }
20
- if (index1 !== undefined && index2 === undefined) {
21
- return -1
22
- }
23
- return index1! - index2!
24
- }
@@ -1,19 +0,0 @@
1
- import { AstroError } from "astro/errors"
2
-
3
- export const resolveDefaultLocale = ({
4
- languages,
5
- }: {
6
- languages: {
7
- code: string
8
- isDefaultSiteLanguage?: boolean
9
- }[]
10
- }) => {
11
- const defaultLanguage = languages.find((l) => l.isDefaultSiteLanguage)
12
- if (!defaultLanguage) {
13
- throw new AstroError(
14
- "No default site language set",
15
- "To fix the issue, set isDefaultSiteLanguage for one language in the LightNet configuration in your astro.config.mjs file.",
16
- )
17
- }
18
- return defaultLanguage.code
19
- }
@@ -1,5 +0,0 @@
1
- import type { Language } from "../astro-integration/config"
2
-
3
- export const resolveLocales = ({ languages }: { languages: Language[] }) => {
4
- return languages.filter((l) => l.isSiteLanguage).map((l) => l.code)
5
- }
@@ -1,29 +0,0 @@
1
- import { compareMediaCollectionItems } from "../../../content/compare-media-collection-items"
2
- import type { MediaItemEntry } from "../../../content/content-schema"
3
- import { getMediaItems } from "../../../content/get-media-items"
4
-
5
- const groupItemsByCollections = async () => {
6
- const items = await getMediaItems()
7
- items.forEach((item) => {
8
- item.data.collections?.forEach(({ collection }) => {
9
- if (!itemsByCollections.has(collection.id)) {
10
- itemsByCollections.set(collection.id, [])
11
- }
12
- itemsByCollections.get(collection.id)?.push(item)
13
- })
14
- })
15
- itemsByCollections.forEach((entries, collectionId) =>
16
- entries.sort((a, b) => compareMediaCollectionItems(a, b, collectionId)),
17
- )
18
- }
19
-
20
- let isInitialized = false
21
- const itemsByCollections = new Map<string, MediaItemEntry[]>()
22
-
23
- export const getCollectionItems = async (collectionId: string) => {
24
- if (!isInitialized) {
25
- isInitialized = true
26
- await groupItemsByCollections()
27
- }
28
- return itemsByCollections.get(collectionId) ?? []
29
- }