@content-collections/core 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.
package/README.md CHANGED
@@ -22,35 +22,16 @@ Transform your content into type-safe data collections. Eliminate the need for m
22
22
 
23
23
  ## Installation
24
24
 
25
- 1. Install required packages:
25
+ Content Collections offers a variety of adapters that seamlessly integrate with popular web frameworks. The installation process depends on the chosen adapter:
26
26
 
27
- ```bash
28
- pnpm add -D @content-collections/core @content-collections/cli concurrently
29
- ```
30
-
31
- 1. Add path alias to your `tsconfig.json`:
32
-
33
- ```json
34
- {
35
- "compilerOptions": {
36
- // ...
37
- "paths": {
38
- "content-collections": ["./.content-collections/generated"]
39
- }
40
- }
41
- }
42
- ```
27
+ - [Next.js](https://www.content-collections.dev/docs/quickstart/next)
28
+ - [Qwik](https://www.content-collections.dev/docs/quickstart/qwik)
29
+ - [Remix (Vite)](https://www.content-collections.dev/docs/quickstart/remix-vite)
30
+ - [Solid Start](https://www.content-collections.dev/docs/quickstart/solid)
31
+ - [Svelte Kit](https://www.content-collections.dev/docs/quickstart/svelte-kit)
32
+ - [Vite](https://www.content-collections.dev/docs/quickstart/vite)
43
33
 
44
- 1. Update your scripts in `package.json`:
45
-
46
- ```json
47
- {
48
- "scripts": {
49
- "dev": "concurrently 'content-collections watch' 'build-scripts dev'",
50
- "build": "content-collections build && build-scripts build"
51
- }
52
- }
53
- ```
34
+ If your framework is not listed, you can still use Content Collections by using the [CLI](https://www.content-collections.dev/docs/quickstart/cli). Please open a ticket if you want to see your framework listed.
54
35
 
55
36
  ## Usage
56
37
 
@@ -108,7 +89,14 @@ Transform your content into type-safe data collections. Eliminate the need for m
108
89
  }
109
90
  ```
110
91
 
111
- For a more detailed guide, please refer to the [documentation](https://content-collections.dev/docs/guides/getting-started).
92
+ Please note that the example above shows only the very basics of Content Collections and it does not cover content transformation.
93
+ Content Collections does not transform content like markdown or mdx by default.
94
+ But it has packages which can do that for you:
95
+
96
+ - [@content-collections/markdown](https://www.content-collections.dev/docs/samples/markdown)
97
+ - [@content-collections/mdx](https://www.content-collections.dev/docs/samples/mdx)
98
+
99
+ If you want to see more examples and use cases, please refer to the [documentation](https://content-collections.dev/docs).
112
100
 
113
101
  ## Sponsors
114
102
 
@@ -119,6 +107,10 @@ For a more detailed guide, please refer to the [documentation](https://content-c
119
107
  <img alt="supastarter" src="./assets/sponsors/supastarter/light.svg" height="64">
120
108
  </picture>
121
109
  </a>
110
+ &nbsp;&nbsp;
111
+ <a href="https://cloudogu.com">
112
+ <img src="./assets/sponsors/cloudogu.png" alt="Cloudogu GmbH" height="64">
113
+ </a>
122
114
 
123
115
  ### [Become a sponsor](https://github.com/sponsors/sdorra)
124
116
 
package/dist/index.d.ts CHANGED
@@ -52,6 +52,10 @@ type Schema<TParser extends Parser | undefined, TShape extends ZodRawShape> = z$
52
52
  type Context = {
53
53
  documents<TCollection extends AnyCollection>(collection: TCollection): Array<Schema<TCollection["parser"], TCollection["schema"]>>;
54
54
  cache: CacheFn;
55
+ collection: {
56
+ name: string;
57
+ directory: string;
58
+ };
55
59
  };
56
60
  type Z = typeof z$1;
57
61
  type CollectionRequest<TName extends string, TShape extends ZodRawShape, TParser, TSchema, TTransformResult, TDocument> = {
@@ -62,6 +66,7 @@ type CollectionRequest<TName extends string, TShape extends ZodRawShape, TParser
62
66
  transform?: (data: TSchema, context: Context) => TTransformResult;
63
67
  directory: string;
64
68
  include: string | string[];
69
+ exclude?: string | string[];
65
70
  onSuccess?: (documents: Array<TDocument>) => void | Promise<void>;
66
71
  };
67
72
  type Collection<TName extends string, TShape extends ZodRawShape, TParser extends Parser, TSchema, TTransformResult, TDocument> = Omit<CollectionRequest<TName, TShape, TParser, TSchema, TTransformResult, TDocument>, "schema"> & {
@@ -86,6 +91,9 @@ type AnyConfiguration = Configuration<Array<AnyCollection>>;
86
91
  declare function defineConfig<TConfig extends AnyConfiguration>(config: TConfig): TConfig;
87
92
 
88
93
  type Modification = "create" | "update" | "delete";
94
+ type Document = {
95
+ _meta: Meta;
96
+ };
89
97
  type CollectionFile = {
90
98
  data: {
91
99
  content?: string;
@@ -192,4 +200,4 @@ declare function createBuilder(configurationPath: string, options?: Options): Pr
192
200
  }>;
193
201
  type Builder = Awaited<ReturnType<typeof createBuilder>>;
194
202
 
195
- export { AnyCollection, AnyConfiguration, Builder, BuilderEvents, CollectError, Collection, CollectionRequest, Configuration, ConfigurationError, Context, GetTypeByName, Meta, Modification, Schema, TransformError, createBuilder, defineCollection, defineConfig };
203
+ export { AnyCollection, AnyConfiguration, Builder, BuilderEvents, CollectError, Collection, CollectionRequest, Configuration, ConfigurationError, Context, Document, GetTypeByName, Meta, Modification, Schema, TransformError, createBuilder, defineCollection, defineConfig };
package/dist/index.js CHANGED
@@ -45,7 +45,7 @@ import path from "path";
45
45
  // package.json
46
46
  var package_default = {
47
47
  name: "@content-collections/core",
48
- version: "0.4.1",
48
+ version: "0.5.0",
49
49
  type: "module",
50
50
  main: "dist/index.js",
51
51
  types: "./dist/index.d.ts",
@@ -68,25 +68,25 @@ var package_default = {
68
68
  postpack: "rm -f ./README.md"
69
69
  },
70
70
  devDependencies: {
71
- "@types/micromatch": "^4.0.6",
71
+ "@types/micromatch": "^4.0.7",
72
72
  "@types/node": "^20.9.0",
73
73
  "@types/pluralize": "^0.0.33",
74
- "@vitest/coverage-v8": "^1.1.0",
74
+ "@vitest/coverage-v8": "^1.5.0",
75
75
  tsup: "^7.2.0",
76
76
  tsx: "^4.1.1",
77
- typescript: "^5.3.3",
78
- vitest: "^1.1.0"
77
+ typescript: "^5.4.5",
78
+ vitest: "^1.5.0"
79
79
  },
80
80
  dependencies: {
81
- "@parcel/watcher": "^2.3.0",
81
+ "@parcel/watcher": "^2.4.1",
82
82
  camelcase: "^8.0.0",
83
- esbuild: "^0.19.5",
83
+ esbuild: "^0.20.2",
84
84
  "fast-glob": "^3.3.2",
85
85
  "gray-matter": "^4.0.3",
86
86
  micromatch: "^4.0.5",
87
87
  pluralize: "^8.0.0",
88
- yaml: "^2.3.4",
89
- zod: "^3.22.4"
88
+ yaml: "^2.4.1",
89
+ zod: "^3.22.5"
90
90
  }
91
91
  };
92
92
 
@@ -245,12 +245,23 @@ function createCollector(emitter, baseDirectory = ".") {
245
245
  return null;
246
246
  }
247
247
  }
248
+ function createIgnorePattern(collection) {
249
+ if (collection.exclude) {
250
+ if (Array.isArray(collection.exclude)) {
251
+ return collection.exclude;
252
+ } else {
253
+ return [collection.exclude];
254
+ }
255
+ }
256
+ return void 0;
257
+ }
248
258
  async function resolveCollection(collection) {
249
259
  const collectionDirectory = path2.join(baseDirectory, collection.directory);
250
260
  const filePaths = await fg(collection.include, {
251
261
  cwd: collectionDirectory,
252
262
  onlyFiles: true,
253
- absolute: false
263
+ absolute: false,
264
+ ignore: createIgnorePattern(collection)
254
265
  });
255
266
  const promises = filePaths.map(
256
267
  (filePath) => collectFile(collection, filePath)
@@ -438,18 +449,22 @@ function createTransformer(emitter, cacheManager) {
438
449
  documents: (await Promise.all(promises)).filter(isDefined)
439
450
  };
440
451
  }
441
- function createContext(collections, cache) {
452
+ function createContext(collections, collection, cache) {
442
453
  return {
443
- documents: (collection) => {
444
- const resolved = collections.find((c) => c.name === collection.name);
454
+ documents: (collection2) => {
455
+ const resolved = collections.find((c) => c.name === collection2.name);
445
456
  if (!resolved) {
446
457
  throw new TransformError(
447
458
  "Configuration",
448
- `Collection ${collection.name} not found, do you have registered it in your configuration?`
459
+ `Collection ${collection2.name} not found, do you have registered it in your configuration?`
449
460
  );
450
461
  }
451
462
  return resolved.documents.map((doc) => doc.document);
452
463
  },
464
+ collection: {
465
+ name: collection.name,
466
+ directory: collection.directory
467
+ },
453
468
  cache: cache.cacheFn
454
469
  };
455
470
  }
@@ -461,7 +476,7 @@ function createTransformer(emitter, cacheManager) {
461
476
  collection.name,
462
477
  doc.document._meta.path
463
478
  );
464
- const context = createContext(collections, cache);
479
+ const context = createContext(collections, collection, cache);
465
480
  try {
466
481
  const document = await collection.transform(doc.document, context);
467
482
  docs.push({
@@ -547,7 +562,9 @@ function createSynchronizer(readCollectionFile, collections, baseDirectory = "."
547
562
  relativePath
548
563
  };
549
564
  }).filter(({ collection, relativePath }) => {
550
- return micromatch.isMatch(relativePath, collection.include);
565
+ return micromatch.isMatch(relativePath, collection.include, {
566
+ ignore: collection.exclude
567
+ });
551
568
  });
552
569
  }
553
570
  function deleted(filePath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@content-collections/core",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -16,25 +16,25 @@
16
16
  "README.md"
17
17
  ],
18
18
  "devDependencies": {
19
- "@types/micromatch": "^4.0.6",
19
+ "@types/micromatch": "^4.0.7",
20
20
  "@types/node": "^20.9.0",
21
21
  "@types/pluralize": "^0.0.33",
22
- "@vitest/coverage-v8": "^1.1.0",
22
+ "@vitest/coverage-v8": "^1.5.0",
23
23
  "tsup": "^7.2.0",
24
24
  "tsx": "^4.1.1",
25
- "typescript": "^5.3.3",
26
- "vitest": "^1.1.0"
25
+ "typescript": "^5.4.5",
26
+ "vitest": "^1.5.0"
27
27
  },
28
28
  "dependencies": {
29
- "@parcel/watcher": "^2.3.0",
29
+ "@parcel/watcher": "^2.4.1",
30
30
  "camelcase": "^8.0.0",
31
- "esbuild": "^0.19.5",
31
+ "esbuild": "^0.20.2",
32
32
  "fast-glob": "^3.3.2",
33
33
  "gray-matter": "^4.0.3",
34
34
  "micromatch": "^4.0.5",
35
35
  "pluralize": "^8.0.0",
36
- "yaml": "^2.3.4",
37
- "zod": "^3.22.4"
36
+ "yaml": "^2.4.1",
37
+ "zod": "^3.22.5"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup src/index.ts --format esm --dts -d dist",