@@ -2,55 +2,57 @@ import { JSDOM } from 'jsdom';
22
33/**
44 * Fetches a list of all the docs on the langbase website
5+ *
6+ *
57 * @returns {Promise<string> } A promise that resolves to a string of all the docs on the langbase website
68 */
7-
89export async function fetchDocsList ( ) {
910 try {
10- const response = await fetch ( 'https://langbase.com/docs/llms.txt' ) ;
11-
12- if ( ! response . ok ) {
13- throw new Error ( 'Failed to fetch docs' ) ;
14- }
15-
16- const text = await response . text ( ) ;
17- return text ;
18-
19- } catch ( error ) {
20- throw new Error ( 'Failed to fetch docs ' + JSON . stringify ( error ) ) ;
21- }
11+ const response = await fetch ( 'https://langbase.com/docs/llms.txt' ) ;
12+ if ( ! response . ok ) {
13+ throw new Error ( 'Failed to fetch docs' ) ;
14+ }
15+
16+ const text = await response . text ( ) ;
17+ return text ;
18+ } catch ( error ) {
19+ throw new Error ( 'Failed to fetch docs ' + JSON . stringify ( error ) ) ;
20+ }
2221}
2322
2423/**
2524 * Fetches and converts a blog post to markdown
25+ *
26+ *
2627 * @param {string } url - The URL of the blog post to fetch
2728 * @returns {Promise<string> } A promise that resolves to a string of the blog post in markdown format
2829 */
29-
3030export async function fetchDocsPost ( url : string ) : Promise < string > {
3131 try {
32- const response = await fetch ( url ) ;
33- if ( ! response . ok ) {
34- throw new Error ( 'Failed to fetch blog post' ) ;
35- }
36-
37- const html = await response . text ( ) ;
38-
32+ const response = await fetch ( url ) ;
33+ if ( ! response . ok ) {
34+ throw new Error ( 'Failed to fetch blog post' ) ;
35+ }
36+
37+ const html = await response . text ( ) ;
38+
3939 const dom = new JSDOM ( html ) ;
4040 const document = dom . window . document ;
41+
4142 // Remove Next.js initialization code
4243 const scripts = document . querySelectorAll ( 'script' ) ;
4344 scripts . forEach ( script => script . remove ( ) ) ;
44-
45+
4546 // Get the main content
4647 const content = document . body . textContent ?. trim ( ) || '' ;
4748 if ( ! content ) {
4849 throw new Error ( 'No content found in docs' ) ;
4950 }
50-
51- return content ;
5251
53- } catch ( error ) {
54- throw new Error ( `Failed to fetch docs: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
55- }
56- }
52+ return content ;
53+ } catch ( error ) {
54+ throw new Error (
55+ `Failed to fetch docs: ${ error instanceof Error ? error . message : 'Something went wrong. Please try again.' } `
56+ ) ;
57+ }
58+ }
0 commit comments