|
1 | 1 | import { stripIndent } from 'common-tags'; |
| 2 | +import { getParentPath, getPath } from '../router/util.js'; |
2 | 3 | import { get } from '../util/ajax.js'; |
3 | 4 |
|
4 | | -const cached = {}; |
| 5 | +const cached = new Map(); |
5 | 6 |
|
6 | 7 | /** |
7 | 8 | * Extracts the content between matching fragment markers in the text. |
@@ -132,9 +133,20 @@ function walkFetchEmbed({ embedTokens, compile, fetch, frontMatter }, cb) { |
132 | 133 | } |
133 | 134 |
|
134 | 135 | export function prerenderEmbed({ compiler, raw = '', fetch }, done) { |
135 | | - const hit = cached[raw]; |
| 136 | + // Match the base used by compileEmbed to resolve relative includes. |
| 137 | + const contentDirectory = getPath( |
| 138 | + compiler.contentBase, |
| 139 | + getParentPath(compiler.router.getCurrentPath()), |
| 140 | + ); |
| 141 | + let directoryCache = cached.get(contentDirectory); |
| 142 | + if (!directoryCache) { |
| 143 | + directoryCache = new Map(); |
| 144 | + cached.set(contentDirectory, directoryCache); |
| 145 | + } |
| 146 | + |
| 147 | + const hit = directoryCache.get(raw); |
136 | 148 | if (hit) { |
137 | | - const copy = hit.slice(); |
| 149 | + const copy = hit.tokens.slice(); |
138 | 150 | copy.links = hit.links; |
139 | 151 | return done(copy); |
140 | 152 | } |
@@ -271,8 +283,8 @@ export function prerenderEmbed({ compiler, raw = '', fetch }, done) { |
271 | 283 | } |
272 | 284 | } |
273 | 285 | } else if (!token) { |
274 | | - cached[raw] = tokens.concat(); |
275 | | - tokens.links = cached[raw].links = links; |
| 286 | + directoryCache.set(raw, { tokens: tokens.concat(), links }); |
| 287 | + tokens.links = links; |
276 | 288 | done(tokens); |
277 | 289 | } |
278 | 290 | }, |
|
0 commit comments