Skip to content
Merged
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
1 change: 0 additions & 1 deletion src/content/docs/docs/flows.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
title: Defining AI workflows
description: Learn how to define and manage AI workflows in Genkit using flows across JavaScript, Go, and Python, which provide type safety, integration with the developer UI, and simplified deployment.
Expand Down
22 changes: 18 additions & 4 deletions src/gen-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { parse } from 'yaml';
export const FRONTMATTER_AND_BODY_REGEX = /^---\s*(?:\r\n|\r|\n)([\s\S]*?)(?:\r\n|\r|\n)---\s*(?:\r\n|\r|\n)([\s\S]*)$/;

async function main() {
const allDocs = await indexDocs('src/content/docs/docs');
const documents: Record<string, Doc> = {};
for (const lang of ['js', 'go', 'python']) {
const allDocs = await indexDocs('src/content/docs/docs', lang);
for (const doc of Object.keys(allDocs)) {
documents[`${lang}/${doc}`] = {
...allDocs[doc],
Expand All @@ -38,11 +38,12 @@ interface Doc {
title: string;
description?: string;
text: string;
url: string;
headers: string;
lang: string;
}

async function indexDocs(dir: string) {
async function indexDocs(dir: string, lang: string) {
const allFiles = await readdir(dir, { recursive: true });
const docFiles = allFiles.filter((f) => f.endsWith('.md') || f.endsWith('.mdx'));
const documents: Record<string, Omit<Doc, 'lang'>> = {};
Expand All @@ -54,7 +55,9 @@ async function indexDocs(dir: string) {
const normalizedFileName = file.endsWith('.mdx') ? file.substring(0, file.length - 1) : file;

documents[normalizedFileName] = {
text: renderContent(file, body, frontmatter.title || normalizedFileName),
text: renderContent(file, body, frontmatter.title || normalizedFileName, lang),
url:
'https://genkit.dev/docs/' + normalizedFileName.substring(0, normalizedFileName.lastIndexOf('.')) + '/',
title: frontmatter.title || normalizedFileName,
description: frontmatter.description,
headers,
Expand All @@ -66,8 +69,19 @@ async function indexDocs(dir: string) {
const LLM_SUMMARY_REGEX = /<LLMSummary>([\s\S]*?)<\/LLMSummary>/;
const FRONTMATTER_REGEX = /^---\s*[\s\S]*?---/;

function renderContent(file: string, rawContent: string, title: string) {
function renderContent(file: string, rawContent: string, title: string, lang: string) {
if (file.endsWith('.mdx')) {
// Strip out content for other languages
rawContent = rawContent.replace(
/<LanguageContent\s+lang="([^"]+)"[^>]*>([\s\S]*?)<\/LanguageContent>/g,
(match, blockLang, content) => {
if (blockLang === lang) {
return content;
}
return '';
},
);

// --- Check for <LLMs> tag ---
const llmMatch = rawContent.match(LLM_SUMMARY_REGEX);

Expand Down