From aa1db498312a678ce170402eea9f01775a548c4b Mon Sep 17 00:00:00 2001
From: Matt Kane
Date: Mon, 24 Jun 2024 17:24:28 +0100
Subject: [PATCH 01/19] wip
---
packages/astro/src/content/utils.ts | 1 +
.../fixtures/content-layer/astro.config.mjs | 6 +++
.../test/fixtures/content-layer/package.json | 9 +++++
.../content-layer/src/components/H2.astro | 4 ++
.../content-layer/src/components/H3.astro | 2 +
.../src/components/LayoutProp.astro | 39 +++++++++++++++++++
.../src/components/WithScripts.astro | 11 ++++++
.../content-layer/src/content/blog/one.md | 5 +++
.../src/content/blog/with-layout-prop.md | 9 +++++
.../content-layer/src/content/config.ts | 10 +++++
.../content-layer/src/loaders/post-loader.ts | 25 ++++++++++++
.../content-layer/src/pages/index.astro | 19 +++++++++
.../pages/launch-week-component-scripts.astro | 14 +++++++
.../pages/launch-week-components-export.astro | 14 +++++++
.../content-layer/src/pages/launch-week.astro | 14 +++++++
.../src/pages/sort-blog-collection.astro | 22 +++++++++++
.../src/pages/with-layout-prop.astro | 9 +++++
packages/astro/types/content.d.ts | 37 +++++++++++++++++-
18 files changed, 249 insertions(+), 1 deletion(-)
create mode 100644 packages/astro/test/fixtures/content-layer/astro.config.mjs
create mode 100644 packages/astro/test/fixtures/content-layer/package.json
create mode 100644 packages/astro/test/fixtures/content-layer/src/components/H2.astro
create mode 100644 packages/astro/test/fixtures/content-layer/src/components/H3.astro
create mode 100644 packages/astro/test/fixtures/content-layer/src/components/LayoutProp.astro
create mode 100644 packages/astro/test/fixtures/content-layer/src/components/WithScripts.astro
create mode 100644 packages/astro/test/fixtures/content-layer/src/content/blog/one.md
create mode 100644 packages/astro/test/fixtures/content-layer/src/content/blog/with-layout-prop.md
create mode 100644 packages/astro/test/fixtures/content-layer/src/content/config.ts
create mode 100644 packages/astro/test/fixtures/content-layer/src/loaders/post-loader.ts
create mode 100644 packages/astro/test/fixtures/content-layer/src/pages/index.astro
create mode 100644 packages/astro/test/fixtures/content-layer/src/pages/launch-week-component-scripts.astro
create mode 100644 packages/astro/test/fixtures/content-layer/src/pages/launch-week-components-export.astro
create mode 100644 packages/astro/test/fixtures/content-layer/src/pages/launch-week.astro
create mode 100644 packages/astro/test/fixtures/content-layer/src/pages/sort-blog-collection.astro
create mode 100644 packages/astro/test/fixtures/content-layer/src/pages/with-layout-prop.astro
diff --git a/packages/astro/src/content/utils.ts b/packages/astro/src/content/utils.ts
index 2bbe40fbe9a4..f6fe76c8e4c8 100644
--- a/packages/astro/src/content/utils.ts
+++ b/packages/astro/src/content/utils.ts
@@ -406,6 +406,7 @@ export async function loadContentConfig({
unparsedConfig = await viteServer.ssrLoadModule(configPathname);
const config = contentConfigParser.safeParse(unparsedConfig);
+ console.log({config});
if (config.success) {
return config.data;
} else {
diff --git a/packages/astro/test/fixtures/content-layer/astro.config.mjs b/packages/astro/test/fixtures/content-layer/astro.config.mjs
new file mode 100644
index 000000000000..d69e57975a64
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/astro.config.mjs
@@ -0,0 +1,6 @@
+import mdx from '@astrojs/mdx';
+import { defineConfig } from 'astro/config';
+
+export default defineConfig({
+ integrations: [mdx()],
+});
diff --git a/packages/astro/test/fixtures/content-layer/package.json b/packages/astro/test/fixtures/content-layer/package.json
new file mode 100644
index 000000000000..3be40eb87157
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "@test/content",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "astro": "workspace:*",
+ "@astrojs/mdx": "workspace:*"
+ }
+}
diff --git a/packages/astro/test/fixtures/content-layer/src/components/H2.astro b/packages/astro/test/fixtures/content-layer/src/components/H2.astro
new file mode 100644
index 000000000000..d1ad359c2ee1
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/components/H2.astro
@@ -0,0 +1,4 @@
+---
+---
+
+
diff --git a/packages/astro/test/fixtures/content-layer/src/components/H3.astro b/packages/astro/test/fixtures/content-layer/src/components/H3.astro
new file mode 100644
index 000000000000..fa476e929eae
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/components/H3.astro
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/packages/astro/test/fixtures/content-layer/src/components/LayoutProp.astro b/packages/astro/test/fixtures/content-layer/src/components/LayoutProp.astro
new file mode 100644
index 000000000000..a2954162a396
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/components/LayoutProp.astro
@@ -0,0 +1,39 @@
+---
+import { CollectionEntry, getCollection } from 'astro:content';
+import H3 from './H3.astro'
+// Test for recursive `getCollection()` calls
+const blog = await getCollection('blog');
+
+type Props = {
+ content: CollectionEntry<'blog'>['data'];
+};
+
+const {
+ content: { title },
+} = Astro.props;
+---
+
+
+
+
+
+
+
+ With Layout Prop
+
+
+ {title}
+ H3 inserted in the layout
+
+
+
+
+
diff --git a/packages/astro/test/fixtures/content-layer/src/components/WithScripts.astro b/packages/astro/test/fixtures/content-layer/src/components/WithScripts.astro
new file mode 100644
index 000000000000..e37694eaf1f0
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/components/WithScripts.astro
@@ -0,0 +1,11 @@
+Hoisted script didn't update me :(
+
+Inline script didn't update me :(
+
+
+
+
diff --git a/packages/astro/test/fixtures/content-layer/src/content/blog/one.md b/packages/astro/test/fixtures/content-layer/src/content/blog/one.md
new file mode 100644
index 000000000000..f4293f0a5ee5
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/content/blog/one.md
@@ -0,0 +1,5 @@
+---
+title: Hello world
+description: Just a demo
+---
+This is a post
diff --git a/packages/astro/test/fixtures/content-layer/src/content/blog/with-layout-prop.md b/packages/astro/test/fixtures/content-layer/src/content/blog/with-layout-prop.md
new file mode 100644
index 000000000000..ce8a866cb9c0
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/content/blog/with-layout-prop.md
@@ -0,0 +1,9 @@
+---
+title: With Layout Prop
+description: Use a layout prop in a content collection
+layout: "../../components/LayoutProp.astro"
+---
+
+## Content with a layout prop
+
+Sure, why not?
diff --git a/packages/astro/test/fixtures/content-layer/src/content/config.ts b/packages/astro/test/fixtures/content-layer/src/content/config.ts
new file mode 100644
index 000000000000..440b6511e0cb
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/content/config.ts
@@ -0,0 +1,10 @@
+import { defineCollection, z } from 'astro:content';
+import { loader } from '../loaders/post-loader.js';
+
+const blog = defineCollection({
+ type: "experimental_content",
+ name: "blog",
+ loader: loader({ url: "https://jsonplaceholder.typicode.com/posts" }),
+});
+
+export const collections = { blog };
diff --git a/packages/astro/test/fixtures/content-layer/src/loaders/post-loader.ts b/packages/astro/test/fixtures/content-layer/src/loaders/post-loader.ts
new file mode 100644
index 000000000000..584aa6616163
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/loaders/post-loader.ts
@@ -0,0 +1,25 @@
+import type { Loader } from 'astro:content';
+
+export interface PostLoaderConfig {
+ url: string;
+}
+
+export function loader(config:PostLoaderConfig): Loader {
+ return {
+ name: "post-loader",
+ load: async ({
+ store, collection, cache
+ }) => {
+
+ const posts = await fetch(config.url)
+ .then((res) => res.json());
+
+ store.clear(collection);
+
+ for (const post of posts) {
+ store.set(collection, post.id, post);
+ }
+
+ },
+ };
+}
diff --git a/packages/astro/test/fixtures/content-layer/src/pages/index.astro b/packages/astro/test/fixtures/content-layer/src/pages/index.astro
new file mode 100644
index 000000000000..a024728577e7
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/pages/index.astro
@@ -0,0 +1,19 @@
+---
+import { getCollection } from 'astro:content';
+
+const blog = await getCollection('blog');
+---
+
+
+ Index
+
+
+ Blog Posts
+
+
+ {blog.map(post => (
+ - { post.data.title }
+ ))}
+
+
+
diff --git a/packages/astro/test/fixtures/content-layer/src/pages/launch-week-component-scripts.astro b/packages/astro/test/fixtures/content-layer/src/pages/launch-week-component-scripts.astro
new file mode 100644
index 000000000000..3936b2f8d082
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/pages/launch-week-component-scripts.astro
@@ -0,0 +1,14 @@
+---
+import { getEntryBySlug } from 'astro:content';
+
+const entry = await getEntryBySlug('blog', 'promo/launch-week-component-scripts');
+const { Content } = await entry.render();
+---
+
+
+ Launch Week
+
+
+
+
+
diff --git a/packages/astro/test/fixtures/content-layer/src/pages/launch-week-components-export.astro b/packages/astro/test/fixtures/content-layer/src/pages/launch-week-components-export.astro
new file mode 100644
index 000000000000..463e6519129c
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/pages/launch-week-components-export.astro
@@ -0,0 +1,14 @@
+---
+import { getEntryBySlug } from 'astro:content';
+
+const entry = await getEntryBySlug('blog', 'promo/launch-week-components-export');
+const { Content } = await entry.render();
+---
+
+
+ Launch Week
+
+
+
+
+
diff --git a/packages/astro/test/fixtures/content-layer/src/pages/launch-week.astro b/packages/astro/test/fixtures/content-layer/src/pages/launch-week.astro
new file mode 100644
index 000000000000..e7a992e2dfe4
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/pages/launch-week.astro
@@ -0,0 +1,14 @@
+---
+import { getEntryBySlug } from 'astro:content';
+
+const entry = await getEntryBySlug('blog', 'promo/launch-week');
+const { Content } = await entry.render();
+---
+
+
+ Launch Week
+
+
+
+
+
diff --git a/packages/astro/test/fixtures/content-layer/src/pages/sort-blog-collection.astro b/packages/astro/test/fixtures/content-layer/src/pages/sort-blog-collection.astro
new file mode 100644
index 000000000000..5426068197ad
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/pages/sort-blog-collection.astro
@@ -0,0 +1,22 @@
+---
+import { getCollection } from 'astro:content';
+
+const blog = await getCollection('blog');
+
+// Sort descending by title, make sure mutating `blog` doesn't mutate other pages that call `getCollection` too
+blog.sort((a, b) => a.data.title < b.data.title ? 1 : -1)
+---
+
+
+ Index
+
+
+ Blog Posts
+
+
+ {blog.map(post => (
+ - { post.data.title }
+ ))}
+
+
+
diff --git a/packages/astro/test/fixtures/content-layer/src/pages/with-layout-prop.astro b/packages/astro/test/fixtures/content-layer/src/pages/with-layout-prop.astro
new file mode 100644
index 000000000000..4cbb87624267
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer/src/pages/with-layout-prop.astro
@@ -0,0 +1,9 @@
+---
+import { getEntryBySlug } from 'astro:content';
+import H3 from '../components/H3.astro';
+
+const entry = await getEntryBySlug('blog', 'with-layout-prop');
+const { Content } = await entry.render();
+---
+H3 directly inserted to the page
+
\ No newline at end of file
diff --git a/packages/astro/types/content.d.ts b/packages/astro/types/content.d.ts
index e09bda61844b..3dda00c43c61 100644
--- a/packages/astro/types/content.d.ts
+++ b/packages/astro/types/content.d.ts
@@ -32,6 +32,40 @@ declare module 'astro:content' {
export type SchemaContext = { image: ImageFunction };
+ export interface DataStore{
+ get: (collection: string, key: string) => T | undefined;
+ entries: (collection: string) => Array<[key: string, T]>;
+ set: (collection: string, key: string, value: T) => void;
+ delete: (collection: string, key: string) => void;
+ clear: (collection: string) => void;
+ }
+
+ export interface LoaderContext {
+ collection: string;
+ // A database abstraction to store the actual data
+ store: DataStore;
+ // A simple KV store, designed for things like sync tokens
+ // Persisted to disk
+ cache: any;
+ }
+
+ export interface Loader {
+ // Name of the loader, e.g. the npm package name
+ name: string;
+ // Do the actual loading of the data
+ load: (context: LoaderContext) => Promise;
+ // Allow a loader to define its own schema
+ schema?: S | Promise | ((context: SchemaContext) => S | Promise);
+ // Render content from the store
+ render?: (entry: any) => AstroComponentFactory;
+ }
+
+ type ContentCollectionV2Config = {
+ type: 'experimental_content';
+ name: string;
+ loader: Loader;
+ };
+
type DataCollectionConfig = {
type: 'data';
schema?: S | ((context: SchemaContext) => S);
@@ -44,7 +78,8 @@ declare module 'astro:content' {
export type CollectionConfig =
| ContentCollectionConfig
- | DataCollectionConfig;
+ | DataCollectionConfig
+ | ContentCollectionV2Config;
export function defineCollection(
input: CollectionConfig
From a7639e361aecf7af00e63154d00521e7ed93aa4c Mon Sep 17 00:00:00 2001
From: Matt Kane
Date: Tue, 25 Jun 2024 08:54:02 +0100
Subject: [PATCH 02/19] wip
---
packages/astro/src/content/data-store.ts | 72 +++++++++++++++++++
packages/astro/src/content/loaders.ts | 29 ++++++++
packages/astro/src/content/runtime.ts | 1 +
packages/astro/src/content/types-generator.ts | 10 ++-
packages/astro/src/content/utils.ts | 14 +++-
packages/astro/src/core/build/index.ts | 4 +-
packages/astro/src/core/sync/index.ts | 2 +
.../test/fixtures/content-layer/package.json | 2 +-
.../content-layer/src/content/config.ts | 2 +-
.../content-layer/src/loaders/post-loader.ts | 3 +-
.../content-layer/src/pages/index.astro | 2 +-
.../pages/launch-week-component-scripts.astro | 14 ----
.../pages/launch-week-components-export.astro | 14 ----
.../content-layer/src/pages/launch-week.astro | 14 ----
.../src/pages/sort-blog-collection.astro | 22 ------
.../src/pages/with-layout-prop.astro | 9 ---
packages/astro/types/content.d.ts | 7 +-
17 files changed, 137 insertions(+), 84 deletions(-)
create mode 100644 packages/astro/src/content/data-store.ts
create mode 100644 packages/astro/src/content/loaders.ts
delete mode 100644 packages/astro/test/fixtures/content-layer/src/pages/launch-week-component-scripts.astro
delete mode 100644 packages/astro/test/fixtures/content-layer/src/pages/launch-week-components-export.astro
delete mode 100644 packages/astro/test/fixtures/content-layer/src/pages/launch-week.astro
delete mode 100644 packages/astro/test/fixtures/content-layer/src/pages/sort-blog-collection.astro
delete mode 100644 packages/astro/test/fixtures/content-layer/src/pages/with-layout-prop.astro
diff --git a/packages/astro/src/content/data-store.ts b/packages/astro/src/content/data-store.ts
new file mode 100644
index 000000000000..d53705c2a62b
--- /dev/null
+++ b/packages/astro/src/content/data-store.ts
@@ -0,0 +1,72 @@
+export class DataStore {
+ #collections = new Map>();
+ constructor() {
+ this.#collections = new Map();
+ }
+ get(collectionName: string) {
+ return this.#collections.get(collectionName);
+ }
+ entries(collectionName: string): IterableIterator<[id: string, any]> {
+ const collection = this.#collections.get(collectionName) ?? new Map();
+ return collection.entries();
+ }
+ set(collectionName: string, key: string, value: any) {
+ const collection = this.#collections.get(collectionName) ?? new Map();
+ collection.set(key, value);
+ this.#collections.set(collectionName, collection);
+ }
+ delete(collectionName: string, key: string) {
+ const collection = this.#collections.get(collectionName);
+ if (collection) {
+ collection.delete(key);
+ }
+ }
+ clear(collectionName: string) {
+ this.#collections.delete(collectionName);
+ }
+
+ has(collectionName: string, key: string) {
+ const collection = this.#collections.get(collectionName);
+ if (collection) {
+ return collection.has(key);
+ }
+ return false;
+ }
+
+ scopedStore(collectionName: string): ScopedDataStore {
+ return {
+ get: (key: string) => this.get(collectionName)?.get(key),
+ entries: () => this.entries(collectionName),
+ set: (key: string, value: any) => this.set(collectionName, key, value),
+ delete: (key: string) => this.delete(collectionName, key),
+ clear: () => this.clear(collectionName),
+ has: (key: string) => this.has(collectionName, key),
+ };
+ }
+}
+
+export interface ScopedDataStore {
+ get: (key: string) => any;
+ entries: () => IterableIterator<[id: string, any]>;
+ set: (key: string, value: any) => void;
+ delete: (key: string) => void;
+ clear: () => void;
+ has: (key: string) => boolean;
+}
+
+function dataStoreSingleton() {
+ let instance: DataStore | undefined = undefined;
+ return {
+ get: () => {
+ if (!instance) {
+ instance = new DataStore();
+ }
+ return instance;
+ },
+ set: (store: DataStore) => {
+ instance = store;
+ },
+ };
+}
+
+export const globalDataStore = dataStoreSingleton();
diff --git a/packages/astro/src/content/loaders.ts b/packages/astro/src/content/loaders.ts
new file mode 100644
index 000000000000..f5a5fa7786d2
--- /dev/null
+++ b/packages/astro/src/content/loaders.ts
@@ -0,0 +1,29 @@
+import type { AstroSettings } from '../@types/astro.js';
+import type { Logger } from '../core/logger/core.js';
+import { globalDataStore, type DataStore } from './data-store.js';
+import { globalContentConfigObserver } from './utils.js';
+
+export async function syncDataLayer({
+ settings,
+ logger,
+ store = globalDataStore.get(),
+}: { settings: AstroSettings; logger: Logger; store?: DataStore }) {
+
+ const contentConfig = globalContentConfigObserver.get();
+ if (contentConfig?.status !== 'loaded') {
+ logger.debug('content', 'Content config not loaded, skipping sync');
+ return;
+ }
+ await Promise.all(
+ Object.entries(contentConfig.config.collections).map(async ([name, collection]) => {
+ if (collection.type !== 'experimental_data') {
+ return;
+ }
+ return collection.loader.load({
+ collection: name,
+ store: store.scopedStore(name),
+ cache: {},
+ });
+ })
+ );
+}
diff --git a/packages/astro/src/content/runtime.ts b/packages/astro/src/content/runtime.ts
index 6fd017c85c95..a34608e84018 100644
--- a/packages/astro/src/content/runtime.ts
+++ b/packages/astro/src/content/runtime.ts
@@ -57,6 +57,7 @@ export function createGetCollection({
}) {
return async function getCollection(collection: string, filter?: (entry: any) => unknown) {
let type: 'content' | 'data';
+ console.log({ collection, contentCollectionToEntryMap, dataCollectionToEntryMap });
if (collection in contentCollectionToEntryMap) {
type = 'content';
} else if (collection in dataCollectionToEntryMap) {
diff --git a/packages/astro/src/content/types-generator.ts b/packages/astro/src/content/types-generator.ts
index b970eadb9011..2a8e8b199acb 100644
--- a/packages/astro/src/content/types-generator.ts
+++ b/packages/astro/src/content/types-generator.ts
@@ -46,6 +46,10 @@ type CollectionEntryMap = {
| {
type: 'data';
entries: Record;
+ }
+ | {
+ type: 'experimental_data';
+ entries: Record;
};
};
@@ -400,6 +404,7 @@ async function writeContentFiles({
if (
collectionConfig?.type &&
collection.type !== 'unknown' &&
+ collectionConfig.type !== 'experimental_data' &&
collection.type !== collectionConfig.type
) {
viteServer.hot.send({
@@ -422,7 +427,7 @@ async function writeContentFiles({
});
return;
}
- const resolvedType: 'content' | 'data' =
+ const resolvedType: 'content' | 'data' | 'experimental_data' =
collection.type === 'unknown'
? // Add empty / unknown collections to the data type map by default
// This ensures `getCollection('empty-collection')` doesn't raise a type error
@@ -491,6 +496,9 @@ async function writeContentFiles({
}
}
break;
+ case 'experimental_data':
+ console.log('experimental_data', collectionKey);
+ break;
}
}
diff --git a/packages/astro/src/content/utils.ts b/packages/astro/src/content/utils.ts
index f6fe76c8e4c8..f5d4b599aefe 100644
--- a/packages/astro/src/content/utils.ts
+++ b/packages/astro/src/content/utils.ts
@@ -35,6 +35,19 @@ export const collectionConfigParser = z.union([
type: z.literal('data'),
schema: z.any().optional(),
}),
+ z.object({
+ type: z.literal('experimental_data'),
+ name: z.string(),
+ schema: z.undefined().optional(),
+ loader: z.object({
+ name: z.string(),
+ load: z.function(
+ z.tuple([z.object({ collection: z.string(), store: z.any(), cache: z.any() })], z.unknown())
+ ),
+ schema: z.any().optional(),
+ render: z.function(z.tuple([z.any()], z.unknown())).optional(),
+ }),
+ }),
]);
export const contentConfigParser = z.object({
@@ -406,7 +419,6 @@ export async function loadContentConfig({
unparsedConfig = await viteServer.ssrLoadModule(configPathname);
const config = contentConfigParser.safeParse(unparsedConfig);
- console.log({config});
if (config.success) {
return config.data;
} else {
diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts
index 50085d58132a..c4704f5eabcb 100644
--- a/packages/astro/src/core/build/index.ts
+++ b/packages/astro/src/core/build/index.ts
@@ -11,6 +11,7 @@ import type {
RuntimeMode,
} from '../../@types/astro.js';
import { injectImageEndpoint } from '../../assets/endpoint/config.js';
+import { syncDataLayer } from '../../content/loaders.js';
import { telemetry } from '../../events/index.js';
import { eventCliSession } from '../../events/session.js';
import {
@@ -32,7 +33,7 @@ import { collectPagesData } from './page-data.js';
import { staticBuild, viteBuild } from './static-build.js';
import type { StaticBuildOptions } from './types.js';
import { getTimeStat } from './util.js';
-
+import { globalDataStore } from '../../content/data-store.js';
export interface BuildOptions {
/**
* Teardown the compiler WASM instance after build. This can improve performance when
@@ -148,6 +149,7 @@ class AstroBuilder {
if (syncRet !== 0) {
return process.exit(syncRet);
}
+ await syncDataLayer({ settings: this.settings, logger: logger });
return { viteConfig };
}
diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts
index 0b4bd1af46d1..c30f293ae54b 100644
--- a/packages/astro/src/core/sync/index.ts
+++ b/packages/astro/src/core/sync/index.ts
@@ -6,6 +6,7 @@ import { type HMRPayload, createServer } from 'vite';
import type { AstroConfig, AstroInlineConfig, AstroSettings } from '../../@types/astro.js';
import { getPackage } from '../../cli/install-package.js';
import { createContentTypesGenerator } from '../../content/index.js';
+import { syncDataLayer } from '../../content/loaders.js';
import { globalContentConfigObserver } from '../../content/utils.js';
import { telemetry } from '../../events/index.js';
import { eventCliSession } from '../../events/session.js';
@@ -83,6 +84,7 @@ export default async function sync(
await dbPackage?.typegen?.(astroConfig);
const exitCode = await syncContentCollections(settings, { ...options, logger });
if (exitCode !== 0) return exitCode;
+ await syncDataLayer({ settings, logger });
logger.info(null, `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`);
return 0;
diff --git a/packages/astro/test/fixtures/content-layer/package.json b/packages/astro/test/fixtures/content-layer/package.json
index 3be40eb87157..fc73ce6f7ac7 100644
--- a/packages/astro/test/fixtures/content-layer/package.json
+++ b/packages/astro/test/fixtures/content-layer/package.json
@@ -1,5 +1,5 @@
{
- "name": "@test/content",
+ "name": "@test/content-layer",
"version": "0.0.0",
"private": true,
"dependencies": {
diff --git a/packages/astro/test/fixtures/content-layer/src/content/config.ts b/packages/astro/test/fixtures/content-layer/src/content/config.ts
index 440b6511e0cb..62bc51654c8f 100644
--- a/packages/astro/test/fixtures/content-layer/src/content/config.ts
+++ b/packages/astro/test/fixtures/content-layer/src/content/config.ts
@@ -2,7 +2,7 @@ import { defineCollection, z } from 'astro:content';
import { loader } from '../loaders/post-loader.js';
const blog = defineCollection({
- type: "experimental_content",
+ type: "experimental_data",
name: "blog",
loader: loader({ url: "https://jsonplaceholder.typicode.com/posts" }),
});
diff --git a/packages/astro/test/fixtures/content-layer/src/loaders/post-loader.ts b/packages/astro/test/fixtures/content-layer/src/loaders/post-loader.ts
index 584aa6616163..a7f139482416 100644
--- a/packages/astro/test/fixtures/content-layer/src/loaders/post-loader.ts
+++ b/packages/astro/test/fixtures/content-layer/src/loaders/post-loader.ts
@@ -10,7 +10,7 @@ export function loader(config:PostLoaderConfig): Loader {
load: async ({
store, collection, cache
}) => {
-
+ console.log('loading posts');
const posts = await fetch(config.url)
.then((res) => res.json());
@@ -19,7 +19,6 @@ export function loader(config:PostLoaderConfig): Loader {
for (const post of posts) {
store.set(collection, post.id, post);
}
-
},
};
}
diff --git a/packages/astro/test/fixtures/content-layer/src/pages/index.astro b/packages/astro/test/fixtures/content-layer/src/pages/index.astro
index a024728577e7..eef648122e82 100644
--- a/packages/astro/test/fixtures/content-layer/src/pages/index.astro
+++ b/packages/astro/test/fixtures/content-layer/src/pages/index.astro
@@ -12,7 +12,7 @@ const blog = await getCollection('blog');
{blog.map(post => (
- - { post.data.title }
+ - { post.data?.title }
))}
-
-
diff --git a/packages/astro/test/fixtures/content-layer/src/pages/launch-week-component-scripts.astro b/packages/astro/test/fixtures/content-layer/src/pages/launch-week-component-scripts.astro
deleted file mode 100644
index 3936b2f8d082..000000000000
--- a/packages/astro/test/fixtures/content-layer/src/pages/launch-week-component-scripts.astro
+++ /dev/null
@@ -1,14 +0,0 @@
----
-import { getEntryBySlug } from 'astro:content';
-
-const entry = await getEntryBySlug('blog', 'promo/launch-week-component-scripts');
-const { Content } = await entry.render();
----
-
-