diff --git a/_docs/latest/_includes/test-md.md b/_docs/latest/_includes/test-md.md new file mode 100644 index 0000000000..bb95b7e3e7 --- /dev/null +++ b/_docs/latest/_includes/test-md.md @@ -0,0 +1,3 @@ +## Included md file heading + +Included md file *markdown* (latest). diff --git a/_docs/latest/embedding/authentication.md b/_docs/latest/embedding/authentication.md index ad75134ff4..69d1f28e2d 100644 --- a/_docs/latest/embedding/authentication.md +++ b/_docs/latest/embedding/authentication.md @@ -16,6 +16,8 @@ latest: true # Modular embedding - authentication +{% include {{ _includes }}/test-md.md %} + {% include plans-blockquote.html feature="Authenticated embeds" sdk=true is_plural=true%} For using modular embedding with SSO in production, you'll need to set up authentication. diff --git a/_docs/v0.63/_includes/test-html.html b/_docs/v0.63/_includes/test-html.html new file mode 100644 index 0000000000..6dfb81eceb --- /dev/null +++ b/_docs/v0.63/_includes/test-html.html @@ -0,0 +1 @@ +

v0.63-scoped partial

diff --git a/_docs/v0.63/embedding/authentication.md b/_docs/v0.63/embedding/authentication.md index b82e598281..60d89d942f 100644 --- a/_docs/v0.63/embedding/authentication.md +++ b/_docs/v0.63/embedding/authentication.md @@ -14,6 +14,8 @@ redirect_from: # Modular embedding - authentication +{% include {{ _includes }}/test-html.html %} + {% include plans-blockquote.html feature="Authenticated embeds" sdk=true is_plural=true%} For using modular embedding with SSO in production, you'll need to set up authentication. diff --git a/lib/frontmatter.js b/lib/frontmatter.js index c36981d872..83e6758d0a 100644 --- a/lib/frontmatter.js +++ b/lib/frontmatter.js @@ -13,7 +13,7 @@ function addFrontmatter(directory, frontmatter) { const stats = fs.statSync(filePath); if (stats.isDirectory()) { addFrontmatter(filePath, frontmatter); - } else if (canBeProcessedByFrontmatter(file)) { + } else if (canBeProcessedByFrontmatter(filePath)) { const fileContents = fs.readFileSync(filePath, "utf8"); const { data, content } = matter(fileContents); // Merge the keys with the existing frontmatter. diff --git a/lib/utils.js b/lib/utils.js index 37f29e5e9f..22a64430ab 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -7,6 +7,10 @@ const matter = require("gray-matter"); const yaml = require("yamljs"); function canBeProcessedByFrontmatter(filePath) { + if (filePath.includes("/_includes/")) { + return false; + } + return path.extname(filePath) === ".md" || path.extname(filePath) === ".html" } diff --git a/src/content.config.ts b/src/content.config.ts index 49c5563892..f45713c354 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -5,7 +5,7 @@ import { DOCS_SRC_ROOT } from "./constants"; const docs = defineCollection({ loader: glob({ - pattern: ["**/*.md", "!**/embedding/sdk/api/snippets/**"], + pattern: ["**/*.md", "!**/embedding/sdk/api/snippets/**", "!**/_includes/**"], base: DOCS_SRC_ROOT, // Preserves dots (.) in pathnames diff --git a/src/lib/docs/collectRedirects.ts b/src/lib/docs/collectRedirects.ts index a2a9f1385b..c66ca58064 100644 --- a/src/lib/docs/collectRedirects.ts +++ b/src/lib/docs/collectRedirects.ts @@ -5,7 +5,7 @@ import matter from "gray-matter"; import { DOCS_SRC_ROOT } from "../../constants"; import { resolveDocUrl } from "./resolveDoc"; -const EXCLUDE = ["**/embedding/sdk/api/snippets/**"]; +const EXCLUDE = ["**/embedding/sdk/api/snippets/**", "**/_includes/**"]; type ScanTarget = { extension: "md" | "html"; stripExtension: boolean }; diff --git a/src/lib/docs/docsHtmlLoader.ts b/src/lib/docs/docsHtmlLoader.ts index b31fd154fe..73573f0259 100644 --- a/src/lib/docs/docsHtmlLoader.ts +++ b/src/lib/docs/docsHtmlLoader.ts @@ -21,7 +21,7 @@ export const docsHtmlLoader = (): Loader => ({ const rootDir = fileURLToPath(config.root); const entries: string[] = glob.sync("**/*.html", { cwd: baseDir, - ignore: ["**/embedding/sdk/api/snippets/**"], + ignore: ["**/embedding/sdk/api/snippets/**", "**/_includes/**"], }); for (const entry of entries) { diff --git a/src/lib/liquid/liquidRenderer.ts b/src/lib/liquid/liquidRenderer.ts index 642f3fe333..3db73c17de 100644 --- a/src/lib/liquid/liquidRenderer.ts +++ b/src/lib/liquid/liquidRenderer.ts @@ -1,5 +1,6 @@ import fs from "node:fs"; import path from "node:path"; +import { DOCS_SRC_ROOT } from "@/constants"; import { buildVersionSupportTable } from "@/lib/docs/versionSupport"; import { compose } from "@/lib/fn"; import { Liquid, ParseError, TokenizationError } from "liquidjs"; @@ -41,7 +42,8 @@ const stripInvalidLiquidSpan = ( }; const ROOT = process.cwd(); -const INCLUDES_ROOT = path.join(ROOT, "_includes"); +const INCLUDES_ROOT_SITE = path.join(ROOT, "_includes"); +const INCLUDES_ROOT_DOCS = path.join(ROOT, DOCS_SRC_ROOT); const loadDataDir = (dir: string): Record => { const data: Record = {}; @@ -90,13 +92,15 @@ const collapseBlankLines = (html: string): string => export const getLiquidRenderer = ({ page, dirname, + _includes, }: { page: Record; dirname: string; + _includes?: string; }) => { if (!liquidEngine) { liquidEngine = new Liquid({ - root: [INCLUDES_ROOT], + root: [INCLUDES_ROOT_SITE, INCLUDES_ROOT_DOCS], jekyllInclude: true, jekyllWhere: true, strictVariables: false, // TODO: Would be nice to flip this to true @@ -112,6 +116,7 @@ export const getLiquidRenderer = ({ ...baseCtx, page, dirname, + _includes, }; return { diff --git a/src/pages/docs/[version]/[...slug].astro b/src/pages/docs/[version]/[...slug].astro index 46e60ca6a5..6c242c1a38 100644 --- a/src/pages/docs/[version]/[...slug].astro +++ b/src/pages/docs/[version]/[...slug].astro @@ -36,9 +36,14 @@ export const getStaticPaths = async () => { const { version, slug = "" } = Astro.params; const { kind, doc } = Astro.props; const dirname = path.dirname(doc.filePath!); +const _includes = `${version}/_includes`; // Process liquid first (e.g. control flow, includes, variables, etc) -const lq = getLiquidRenderer({ page: doc.data, dirname }); +const lq = getLiquidRenderer({ + page: doc.data, + dirname, + _includes, +}); const lqOutput = await lq.render(doc.body!, undefined, { maxSyntaxErrors: version === "latest" ? 0 : 3, });