Skip to content

Commit

Permalink
Always regenerate content layer on sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Jan 15, 2025
1 parent 9a57a0b commit 43d42fc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
17 changes: 8 additions & 9 deletions packages/astro/src/content/content-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export interface ContentLayerOptions {
watcher?: FSWatcher;
}

export function getAstroConfigDigest(config: AstroConfig) {
const { vite, integrations, adapter, ...hashableConfig } = config;
return safeStringify(hashableConfig);
}

export class ContentLayer {
#logger: Logger;
Expand Down Expand Up @@ -146,9 +142,6 @@ export class ContentLayer {
return this.#queue.add(() => this.#doSync(options));
}

configMatches(config: AstroConfig) {
return getAstroConfigDigest(config) === getAstroConfigDigest(this.#settings.config);
}

async #doSync(options: RefreshContentOptions) {
let contentConfig = globalContentConfigObserver.get();
Expand Down Expand Up @@ -184,8 +177,14 @@ export class ContentLayer {
}

logger.info('Syncing content');
const astroConfigDigest = getAstroConfigDigest(this.#settings.config);

const {
vite: _vite,
integrations: _integrations,
adapter: _adapter,
...hashableConfig
} = this.#settings.config;

const astroConfigDigest = safeStringify(hashableConfig);
const { digest: currentConfigDigest } = contentConfig.config;
this.#lastConfigDigest = currentConfigDigest;

Expand Down
47 changes: 20 additions & 27 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type SyncOptions = {
};
manifest: ManifestData;
command: 'build' | 'dev' | 'sync';
watcher?: FSWatcher
watcher?: FSWatcher;
};

export default async function sync(
Expand Down Expand Up @@ -121,7 +121,7 @@ export async function syncInternal({
force,
manifest,
command,
watcher
watcher,
}: SyncOptions): Promise<void> {
const isDev = command === 'dev';
if (force) {
Expand All @@ -133,34 +133,27 @@ export async function syncInternal({
if (!skip?.content) {
await syncContentCollections(settings, { mode, fs, logger, manifest });
settings.timer.start('Sync content layer');
let contentLayer = globalContentLayer.get();

if(contentLayer && !contentLayer.configMatches(settings.config)) {
logger.info('content', 'Astro config changed: reloading content layer.');
contentLayer = null;
let store: MutableDataStore | undefined;
try {
const dataStoreFile = getDataStoreFile(settings, isDev);
store = await MutableDataStore.fromFile(dataStoreFile);
} catch (err: any) {
logger.error('content', err.message);
}
if (!store) {
logger.error('content', 'Failed to load content store');
return;
}
if (!contentLayer) {
let store: MutableDataStore | undefined;
try {
const dataStoreFile = getDataStoreFile(settings, isDev);
store = await MutableDataStore.fromFile(dataStoreFile);
} catch (err: any) {
logger.error('content', err.message);
}
if (!store) {
logger.error('content', 'Failed to load content store');
return;
}

contentLayer = globalContentLayer.init({
settings,
logger,
store,
watcher
});
if(watcher) {
contentLayer.watchContentConfig();
}
const contentLayer = globalContentLayer.init({
settings,
logger,
store,
watcher,
});
if (watcher) {
contentLayer.watchContentConfig();
}
await contentLayer.sync();
if (!skip?.cleanup) {
Expand Down

0 comments on commit 43d42fc

Please sign in to comment.