1
1
import { useEffect } from 'preact/hooks' ;
2
2
3
- import { getContent } from './content.js' ;
4
- import { useLanguage } from './i18n' ;
5
-
6
3
/**
7
4
* @typedef {Object } CacheEntry
8
5
* @property {Promise<any> } promise
@@ -12,28 +9,8 @@ import { useLanguage } from './i18n';
12
9
*/
13
10
14
11
/** @type {Map<string, CacheEntry> } */
15
- const CACHE = new Map ( ) ;
16
- const createCacheKey = ( fn , deps ) => '' + fn + JSON . stringify ( deps ) ;
17
-
18
- /**
19
- * @param {string } path
20
- */
21
- export function prefetchContent ( path ) {
22
- const lang = document . documentElement . lang ;
23
- const cacheKey = createCacheKey ( ( ) => getContent ( [ lang , path ] ) , [ lang , path ] ) ;
24
- if ( CACHE . has ( cacheKey ) ) return ;
25
-
26
- setupCacheEntry ( ( ) => getContent ( [ lang , path ] ) , cacheKey ) ;
27
- }
28
-
29
- /**
30
- * @param {string } path
31
- * @returns {{ html: string, meta: any } }
32
- */
33
- export function fetchContent ( path ) {
34
- const [ lang ] = useLanguage ( ) ;
35
- return useResource ( ( ) => getContent ( [ lang , path ] ) , [ lang , path ] ) ;
36
- }
12
+ export const CACHE = new Map ( ) ;
13
+ export const createCacheKey = ( fn , deps ) => '' + fn + JSON . stringify ( deps ) ;
37
14
38
15
export function useResource ( fn , deps ) {
39
16
const cacheKey = createCacheKey ( fn , deps ) ;
@@ -64,7 +41,7 @@ export function useResource(fn, deps) {
64
41
* @param {string } cacheKey
65
42
* @returns {CacheEntry }
66
43
*/
67
- function setupCacheEntry ( fn , cacheKey ) {
44
+ export function setupCacheEntry ( fn , cacheKey ) {
68
45
/** @type {CacheEntry } */
69
46
const state = { promise : fn ( ) , status : 'pending' , result : undefined , users : 0 } ;
70
47
0 commit comments