Skip to content

Commit

Permalink
CLean up types
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Jul 9, 2024
1 parent a36548c commit c7c68a8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
8 changes: 2 additions & 6 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type {
} from '../transitions/events.js';
import type { DeepPartial, OmitIndexSignature, Simplify } from '../type-utils.js';
import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
import type { DataEntry } from '../content/data-store.js';
import type { DataEntry, RenderedContent } from '../content/data-store.js';

export type { AstroIntegrationLogger, ToolbarServerHelpers };

Expand Down Expand Up @@ -2277,11 +2277,7 @@ export type DataEntryModule = {
};
};

export interface RenderResult {
code: string;
metadata?: Record<string, any>;
}
export type RenderFunction = (entry: DataEntry) => Promise<RenderResult>;
export type RenderFunction = (entry: DataEntry) => Promise<RenderedContent>;

export interface ContentEntryType {
extensions: string[];
Expand Down
15 changes: 7 additions & 8 deletions packages/astro/src/content/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { promises as fs, type PathLike, existsSync } from 'fs';

const SAVE_DEBOUNCE_MS = 500;

export interface RenderedContent {
html: string;
metadata?: Record<string, unknown>;
}

export interface DataEntry {
id: string;
data: Record<string, unknown>;
filePath?: string;
body?: string;
digest?: number | string;
rendered?: {
html: string;
metadata?: Record<string, unknown>;
};
rendered?: RenderedContent;
}

export class DataStore {
Expand Down Expand Up @@ -207,10 +209,7 @@ export interface ScopedDataStore {
body?: string;
filePath?: string;
digest?: number | string;
rendered?: {
html: string;
metadata?: Record<string, unknown>;
};
rendered?: RenderedContent;
}) => boolean;
values: () => Array<DataEntry>;
keys: () => Array<string>;
Expand Down
7 changes: 2 additions & 5 deletions packages/astro/src/content/loaders/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function glob(globOptions: GlobOptions): Loader {
render = await entryType.getRenderFunction(settings);
renderFunctionByContentType.set(entryType, render);
}
const renderResult = await render({
const rendered = await render({
id,
data: parsedData,
body,
Expand All @@ -125,10 +125,7 @@ export function glob(globOptions: GlobOptions): Loader {
body,
filePath,
digest,
rendered: {
html: renderResult.code,
metadata: renderResult.metadata,
},
rendered,
});
} else {
store.set({ id, data: parsedData, body, filePath, digest });
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/content/loaders/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { FSWatcher } from 'vite';
import type { ZodSchema } from 'zod';
import type { AstroIntegrationLogger, AstroSettings } from '../../@types/astro.js';
import type { MetaStore, ScopedDataStore } from '../data-store.js';
import type { XXHashAPI } from 'xxhash-wasm';

export interface ParseDataOptions {
/** The ID of the entry. Unique per collection */
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/content/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function createGetCollection({
return [...store.values<DataEntry>(collection)].map((entry) => ({
...entry,
collection,
render: async () => renderEntry(entry),
render: () => renderEntry(entry),
}));
} else {
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -149,7 +149,7 @@ export function createGetEntryBySlug({
return {
...entry,
collection,
render: async () => renderEntry(entry),
render: () => renderEntry(entry),
};
}

Expand Down Expand Up @@ -269,7 +269,7 @@ export function createGetEntry({
return {
...entry,
collection,
render: async () => render({ ...entry, id: lookupId, collection }),
render: () => renderEntry(entry),
} as DataEntryResult | ContentEntryResult;
}

Expand Down
9 changes: 6 additions & 3 deletions packages/astro/src/vite-plugin-markdown/content-entry-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ export const markdownContentEntryType: ContentEntryType = {
return async function renderToString(entry) {
if (!entry.body) {
return {
code: '',
html: '',
};
}
const res = await processor.render(entry.body, {
const result = await processor.render(entry.body, {
frontmatter: entry.data,
});
return res;
return {
html: result.code,
metadata: result.metadata,
};
};
},
};

0 comments on commit c7c68a8

Please sign in to comment.