-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove option and fix renderFile errors on serve
- Loading branch information
1 parent
53a78e8
commit bfbdb10
Showing
4 changed files
with
13 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,11 @@ | ||
import fs from "node:fs/promises"; | ||
|
||
const templateMap = new Map<{ lang: string; source: string }, string>(); | ||
import { RenderPlugin } from "npm:@11ty/eleventy@^3.0.0-alpha.15"; | ||
|
||
export async function renderTemplate( | ||
this: any, | ||
config: any, | ||
template: string | { lang: string; source: string }, | ||
tmpDir: string, | ||
data: { headers: Array<{ id: string; text: string; tag: string }> }, | ||
): Promise<string> { | ||
const renderFile = config.getShortcode("eleventyDocumentOutlineRender"); | ||
if (typeof template == "string") { | ||
return await renderFile.call(this, template, data); | ||
} | ||
if (!templateMap.has(template)) { | ||
await fs.mkdir(tmpDir, { recursive: true }); | ||
const { lang, source } = template; | ||
const uuid = crypto.randomUUID(); | ||
const filePath = `${tmpDir}/${uuid}.${lang}`; | ||
await fs.writeFile(filePath, source); | ||
templateMap.set(template, filePath); | ||
} | ||
const path = templateMap.get(template); | ||
return await renderFile.call(this, path, data); | ||
const renderer = typeof template == "string" | ||
? await RenderPlugin.File(template) | ||
: await RenderPlugin.String(template.source, template.lang); | ||
return await renderer(data); | ||
} |