Skip to content

Commit afc6fb7

Browse files
committed
chore: renamed plugin variables, added extra checks for webhook and toggling writeSync, removed intro.md
1 parent db7d108 commit afc6fb7

File tree

3 files changed

+64
-41
lines changed

3 files changed

+64
-41
lines changed

docs/.vitepress/config.mts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fileURLToPath, URL } from 'node:url'
22
import yaml from 'vite-plugin-yaml'
33
import llmstxt from 'vitepress-plugin-llms'
4-
import sanitizeDocsPlugin from './plugins/vitepress-plugin-robo8o';
4+
import coolbotPlugin from './plugins/vitepress-plugin-coolbot';
55
import { defineConfig } from 'vitepress'
66
import { useSidebar } from 'vitepress-openapi'
77
import spec from './theme/openapi.json' with { type: 'json' }
@@ -623,14 +623,21 @@ export default defineConfig({
623623
vite: {
624624
plugins: [
625625
yaml as any,
626-
// llmstxt({
627-
// ignoreFiles: [
628-
// '/docs/api-reference/api/**/*',
629-
// '**/api-reference/api/**/*'
630-
// ],
631-
// }),
632-
sanitizeDocsPlugin({
633-
docsDir: 'docs'
626+
llmstxt({
627+
ignoreFiles: [
628+
'/docs/api-reference/api/**/*',
629+
'**/api-reference/api/**/*'
630+
],
631+
}),
632+
coolbotPlugin({
633+
docsDir: 'docs',
634+
writeRawOutput: false,
635+
ignoreFolders: [
636+
'vitepress',
637+
'api-reference',
638+
'node_modules',
639+
'dist'
640+
],
634641
}),
635642
groupIconVitePlugin({
636643
customIcon: {

docs/.vitepress/plugins/vitepress-plugin-robo8o.ts renamed to docs/.vitepress/plugins/vitepress-plugin-coolbot.ts

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@ import { resolve, join, dirname } from 'path';
22
import { readFileSync, readdirSync, statSync, mkdirSync, existsSync, writeFileSync } from 'fs';
33
import type { Plugin } from 'vite';
44

5-
export interface robot8oPluginOptions {
5+
export interface coolbotPluginOptions {
6+
/**
7+
* Write the raw txt output to the converted directory
8+
* @default false
9+
*/
10+
writeRawOutput?: boolean;
611
/**
712
* Directory containing markdown files to convert
813
* @default 'docs'
914
*/
1015
docsDir?: string;
16+
/**
17+
* Webhook URL to send the file map to
18+
* @default '' || process.env.COOLBOT_WEBHOOK_URL
19+
*/
20+
webhookUrl?: string;
21+
/**
22+
* Ignore files in the docs directory
23+
* @default []
24+
*/
25+
ignoreFolders?: string[];
1126
}
1227

1328
interface FileMap {
@@ -17,9 +32,9 @@ interface FileMap {
1732
/**
1833
* Plugin to convert markdown files to text files, RAG chain.
1934
*/
20-
export default function robot8oPlugin(options: robot8oPluginOptions = {}): Plugin {
35+
export default function coolbotPlugin(options: coolbotPluginOptions = {}): Plugin {
2136
const docsDir = options.docsDir || 'docs';
22-
const webhookUrl = 'https://n8n.darweb.io/webhook-test/kv';
37+
const webhookUrl = process.env.COOLBOT_WEBHOOK_URL || '';
2338

2439
const ensureDirectoryExists = (filePath: string) => {
2540
const dir = dirname(filePath);
@@ -29,26 +44,26 @@ export default function robot8oPlugin(options: robot8oPluginOptions = {}): Plugi
2944
};
3045

3146
return {
32-
name: 'vitepress-plugin-robo8o',
47+
name: 'vitepress-plugin-CoolBot',
3348

3449
async closeBundle() {
3550
try {
3651
const docsPath = resolve(process.cwd(), docsDir);
3752
const markdownFiles = getAllMarkdownFiles(docsPath);
38-
const convertedDir = resolve(docsPath, '.vitepress/dist/converted');
53+
const convertedDir = resolve(docsPath, '.vitepress/dist/');
3954
const fileMap: FileMap = {};
4055

4156
// Ensure converted directory exists
4257
if (!existsSync(convertedDir)) {
4358
mkdirSync(convertedDir, { recursive: true });
4459
}
4560

46-
for (const file of markdownFiles) {
61+
for (const file of markdownFiles) {
4762
try {
4863
const relativePath = file.replace(docsPath, '');
4964

5065
if (!relativePath.startsWith('\\') && !relativePath.startsWith('/')) {
51-
console.warn(`Skipping file with invalid path: ${file}`);
66+
console.warn(`CoolBot: Skipping file with invalid path: ${file}`);
5267
continue;
5368
}
5469

@@ -60,23 +75,27 @@ export default function robot8oPlugin(options: robot8oPluginOptions = {}): Plugi
6075
const normalizedPath = relativePath.slice(1).replace('.md', '').replace(/\\/g, '/');
6176
fileMap[normalizedPath] = convertedContent;
6277

63-
// Write the converted file
64-
ensureDirectoryExists(outputPath);
65-
writeFileSync(outputPath, convertedContent, 'utf-8');
78+
if(options.writeRawOutput) {
79+
// Write the converted file
80+
ensureDirectoryExists(outputPath);
81+
writeFileSync(outputPath, convertedContent, 'utf-8');
82+
console.log(`CoolBot: ${relativePath} -> .vitepress/dist/${relativePath.replace('.md', '.txt')}`);
83+
}
6684

67-
console.log(`Converted: ${relativePath} -> .vitepress/dist/converted${relativePath.replace('.md', '.txt')}`);
6885
} catch (fileError) {
69-
console.error(`Error processing file ${file}:`, fileError);
86+
console.error(`CoolBot: Error processing file ${file}:`, fileError);
7087
}
7188
}
89+
7290

7391
// Write the file map
7492
const mapPath = resolve(convertedDir, 'kvmap.json');
7593
writeFileSync(mapPath, JSON.stringify(fileMap, null, 2), 'utf-8');
7694

77-
// Send POST request to webhook
78-
try {
79-
const response = await fetch(webhookUrl, {
95+
if(webhookUrl) {
96+
// Send POST request to webhook
97+
try {
98+
const response = await fetch(webhookUrl, {
8099
method: 'POST',
81100
headers: {
82101
'Content-Type': 'application/json',
@@ -88,15 +107,16 @@ export default function robot8oPlugin(options: robot8oPluginOptions = {}): Plugi
88107
throw new Error(`HTTP error! status: ${response.status}`);
89108
}
90109

91-
console.log('\nROBO8O: Successfully sent file map to webhook');
92-
} catch (webhookError) {
93-
console.error('ROBO8O: Error sending file map to webhook:', webhookError);
110+
console.log('\nCoolBot: Successfully sent file map to webhook');
111+
} catch (webhookError) {
112+
console.error('CoolBot: Error sending file map to webhook:', webhookError);
113+
}
94114
}
95115

96-
console.log('\nROBO8O: Generated file map at .vitepress/dist/converted/kvmap.json');
97-
console.log('\nROBO8O: Conversion complete');
116+
console.log('\nCoolBot: Generated file map at .vitepress/dist/public/kvmap.json');
117+
console.log('\nCoolBot: Conversion complete');
98118
} catch (error) {
99-
console.error('ROBO8O: Error during conversion:', error);
119+
console.error('CoolBot: Error during conversion:', error);
100120
}
101121
}
102122
};
@@ -111,20 +131,24 @@ function getAllMarkdownFiles(dir: string): string[] {
111131
let results: string[] = [];
112132
try {
113133
const files = readdirSync(dir);
134+
const defaultIgnored = ['node_modules', '.vitepress', 'dist', 'api-reference'];
114135

115136
for (const file of files) {
116137
const filePath = join(dir, file);
117138
const stat = statSync(filePath);
118139

119-
// Skip the .vitepress directory and node_modules
120-
if (stat.isDirectory() && !['node_modules', '.vitepress', 'dist' , 'api-reference'].includes(file)) {
140+
if (defaultIgnored.includes(file)) {
141+
continue;
142+
}
143+
144+
if (stat.isDirectory()) {
121145
results = results.concat(getAllMarkdownFiles(filePath));
122146
} else if (file.endsWith('.md')) {
123147
results.push(filePath);
124148
}
125149
}
126150
} catch (error) {
127-
console.error('ROBO8O: Error reading directory:', error);
151+
console.error('CoolBot: Error reading directory:', error);
128152
}
129153

130154
return results;

docs/introduction.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)