Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _docs/latest/_includes/test-md.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Included md file heading

Included md file *markdown* (latest).
2 changes: 2 additions & 0 deletions _docs/latest/embedding/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions _docs/v0.63/_includes/test-html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>v0.63-scoped <strong>partial</strong></p>
2 changes: 2 additions & 0 deletions _docs/v0.63/embedding/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
2 changes: 1 addition & 1 deletion src/content.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/collectRedirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/docsHtmlLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/lib/liquid/liquidRenderer.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<string, unknown> => {
const data: Record<string, any> = {};
Expand Down Expand Up @@ -90,13 +92,15 @@ const collapseBlankLines = (html: string): string =>
export const getLiquidRenderer = ({
page,
dirname,
_includes,
}: {
page: Record<string, unknown>;
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
Expand All @@ -112,6 +116,7 @@ export const getLiquidRenderer = ({
...baseCtx,
page,
dirname,
_includes,
};

return {
Expand Down
7 changes: 6 additions & 1 deletion src/pages/docs/[version]/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down