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 plugins/vite-plugin-llms-txt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default function llmsTxtPlugin(options: LlmsTxtPluginOptions): Plugin {

return generateLlmsTxtContent({
siteTitle,
basePath: config.base,
siteUrl,
models,
dataFiles,
Expand Down
34 changes: 9 additions & 25 deletions src/llms-txt/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,28 @@ import type { ExtractedModel } from "./types";

export interface GeneratorOptions {
siteTitle: string;
basePath: string;
siteUrl: string;
models: ExtractedModel[];
dataFiles: string[];
notebooks: string[];
}

export function generateLlmsTxtContent(options: GeneratorOptions): string {
const { siteTitle, basePath, siteUrl, models, dataFiles, notebooks } =
options;
const { siteTitle, siteUrl, models, dataFiles, notebooks } = options;

const sections = [
generateHeader(siteTitle, basePath, siteUrl),
generateOverview(
siteTitle,
basePath,
siteUrl,
models,
dataFiles,
notebooks,
),
generateModelsSection(models, basePath),
generateHeader(siteTitle, siteUrl),
generateOverview(siteTitle, siteUrl, models, dataFiles, notebooks),
generateModelsSection(models, siteUrl),
generateQueryParametersSection(),
generateMalloyQueryGuide(),
];

return sections.join("\n\n");
}

function generateHeader(
siteTitle: string,
basePath: string,
siteUrl: string,
): string {
const base = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
const fullUrl = `${siteUrl.endsWith("/") ? siteUrl.slice(0, -1) : siteUrl}${base}/`;
function generateHeader(siteTitle: string, siteUrl: string): string {
const fullUrl = `${siteUrl.endsWith("/") ? siteUrl.slice(0, -1) : siteUrl}/`;
return `# ${siteTitle}

> Malloy Data Explorer - Static web app for exploring semantic data models
Expand All @@ -54,14 +40,12 @@ function generateHeader(

function generateOverview(
_siteTitle: string,
basePath: string,
siteUrl: string,
models: ExtractedModel[],
dataFiles: string[],
notebooks: string[],
): string {
const base = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
const fullBase = `${siteUrl.endsWith("/") ? siteUrl.slice(0, -1) : siteUrl}${base}`;
const fullBase = siteUrl.endsWith("/") ? siteUrl.slice(0, -1) : siteUrl;

// Content summary
const contentItems = [
Expand Down Expand Up @@ -136,13 +120,13 @@ function generateOverview(

function generateModelsSection(
models: ExtractedModel[],
basePath: string,
siteUrl: string,
): string {
if (models.length === 0) {
return "## Models\n\nNo models available.";
}

const base = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
const base = siteUrl.endsWith("/") ? siteUrl.slice(0, -1) : siteUrl;

const modelSections = models.map((model) => {
const sourceSections = model.sources
Expand Down
Loading