Skip to content

Commit

Permalink
chore: debugging deployment issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chengpeiquan committed Oct 29, 2024
1 parent 8cf3cdf commit a8da300
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
63 changes: 39 additions & 24 deletions src/cache/content-cache/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
import { ContentFolder, type ListFolder } from '@/config/content-config'
import {
// ContentFolder,
type ListFolder,
} from '@/config/content-config'
import { type Locale } from '@/config/locale-config'
import {
type CacheMapKey,
// type CacheMapKey,
type ContentCacheItem,
getCacheMapKey,
} from '@/config/cache-config'
import article_en from './article-en.json'
import article_zh from './article-zh.json'
import cookbook_zh from './cookbook-zh.json'
// import article_en from './article-en.json'
// import article_zh from './article-zh.json'
// import cookbook_zh from './cookbook-zh.json'

// const contentCacheMap = new Map<CacheMapKey, ContentCacheItem[]>([
// [
// getCacheMapKey(ContentFolder.Article, 'zh'),
// article_zh as ContentCacheItem[],
// ],
// [
// getCacheMapKey(ContentFolder.Article, 'en'),
// article_en as ContentCacheItem[],
// ],
// [
// getCacheMapKey(ContentFolder.Cookbook, 'zh'),
// cookbook_zh as ContentCacheItem[],
// ],
// ])

const contentCacheMap = new Map<CacheMapKey, ContentCacheItem[]>([
[
getCacheMapKey(ContentFolder.Article, 'zh'),
article_zh as ContentCacheItem[],
],
[
getCacheMapKey(ContentFolder.Article, 'en'),
article_en as ContentCacheItem[],
],
[
getCacheMapKey(ContentFolder.Cookbook, 'zh'),
cookbook_zh as ContentCacheItem[],
],
])
// export const getContentCache = (
// folder: ListFolder,
// locale: Locale,
// ): ContentCacheItem[] => {
// const key = getCacheMapKey(folder, locale)
// const cache = contentCacheMap.get(key)
// return cache || []
// }

export const getContentCache = (
export const getContentCache = async (
folder: ListFolder,
locale: Locale,
): ContentCacheItem[] => {
const key = getCacheMapKey(folder, locale)
const cache = contentCacheMap.get(key)
return cache || []
): Promise<ContentCacheItem[]> => {
try {
const key = getCacheMapKey(folder, locale)
return (await import(`./${key}.json`)).default || []
} catch (e) {
return []
}
}
4 changes: 2 additions & 2 deletions src/config/cache-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export const metaCacheRootFolder = 'meta-cache'

export const contentCacheRootFolder = 'content-cache'

export type CacheMapKey = `${ListFolder}_${Locale}`
export type CacheMapKey = `${ListFolder}-${Locale}`

export const getCacheMapKey = (
folder: ListFolder,
locale: Locale,
): CacheMapKey => {
return `${folder}_${locale}`
return `${folder}-${locale}`
}

export type MetaCacheItem = Pick<ContentItem, 'slug' | 'metadata'>
Expand Down
2 changes: 1 addition & 1 deletion src/core/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const getSearchEngine = async (folder: ListFolder, locale: Locale) => {
const engine = searchEngineMap.get(key)
if (engine) return engine

const data = getContentCache(...args)
const data = await getContentCache(...args)
const instance = await initializeEngine(data)
searchEngineMap.set(key, instance)

Expand Down

0 comments on commit a8da300

Please sign in to comment.