@ontosdk/next 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OntoHead.d.mts +27 -0
- package/dist/OntoHead.d.ts +27 -0
- package/dist/OntoProvider.d.mts +52 -0
- package/dist/OntoProvider.d.ts +52 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/config.d.mts +80 -0
- package/dist/config.d.ts +80 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/middleware.d.mts +26 -0
- package/dist/middleware.d.ts +26 -0
- package/dist/schemas.d.mts +73 -0
- package/dist/schemas.d.ts +73 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OntoHead — Auto-Discovery component for AI agents.
|
|
5
|
+
*
|
|
6
|
+
* Injects `<link rel="alternate">` tags into the page `<head>` so AI crawlers
|
|
7
|
+
* can discover the optimized markdown endpoint for the current route.
|
|
8
|
+
*
|
|
9
|
+
* Usage in a Next.js App Router layout:
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { OntoHead } from '@ontosdk/next/components';
|
|
12
|
+
*
|
|
13
|
+
* export default function RootLayout({ children }) {
|
|
14
|
+
* return (
|
|
15
|
+
* <html>
|
|
16
|
+
* <head>
|
|
17
|
+
* <OntoHead />
|
|
18
|
+
* </head>
|
|
19
|
+
* <body>{children}</body>
|
|
20
|
+
* </html>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function OntoHead(): react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { OntoHead };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OntoHead — Auto-Discovery component for AI agents.
|
|
5
|
+
*
|
|
6
|
+
* Injects `<link rel="alternate">` tags into the page `<head>` so AI crawlers
|
|
7
|
+
* can discover the optimized markdown endpoint for the current route.
|
|
8
|
+
*
|
|
9
|
+
* Usage in a Next.js App Router layout:
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { OntoHead } from '@ontosdk/next/components';
|
|
12
|
+
*
|
|
13
|
+
* export default function RootLayout({ children }) {
|
|
14
|
+
* return (
|
|
15
|
+
* <html>
|
|
16
|
+
* <head>
|
|
17
|
+
* <OntoHead />
|
|
18
|
+
* </head>
|
|
19
|
+
* <body>{children}</body>
|
|
20
|
+
* </html>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function OntoHead(): react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { OntoHead };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { OntoConfig } from './config.mjs';
|
|
4
|
+
|
|
5
|
+
interface OntoProviderProps {
|
|
6
|
+
/**
|
|
7
|
+
* The base URL of your site (e.g., 'https://example.com')
|
|
8
|
+
* Used to construct the full href for the AI discovery link tag.
|
|
9
|
+
*/
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
/**
|
|
12
|
+
* Child components to render
|
|
13
|
+
*/
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Optional: Onto configuration for automatic JSON-LD schema injection
|
|
17
|
+
* If provided, the provider will automatically inject JSON-LD schemas
|
|
18
|
+
* based on the page type configuration
|
|
19
|
+
*/
|
|
20
|
+
config?: OntoConfig;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* OntoProvider — Automatic AI Discovery Provider
|
|
24
|
+
*
|
|
25
|
+
* Wraps your application and automatically injects:
|
|
26
|
+
* 1. `<link rel="alternate">` tags for AI discovery
|
|
27
|
+
* 2. JSON-LD structured data schemas based on page type
|
|
28
|
+
*
|
|
29
|
+
* With config, automatically generates JSON-LD schemas:
|
|
30
|
+
* - 'scoring' pages get Methodology schema with AIO weights (40/35/25)
|
|
31
|
+
* - 'about' pages get Organization/AboutPage schema
|
|
32
|
+
*
|
|
33
|
+
* Usage in a Next.js App Router layout:
|
|
34
|
+
* ```tsx
|
|
35
|
+
* import { OntoProvider } from '@ontosdk/next/provider';
|
|
36
|
+
* import config from '../onto.config';
|
|
37
|
+
*
|
|
38
|
+
* export default function RootLayout({ children }) {
|
|
39
|
+
* return (
|
|
40
|
+
* <OntoProvider baseUrl="https://example.com" config={config}>
|
|
41
|
+
* <html>
|
|
42
|
+
* <head />
|
|
43
|
+
* <body>{children}</body>
|
|
44
|
+
* </html>
|
|
45
|
+
* </OntoProvider>
|
|
46
|
+
* );
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
declare function OntoProvider({ baseUrl, children, config }: OntoProviderProps): react_jsx_runtime.JSX.Element;
|
|
51
|
+
|
|
52
|
+
export { OntoProvider, type OntoProviderProps };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { OntoConfig } from './config.js';
|
|
4
|
+
|
|
5
|
+
interface OntoProviderProps {
|
|
6
|
+
/**
|
|
7
|
+
* The base URL of your site (e.g., 'https://example.com')
|
|
8
|
+
* Used to construct the full href for the AI discovery link tag.
|
|
9
|
+
*/
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
/**
|
|
12
|
+
* Child components to render
|
|
13
|
+
*/
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Optional: Onto configuration for automatic JSON-LD schema injection
|
|
17
|
+
* If provided, the provider will automatically inject JSON-LD schemas
|
|
18
|
+
* based on the page type configuration
|
|
19
|
+
*/
|
|
20
|
+
config?: OntoConfig;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* OntoProvider — Automatic AI Discovery Provider
|
|
24
|
+
*
|
|
25
|
+
* Wraps your application and automatically injects:
|
|
26
|
+
* 1. `<link rel="alternate">` tags for AI discovery
|
|
27
|
+
* 2. JSON-LD structured data schemas based on page type
|
|
28
|
+
*
|
|
29
|
+
* With config, automatically generates JSON-LD schemas:
|
|
30
|
+
* - 'scoring' pages get Methodology schema with AIO weights (40/35/25)
|
|
31
|
+
* - 'about' pages get Organization/AboutPage schema
|
|
32
|
+
*
|
|
33
|
+
* Usage in a Next.js App Router layout:
|
|
34
|
+
* ```tsx
|
|
35
|
+
* import { OntoProvider } from '@ontosdk/next/provider';
|
|
36
|
+
* import config from '../onto.config';
|
|
37
|
+
*
|
|
38
|
+
* export default function RootLayout({ children }) {
|
|
39
|
+
* return (
|
|
40
|
+
* <OntoProvider baseUrl="https://example.com" config={config}>
|
|
41
|
+
* <html>
|
|
42
|
+
* <head />
|
|
43
|
+
* <body>{children}</body>
|
|
44
|
+
* </html>
|
|
45
|
+
* </OntoProvider>
|
|
46
|
+
* );
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
declare function OntoProvider({ baseUrl, children, config }: OntoProviderProps): react_jsx_runtime.JSX.Element;
|
|
51
|
+
|
|
52
|
+
export { OntoProvider, type OntoProviderProps };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration schema for onto.config.ts
|
|
3
|
+
* Used to dynamically generate llms.txt and other AI discovery files
|
|
4
|
+
*/
|
|
5
|
+
type PageType = 'scoring' | 'about' | 'default';
|
|
6
|
+
interface OntoRoute {
|
|
7
|
+
/**
|
|
8
|
+
* The URL path (e.g., '/docs', '/api/reference')
|
|
9
|
+
*/
|
|
10
|
+
path: string;
|
|
11
|
+
/**
|
|
12
|
+
* Description of what this route contains
|
|
13
|
+
*/
|
|
14
|
+
description: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional: Page type for automatic JSON-LD schema injection
|
|
17
|
+
* - 'scoring': Injects Methodology schema with AIO scoring weights (40/35/25)
|
|
18
|
+
* - 'about': Injects Organization/AboutPage schema
|
|
19
|
+
* - 'default': No automatic schema injection
|
|
20
|
+
*/
|
|
21
|
+
pageType?: PageType;
|
|
22
|
+
}
|
|
23
|
+
interface OntoConfig {
|
|
24
|
+
/**
|
|
25
|
+
* The name of your project or site (required)
|
|
26
|
+
* Used as the H1 heading in llms.txt
|
|
27
|
+
*/
|
|
28
|
+
name: string;
|
|
29
|
+
/**
|
|
30
|
+
* A short summary of your project (required)
|
|
31
|
+
* Displayed as a blockquote in llms.txt
|
|
32
|
+
* Should contain key information necessary for understanding the rest of the file
|
|
33
|
+
*/
|
|
34
|
+
summary: string;
|
|
35
|
+
/**
|
|
36
|
+
* The base URL of your site (e.g., 'https://example.com')
|
|
37
|
+
*/
|
|
38
|
+
baseUrl: string;
|
|
39
|
+
/**
|
|
40
|
+
* Optional: Additional sections to include in llms.txt
|
|
41
|
+
* Each section can contain any markdown content
|
|
42
|
+
*/
|
|
43
|
+
sections?: {
|
|
44
|
+
heading: string;
|
|
45
|
+
content: string;
|
|
46
|
+
}[];
|
|
47
|
+
/**
|
|
48
|
+
* Key routes that AI agents should know about
|
|
49
|
+
* These will be formatted as a markdown list in llms.txt
|
|
50
|
+
*/
|
|
51
|
+
routes?: OntoRoute[];
|
|
52
|
+
/**
|
|
53
|
+
* Optional: Links to external resources (documentation, API references, etc.)
|
|
54
|
+
*/
|
|
55
|
+
externalLinks?: {
|
|
56
|
+
title: string;
|
|
57
|
+
url: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
}[];
|
|
60
|
+
/**
|
|
61
|
+
* Optional: Organization information for JSON-LD schemas
|
|
62
|
+
*/
|
|
63
|
+
organization?: {
|
|
64
|
+
name: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
url?: string;
|
|
67
|
+
logo?: string;
|
|
68
|
+
foundingDate?: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Generate llms.txt content from OntoConfig
|
|
73
|
+
* Follows the llms.txt specification:
|
|
74
|
+
* - H1 with project name
|
|
75
|
+
* - Blockquote with summary
|
|
76
|
+
* - Additional markdown sections
|
|
77
|
+
*/
|
|
78
|
+
declare function generateLlmsTxt(config: OntoConfig): string;
|
|
79
|
+
|
|
80
|
+
export { type OntoConfig, type OntoRoute, type PageType, generateLlmsTxt };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration schema for onto.config.ts
|
|
3
|
+
* Used to dynamically generate llms.txt and other AI discovery files
|
|
4
|
+
*/
|
|
5
|
+
type PageType = 'scoring' | 'about' | 'default';
|
|
6
|
+
interface OntoRoute {
|
|
7
|
+
/**
|
|
8
|
+
* The URL path (e.g., '/docs', '/api/reference')
|
|
9
|
+
*/
|
|
10
|
+
path: string;
|
|
11
|
+
/**
|
|
12
|
+
* Description of what this route contains
|
|
13
|
+
*/
|
|
14
|
+
description: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional: Page type for automatic JSON-LD schema injection
|
|
17
|
+
* - 'scoring': Injects Methodology schema with AIO scoring weights (40/35/25)
|
|
18
|
+
* - 'about': Injects Organization/AboutPage schema
|
|
19
|
+
* - 'default': No automatic schema injection
|
|
20
|
+
*/
|
|
21
|
+
pageType?: PageType;
|
|
22
|
+
}
|
|
23
|
+
interface OntoConfig {
|
|
24
|
+
/**
|
|
25
|
+
* The name of your project or site (required)
|
|
26
|
+
* Used as the H1 heading in llms.txt
|
|
27
|
+
*/
|
|
28
|
+
name: string;
|
|
29
|
+
/**
|
|
30
|
+
* A short summary of your project (required)
|
|
31
|
+
* Displayed as a blockquote in llms.txt
|
|
32
|
+
* Should contain key information necessary for understanding the rest of the file
|
|
33
|
+
*/
|
|
34
|
+
summary: string;
|
|
35
|
+
/**
|
|
36
|
+
* The base URL of your site (e.g., 'https://example.com')
|
|
37
|
+
*/
|
|
38
|
+
baseUrl: string;
|
|
39
|
+
/**
|
|
40
|
+
* Optional: Additional sections to include in llms.txt
|
|
41
|
+
* Each section can contain any markdown content
|
|
42
|
+
*/
|
|
43
|
+
sections?: {
|
|
44
|
+
heading: string;
|
|
45
|
+
content: string;
|
|
46
|
+
}[];
|
|
47
|
+
/**
|
|
48
|
+
* Key routes that AI agents should know about
|
|
49
|
+
* These will be formatted as a markdown list in llms.txt
|
|
50
|
+
*/
|
|
51
|
+
routes?: OntoRoute[];
|
|
52
|
+
/**
|
|
53
|
+
* Optional: Links to external resources (documentation, API references, etc.)
|
|
54
|
+
*/
|
|
55
|
+
externalLinks?: {
|
|
56
|
+
title: string;
|
|
57
|
+
url: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
}[];
|
|
60
|
+
/**
|
|
61
|
+
* Optional: Organization information for JSON-LD schemas
|
|
62
|
+
*/
|
|
63
|
+
organization?: {
|
|
64
|
+
name: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
url?: string;
|
|
67
|
+
logo?: string;
|
|
68
|
+
foundingDate?: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Generate llms.txt content from OntoConfig
|
|
73
|
+
* Follows the llms.txt specification:
|
|
74
|
+
* - H1 with project name
|
|
75
|
+
* - Blockquote with summary
|
|
76
|
+
* - Additional markdown sections
|
|
77
|
+
*/
|
|
78
|
+
declare function generateLlmsTxt(config: OntoConfig): string;
|
|
79
|
+
|
|
80
|
+
export { type OntoConfig, type OntoRoute, type PageType, generateLlmsTxt };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { OntoConfig, OntoConfig as OntoConfigType, OntoRoute, OntoRoute as OntoRouteType, PageType, generateLlmsTxt } from './config.mjs';
|
|
2
|
+
export { AIOMethodologySchema, AboutPageSchema, OrganizationSchema, generateAIOMethodologySchema, generateAboutPageSchema, generateOrganizationSchema, generateSchemaForPageType, serializeSchema } from './schemas.mjs';
|
|
3
|
+
|
|
4
|
+
interface ExtractionResult {
|
|
5
|
+
markdown: string;
|
|
6
|
+
metadata: {
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
jsonLd: any[];
|
|
10
|
+
};
|
|
11
|
+
stats: {
|
|
12
|
+
originalHtmlSize: number;
|
|
13
|
+
markdownSize: number;
|
|
14
|
+
tokenReductionRatio: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extracts pure semantic markdown and metadata from rendered Next.js HTML strings.
|
|
19
|
+
* @param html The raw HTML string.
|
|
20
|
+
* @param sourceUrl (Optional) the URL this was generated from, to attach as metadata.
|
|
21
|
+
* @returns {ExtractionResult} The extracted payload.
|
|
22
|
+
*/
|
|
23
|
+
declare function extractContent(html: string, sourceUrl?: string): ExtractionResult;
|
|
24
|
+
|
|
25
|
+
export { extractContent };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { OntoConfig, OntoConfig as OntoConfigType, OntoRoute, OntoRoute as OntoRouteType, PageType, generateLlmsTxt } from './config.js';
|
|
2
|
+
export { AIOMethodologySchema, AboutPageSchema, OrganizationSchema, generateAIOMethodologySchema, generateAboutPageSchema, generateOrganizationSchema, generateSchemaForPageType, serializeSchema } from './schemas.js';
|
|
3
|
+
|
|
4
|
+
interface ExtractionResult {
|
|
5
|
+
markdown: string;
|
|
6
|
+
metadata: {
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
jsonLd: any[];
|
|
10
|
+
};
|
|
11
|
+
stats: {
|
|
12
|
+
originalHtmlSize: number;
|
|
13
|
+
markdownSize: number;
|
|
14
|
+
tokenReductionRatio: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extracts pure semantic markdown and metadata from rendered Next.js HTML strings.
|
|
19
|
+
* @param html The raw HTML string.
|
|
20
|
+
* @param sourceUrl (Optional) the URL this was generated from, to attach as metadata.
|
|
21
|
+
* @returns {ExtractionResult} The extracted payload.
|
|
22
|
+
*/
|
|
23
|
+
declare function extractContent(html: string, sourceUrl?: string): ExtractionResult;
|
|
24
|
+
|
|
25
|
+
export { extractContent };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var P=Object.create;var c=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var n in e)c(t,n,{get:e[n],enumerable:!0})},d=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of C(e))!R.call(t,i)&&i!==n&&c(t,i,{get:()=>e[i],enumerable:!(o=L(e,i))||o.enumerable});return t};var f=(t,e,n)=>(n=t!=null?P(H(t)):{},d(e||!t||!t.__esModule?c(n,"default",{value:t,enumerable:!0}):n,t)),I=t=>d(c({},"__esModule",{value:!0}),t);var j={};v(j,{extractContent:()=>x,generateAIOMethodologySchema:()=>
|
|
1
|
+
"use strict";var P=Object.create;var c=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var n in e)c(t,n,{get:e[n],enumerable:!0})},d=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of C(e))!R.call(t,i)&&i!==n&&c(t,i,{get:()=>e[i],enumerable:!(o=L(e,i))||o.enumerable});return t};var f=(t,e,n)=>(n=t!=null?P(H(t)):{},d(e||!t||!t.__esModule?c(n,"default",{value:t,enumerable:!0}):n,t)),I=t=>d(c({},"__esModule",{value:!0}),t);var j={};v(j,{extractContent:()=>x,generateAIOMethodologySchema:()=>u,generateAboutPageSchema:()=>p,generateLlmsTxt:()=>O,generateOrganizationSchema:()=>l,generateSchemaForPageType:()=>w,serializeSchema:()=>z});module.exports=I(j);var y=f(require("cheerio")),S=f(require("turndown")),M=new S.default({headingStyle:"atx",codeBlockStyle:"fenced"});function x(t,e="Generated Output"){let n=t.length,o=y.load(t),i=o("title").text()||o("h1").first().text()||"Untitled Page",g=o('meta[name="description"]').attr("content")||"No description found.",a=[];o('script[type="application/ld+json"]').each((h,$)=>{try{let b=o($).html()||"",A=JSON.parse(b);a.push(A)}catch{}}),o("script, style, noscript, iframe, svg, nav, footer, meta, link, header").remove();let s="";o("main").length>0?s=o("main").html()||"":o("article").length>0?s=o("article").html()||"":s=o("body").html()||"";let k=M.turndown(s),r=[`# ${i}`,`> ${g}`,"",`**Source:** ${e}`,`**Extracted:** ${new Date().toISOString()}`,"","---",""].join(`
|
|
2
2
|
`)+k;a.length>0&&(r+=`
|
|
3
3
|
|
|
4
4
|
---
|
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
`,a.forEach(h=>{r+=JSON.stringify(h,null,2)+`
|
|
8
8
|
`}),r+="```\n");let m=r.length,T=n>0?(n-m)/n*100:0;return{markdown:r,metadata:{title:i,description:g,jsonLd:a},stats:{originalHtmlSize:n,markdownSize:m,tokenReductionRatio:T}}}function O(t){let e=[];if(e.push(`# ${t.name}`),e.push(""),e.push(`> ${t.summary}`),e.push(""),t.routes&&t.routes.length>0){e.push("## Key Routes"),e.push("");for(let n of t.routes){let o=`${t.baseUrl}${n.path}`;e.push(`- [${n.path}](${o}): ${n.description}`)}e.push("")}if(t.externalLinks&&t.externalLinks.length>0){e.push("## Resources"),e.push("");for(let n of t.externalLinks)n.description?e.push(`- [${n.title}](${n.url}): ${n.description}`):e.push(`- [${n.title}](${n.url})`);e.push("")}if(t.sections&&t.sections.length>0)for(let n of t.sections)e.push(`## ${n.heading}`),e.push(""),e.push(n.content),e.push("");return e.join(`
|
|
9
9
|
`).trim()+`
|
|
10
|
-
`}function
|
|
10
|
+
`}function u(t,e){return{"@context":"https://schema.org","@type":"HowTo",name:"AIO Score Calculation Methodology",description:"AI Optimization (AIO) Score measures how well a website is optimized for AI agents and LLM crawlers. Scored out of 100 points based on four key metrics.",step:[{"@type":"HowToStep",name:"Content Negotiation",text:"Check if the site responds to Accept: text/markdown header. Weight: 40%. Penalty: -30 points if missing. This ensures AI bots receive optimized content instead of heavy HTML.",position:1},{"@type":"HowToStep",name:"Token Efficiency (React Tax)",text:"Measure the ratio of visible text to total HTML size. Weight: 35%. Penalty: -30 points if HTML > 100KB but text < 1KB. Detects JavaScript-heavy sites that are difficult for AI to parse.",position:2},{"@type":"HowToStep",name:"Structured Data",text:"Verify presence of JSON-LD structured data (Schema.org). Weight: 25%. Penalty: -25 points if missing. Enables AI to confidently extract pricing, products, and entities.",position:3},{"@type":"HowToStep",name:"Semantic HTML",text:"Check for semantic tags like <main> and <article>. Bonus: +15 points if present. Helps AI agents separate navigation from core content.",position:4}]}}function l(t,e){if(!t.organization)return null;let n={"@context":"https://schema.org","@type":"Organization",name:t.organization.name};return t.organization.url&&(n.url=t.organization.url),t.organization.description&&(n.description=t.organization.description),t.organization.logo&&(n.logo=t.organization.logo),t.organization.foundingDate&&(n.foundingDate=t.organization.foundingDate),n}function p(t,e){let n=l(t,e),o={"@context":"https://schema.org","@type":"AboutPage",name:`About ${t.name}`,url:e};return t.summary&&(o.description=t.summary),n&&(o.mainEntity=n),o}function w(t,e,n){switch(t){case"scoring":return u(e,n);case"about":return p(e,n);default:return null}}function z(t){return t?JSON.stringify(t,null,2):null}0&&(module.exports={extractContent,generateAIOMethodologySchema,generateAboutPageSchema,generateLlmsTxt,generateOrganizationSchema,generateSchemaForPageType,serializeSchema});
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/extractor.ts","../src/config.ts","../src/schemas.ts"],"sourcesContent":["// We cannot use Webpack plugins reliably in Next.js Turbopack due to WorkerError restrictions.\r\n// Users must instead run `npx onto-next` as a postbuild script.\r\nexport { extractContent } from './extractor';\r\nexport { OntoConfig, OntoRoute, loadOntoConfig, generateLlmsTxt } from './config';\r\nexport type { OntoConfig as OntoConfigType, OntoRoute as OntoRouteType, PageType } from './config';\r\nexport {\r\n generateAIOMethodologySchema,\r\n generateOrganizationSchema,\r\n generateAboutPageSchema,\r\n generateSchemaForPageType,\r\n serializeSchema\r\n} from './schemas';\r\nexport type {\r\n AIOMethodologySchema,\r\n OrganizationSchema,\r\n AboutPageSchema\r\n} from './schemas';\r\n","import * as cheerio from 'cheerio';\r\nimport TurndownService from 'turndown';\r\n\r\nconst turndownService = new TurndownService({\r\n headingStyle: 'atx',\r\n codeBlockStyle: 'fenced',\r\n});\r\n\r\n// Configure turndown to keep some layout or handle semantic tags differently if needed\r\n\r\nexport interface ExtractionResult {\r\n markdown: string;\r\n metadata: {\r\n title: string;\r\n description: string;\r\n jsonLd: any[];\r\n };\r\n stats: {\r\n originalHtmlSize: number;\r\n markdownSize: number;\r\n tokenReductionRatio: number;\r\n };\r\n}\r\n\r\n/**\r\n * Extracts pure semantic markdown and metadata from rendered Next.js HTML strings.\r\n * @param html The raw HTML string.\r\n * @param sourceUrl (Optional) the URL this was generated from, to attach as metadata.\r\n * @returns {ExtractionResult} The extracted payload.\r\n */\r\nexport function extractContent(html: string, sourceUrl: string = 'Generated Output'): ExtractionResult {\r\n const originalSize = html.length;\r\n\r\n const $ = cheerio.load(html);\r\n\r\n // 1. Extract Metadata BEFORE removing structure\r\n const title = $('title').text() || $('h1').first().text() || 'Untitled Page';\r\n const description = $('meta[name=\"description\"]').attr('content') || 'No description found.';\r\n\r\n const jsonLdScripts: any[] = [];\r\n $('script[type=\"application/ld+json\"]').each((_, el) => {\r\n try {\r\n const raw = $(el).html() || '';\r\n const parsed = JSON.parse(raw);\r\n jsonLdScripts.push(parsed);\r\n } catch {\r\n // ignore bad json\r\n }\r\n });\r\n\r\n // 2. Strip noise (React boilerplate, styles, unnecessary tags)\r\n $('script, style, noscript, iframe, svg, nav, footer, meta, link, header').remove();\r\n\r\n // Optionally remove typical Next.js hidden wrappers if they don't contain real content.\r\n // Next.js uses <div id=\"__next\"> but we mostly just want semantic content.\r\n\r\n // 3. Find the entry point for content\r\n // Prefer <main> or <article> over <body>\r\n let contentHtml = '';\r\n if ($('main').length > 0) {\r\n contentHtml = $('main').html() || '';\r\n } else if ($('article').length > 0) {\r\n contentHtml = $('article').html() || '';\r\n } else {\r\n contentHtml = $('body').html() || '';\r\n }\r\n\r\n // 4. Convert to Markdown\r\n let markdown = turndownService.turndown(contentHtml);\r\n\r\n // 5. Optionally inject Metadata header\r\n const headerLines = [\r\n `# ${title}`,\r\n `> ${description}`,\r\n ``,\r\n `**Source:** ${sourceUrl}`,\r\n `**Extracted:** ${new Date().toISOString()}`,\r\n ``,\r\n `---`,\r\n ``\r\n ];\r\n\r\n let finalMarkdown = headerLines.join('\\n') + markdown;\r\n\r\n // Add JSON-LD section if exists\r\n if (jsonLdScripts.length > 0) {\r\n finalMarkdown += '\\n\\n---\\n## Structured Data (JSON-LD)\\n```json\\n';\r\n jsonLdScripts.forEach(j => {\r\n finalMarkdown += JSON.stringify(j, null, 2) + '\\n';\r\n });\r\n finalMarkdown += '```\\n';\r\n }\r\n\r\n const markdownSize = finalMarkdown.length;\r\n const tokenReductionRatio = originalSize > 0 ? ((originalSize - markdownSize) / originalSize) * 100 : 0;\r\n\r\n return {\r\n markdown: finalMarkdown,\r\n metadata: {\r\n title,\r\n description,\r\n jsonLd: jsonLdScripts\r\n },\r\n stats: {\r\n originalHtmlSize: originalSize,\r\n markdownSize,\r\n tokenReductionRatio\r\n }\r\n };\r\n}\r\n\r\nexport async function generateStaticPayloads(nextAppDirDir: string, ontoPublicDir: string) {\r\n const fs = await import('fs');\r\n const path = await import('path');\r\n const { glob } = await import('glob');\r\n\r\n if (!fs.existsSync(nextAppDirDir)) {\r\n return;\r\n }\r\n\r\n const files = await glob('**/*.html', { cwd: nextAppDirDir });\r\n if (files.length === 0) return;\r\n\r\n if (!fs.existsSync(ontoPublicDir)) {\r\n fs.mkdirSync(ontoPublicDir, { recursive: true });\r\n }\r\n\r\n let totalFilesProcessed = 0;\r\n\r\n for (const file of files) {\r\n const inputPath = path.join(nextAppDirDir, file);\r\n const outputPathRelative = file.replace(/\\.html$/, '.md');\r\n const outputPath = path.join(ontoPublicDir, outputPathRelative);\r\n\r\n try {\r\n const htmlContent = fs.readFileSync(inputPath, 'utf8');\r\n\r\n let routeName = file.replace(/\\.html$/, '');\r\n if (routeName === 'index') routeName = '/';\r\n else routeName = `/${routeName}`;\r\n\r\n const result = extractContent(htmlContent, routeName);\r\n\r\n const outputDir = path.dirname(outputPath);\r\n if (!fs.existsSync(outputDir)) {\r\n fs.mkdirSync(outputDir, { recursive: true });\r\n }\r\n\r\n fs.writeFileSync(outputPath, result.markdown, 'utf8');\r\n totalFilesProcessed++;\r\n } catch (e: any) {\r\n console.error(`[Onto] Failed to process ${file}: ${e.message}`);\r\n }\r\n }\r\n console.log(`[Onto] Successfully generated ${totalFilesProcessed} semantic markdown endpoints.`);\r\n}\r\n","/**\r\n * Configuration schema for onto.config.ts\r\n * Used to dynamically generate llms.txt and other AI discovery files\r\n */\r\n\r\nexport type PageType = 'scoring' | 'about' | 'default';\r\n\r\nexport interface OntoRoute {\r\n /**\r\n * The URL path (e.g., '/docs', '/api/reference')\r\n */\r\n path: string;\r\n /**\r\n * Description of what this route contains\r\n */\r\n description: string;\r\n /**\r\n * Optional: Page type for automatic JSON-LD schema injection\r\n * - 'scoring': Injects Methodology schema with AIO scoring weights (40/35/25)\r\n * - 'about': Injects Organization/AboutPage schema\r\n * - 'default': No automatic schema injection\r\n */\r\n pageType?: PageType;\r\n}\r\n\r\nexport interface OntoConfig {\r\n /**\r\n * The name of your project or site (required)\r\n * Used as the H1 heading in llms.txt\r\n */\r\n name: string;\r\n\r\n /**\r\n * A short summary of your project (required)\r\n * Displayed as a blockquote in llms.txt\r\n * Should contain key information necessary for understanding the rest of the file\r\n */\r\n summary: string;\r\n\r\n /**\r\n * The base URL of your site (e.g., 'https://example.com')\r\n */\r\n baseUrl: string;\r\n\r\n /**\r\n * Optional: Additional sections to include in llms.txt\r\n * Each section can contain any markdown content\r\n */\r\n sections?: {\r\n heading: string;\r\n content: string;\r\n }[];\r\n\r\n /**\r\n * Key routes that AI agents should know about\r\n * These will be formatted as a markdown list in llms.txt\r\n */\r\n routes?: OntoRoute[];\r\n\r\n /**\r\n * Optional: Links to external resources (documentation, API references, etc.)\r\n */\r\n externalLinks?: {\r\n title: string;\r\n url: string;\r\n description?: string;\r\n }[];\r\n\r\n /**\r\n * Optional: Organization information for JSON-LD schemas\r\n */\r\n organization?: {\r\n name: string;\r\n description?: string;\r\n url?: string;\r\n logo?: string;\r\n foundingDate?: string;\r\n };\r\n}\r\n\r\n/**\r\n * Generate llms.txt content from OntoConfig\r\n * Follows the llms.txt specification:\r\n * - H1 with project name\r\n * - Blockquote with summary\r\n * - Additional markdown sections\r\n */\r\nexport function generateLlmsTxt(config: OntoConfig): string {\r\n const lines: string[] = [];\r\n\r\n // H1: Project name (required)\r\n lines.push(`# ${config.name}`);\r\n lines.push('');\r\n\r\n // Blockquote: Summary (required)\r\n lines.push(`> ${config.summary}`);\r\n lines.push('');\r\n\r\n // Key Routes section (if provided)\r\n if (config.routes && config.routes.length > 0) {\r\n lines.push('## Key Routes');\r\n lines.push('');\r\n for (const route of config.routes) {\r\n const fullUrl = `${config.baseUrl}${route.path}`;\r\n lines.push(`- [${route.path}](${fullUrl}): ${route.description}`);\r\n }\r\n lines.push('');\r\n }\r\n\r\n // External Links section (if provided)\r\n if (config.externalLinks && config.externalLinks.length > 0) {\r\n lines.push('## Resources');\r\n lines.push('');\r\n for (const link of config.externalLinks) {\r\n if (link.description) {\r\n lines.push(`- [${link.title}](${link.url}): ${link.description}`);\r\n } else {\r\n lines.push(`- [${link.title}](${link.url})`);\r\n }\r\n }\r\n lines.push('');\r\n }\r\n\r\n // Custom sections (if provided)\r\n if (config.sections && config.sections.length > 0) {\r\n for (const section of config.sections) {\r\n lines.push(`## ${section.heading}`);\r\n lines.push('');\r\n lines.push(section.content);\r\n lines.push('');\r\n }\r\n }\r\n\r\n return lines.join('\\n').trim() + '\\n';\r\n}\r\n","/**\r\n * JSON-LD Schema generators for automatic structured data injection\r\n * Follows Schema.org standards for AI-friendly metadata\r\n */\r\n\r\nimport { OntoConfig } from './config';\r\n\r\n/**\r\n * Standard AIO (AI Optimization) scoring methodology\r\n * Based on the Onto scoring algorithm:\r\n * - Content Negotiation: 40% (30 points)\r\n * - React Tax / Token Efficiency: 35% (30 points)\r\n * - Structured Data: 25% (25 points)\r\n * - Semantic HTML: Bonus (15 points)\r\n */\r\nexport interface AIOMethodologySchema {\r\n '@context': 'https://schema.org';\r\n '@type': 'HowTo';\r\n name: string;\r\n description: string;\r\n step: Array<{\r\n '@type': 'HowToStep';\r\n name: string;\r\n text: string;\r\n position: number;\r\n }>;\r\n}\r\n\r\n/**\r\n * Generate AIO Scoring Methodology JSON-LD schema\r\n * This explains to AI agents how the scoring system works\r\n */\r\nexport function generateAIOMethodologySchema(\r\n config: OntoConfig,\r\n pageUrl: string\r\n): AIOMethodologySchema {\r\n return {\r\n '@context': 'https://schema.org',\r\n '@type': 'HowTo',\r\n name: 'AIO Score Calculation Methodology',\r\n description: 'AI Optimization (AIO) Score measures how well a website is optimized for AI agents and LLM crawlers. Scored out of 100 points based on four key metrics.',\r\n step: [\r\n {\r\n '@type': 'HowToStep',\r\n name: 'Content Negotiation',\r\n text: 'Check if the site responds to Accept: text/markdown header. Weight: 40%. Penalty: -30 points if missing. This ensures AI bots receive optimized content instead of heavy HTML.',\r\n position: 1\r\n },\r\n {\r\n '@type': 'HowToStep',\r\n name: 'Token Efficiency (React Tax)',\r\n text: 'Measure the ratio of visible text to total HTML size. Weight: 35%. Penalty: -30 points if HTML > 100KB but text < 1KB. Detects JavaScript-heavy sites that are difficult for AI to parse.',\r\n position: 2\r\n },\r\n {\r\n '@type': 'HowToStep',\r\n name: 'Structured Data',\r\n text: 'Verify presence of JSON-LD structured data (Schema.org). Weight: 25%. Penalty: -25 points if missing. Enables AI to confidently extract pricing, products, and entities.',\r\n position: 3\r\n },\r\n {\r\n '@type': 'HowToStep',\r\n name: 'Semantic HTML',\r\n text: 'Check for semantic tags like <main> and <article>. Bonus: +15 points if present. Helps AI agents separate navigation from core content.',\r\n position: 4\r\n }\r\n ]\r\n };\r\n}\r\n\r\n/**\r\n * Organization schema for About pages\r\n */\r\nexport interface OrganizationSchema {\r\n '@context': 'https://schema.org';\r\n '@type': 'Organization';\r\n name: string;\r\n url?: string;\r\n description?: string;\r\n logo?: string;\r\n foundingDate?: string;\r\n}\r\n\r\n/**\r\n * Generate Organization JSON-LD schema for About pages\r\n */\r\nexport function generateOrganizationSchema(\r\n config: OntoConfig,\r\n pageUrl: string\r\n): OrganizationSchema | null {\r\n if (!config.organization) {\r\n return null;\r\n }\r\n\r\n const schema: OrganizationSchema = {\r\n '@context': 'https://schema.org',\r\n '@type': 'Organization',\r\n name: config.organization.name\r\n };\r\n\r\n if (config.organization.url) {\r\n schema.url = config.organization.url;\r\n }\r\n\r\n if (config.organization.description) {\r\n schema.description = config.organization.description;\r\n }\r\n\r\n if (config.organization.logo) {\r\n schema.logo = config.organization.logo;\r\n }\r\n\r\n if (config.organization.foundingDate) {\r\n schema.foundingDate = config.organization.foundingDate;\r\n }\r\n\r\n return schema;\r\n}\r\n\r\n/**\r\n * AboutPage schema combining Organization and WebPage\r\n */\r\nexport interface AboutPageSchema {\r\n '@context': 'https://schema.org';\r\n '@type': 'AboutPage';\r\n name: string;\r\n url: string;\r\n description?: string;\r\n mainEntity?: OrganizationSchema;\r\n}\r\n\r\n/**\r\n * Generate AboutPage JSON-LD schema\r\n */\r\nexport function generateAboutPageSchema(\r\n config: OntoConfig,\r\n pageUrl: string\r\n): AboutPageSchema {\r\n const orgSchema = generateOrganizationSchema(config, pageUrl);\r\n\r\n const schema: AboutPageSchema = {\r\n '@context': 'https://schema.org',\r\n '@type': 'AboutPage',\r\n name: `About ${config.name}`,\r\n url: pageUrl\r\n };\r\n\r\n if (config.summary) {\r\n schema.description = config.summary;\r\n }\r\n\r\n if (orgSchema) {\r\n schema.mainEntity = orgSchema;\r\n }\r\n\r\n return schema;\r\n}\r\n\r\n/**\r\n * Determine which schema to generate based on page type\r\n */\r\nexport function generateSchemaForPageType(\r\n pageType: 'scoring' | 'about' | 'default',\r\n config: OntoConfig,\r\n pageUrl: string\r\n): any | null {\r\n switch (pageType) {\r\n case 'scoring':\r\n return generateAIOMethodologySchema(config, pageUrl);\r\n case 'about':\r\n return generateAboutPageSchema(config, pageUrl);\r\n case 'default':\r\n default:\r\n return null;\r\n }\r\n}\r\n\r\n/**\r\n * Serialize schema to JSON-LD script tag content\r\n */\r\nexport function serializeSchema(schema: any | null): string | null {\r\n if (!schema) {\r\n return null;\r\n }\r\n return JSON.stringify(schema, null, 2);\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,iCAAAC,EAAA,4BAAAC,EAAA,oBAAAC,EAAA,+BAAAC,EAAA,8BAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAT,GCAA,IAAAU,EAAyB,sBACzBC,EAA4B,uBAEtBC,EAAkB,IAAI,EAAAC,QAAgB,CACxC,aAAc,MACd,eAAgB,QACpB,CAAC,EAwBM,SAASC,EAAeC,EAAcC,EAAoB,mBAAsC,CACnG,IAAMC,EAAeF,EAAK,OAEpBG,EAAY,OAAKH,CAAI,EAGrBI,EAAQD,EAAE,OAAO,EAAE,KAAK,GAA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CACZ,EACA,CACE,QAAS,YACT,KAAM,+BACN,KAAM,4LACN,SAAU,CACZ,EACA,CACE,QAAS,YACT,KAAM,kBACN,KAAM,2KACN,SAAU,CACZ,EACA,CACE,QAAS,YACT,KAAM,gBACN,KAAM,0IACN,SAAU,CACZ,CACF,CACF,CACF,CAkBO,SAASC,EACdF,EACAC,EAC2B,CAC3B,GAAI,CAACD,EAAO,aACV,OAAO,KAGT,IAAMG,EAA6B,CACjC,WAAY,qBACZ,QAAS,eACT,KAAMH,EAAO,aAAa,IAC5B,EAEA,OAAIA,EAAO,aAAa,MACtBG,EAAO,IAAMH,EAAO,aAAa,KAG/BA,EAAO,aAAa,cACtBG,EAAO,YAAcH,EAAO,aAAa,aAGvCA,EAAO,aAAa,OACtBG,EAAO,KAAOH,EAAO,aAAa,MAGhCA,EAAO,aAAa,eACtBG,EAAO,aAAeH,EAAO,aAAa,cAGrCG,CACT,CAiBO,SAASC,EACdJ,EACAC,EACiB,CACjB,IAAMI,EAAYH,EAA2BF,EAAQC,CAAO,EAEtDE,EAA0B,CAC9B,WAAY,qBACZ,QAAS,YACT,KAAM,SAASH,EAAO,IAAI,GAC1B,IAAKC,CACP,EAEA,OAAID,EAAO,UACTG,EAAO,YAAcH,EAAO,SAG1BK,IACFF,EAAO,WAAaE,GAGfF,CACT,CAKO,SAASG,EACdC,EACAP,EACAC,EACY,CACZ,OAAQM,EAAU,CAChB,IAAK,UACH,OAAOR,EAA6BC,EAAQC,CAAO,EACrD,IAAK,QACH,OAAOG,EAAwBJ,EAAQC,CAAO,EAEhD,QACE,OAAO,IACX,CACF,CAKO,SAASO,EAAgBL,EAAmC,CACjE,OAAKA,EAGE,KAAK,UAAUA,EAAQ,KAAM,CAAC,EAF5B,IAGX","names":["index_exports","__export","extractContent","generateAIOMethodologySchema","generateAboutPageSchema","generateLlmsTxt","generateOrganizationSchema","generateSchemaForPageType","serializeSchema","__toCommonJS","cheerio","import_turndown","turndownService","TurndownService","extractContent","html","sourceUrl","originalSize","$","title","description","jsonLdScripts","_","el","raw","parsed","contentHtml","markdown","finalMarkdown","j","markdownSize","tokenReductionRatio","generateLlmsTxt","config","lines","route","fullUrl","link","section","generateAIOMethodologySchema","config","pageUrl","generateOrganizationSchema","schema","generateAboutPageSchema","orgSchema","generateSchemaForPageType","pageType","serializeSchema"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/extractor.ts","../src/config.ts","../src/schemas.ts"],"sourcesContent":["// We cannot use Webpack plugins reliably in Next.js Turbopack due to WorkerError restrictions.\r\n// Users must instead run `npx onto-next` as a postbuild script.\r\nexport { extractContent } from './extractor';\r\nexport { OntoConfig, OntoRoute, generateLlmsTxt } from './config';\r\nexport type { OntoConfig as OntoConfigType, OntoRoute as OntoRouteType, PageType } from './config';\r\nexport {\r\n generateAIOMethodologySchema,\r\n generateOrganizationSchema,\r\n generateAboutPageSchema,\r\n generateSchemaForPageType,\r\n serializeSchema\r\n} from './schemas';\r\nexport type {\r\n AIOMethodologySchema,\r\n OrganizationSchema,\r\n AboutPageSchema\r\n} from './schemas';\r\n","import * as cheerio from 'cheerio';\r\nimport TurndownService from 'turndown';\r\n\r\nconst turndownService = new TurndownService({\r\n headingStyle: 'atx',\r\n codeBlockStyle: 'fenced',\r\n});\r\n\r\n// Configure turndown to keep some layout or handle semantic tags differently if needed\r\n\r\nexport interface ExtractionResult {\r\n markdown: string;\r\n metadata: {\r\n title: string;\r\n description: string;\r\n jsonLd: any[];\r\n };\r\n stats: {\r\n originalHtmlSize: number;\r\n markdownSize: number;\r\n tokenReductionRatio: number;\r\n };\r\n}\r\n\r\n/**\r\n * Extracts pure semantic markdown and metadata from rendered Next.js HTML strings.\r\n * @param html The raw HTML string.\r\n * @param sourceUrl (Optional) the URL this was generated from, to attach as metadata.\r\n * @returns {ExtractionResult} The extracted payload.\r\n */\r\nexport function extractContent(html: string, sourceUrl: string = 'Generated Output'): ExtractionResult {\r\n const originalSize = html.length;\r\n\r\n const $ = cheerio.load(html);\r\n\r\n // 1. Extract Metadata BEFORE removing structure\r\n const title = $('title').text() || $('h1').first().text() || 'Untitled Page';\r\n const description = $('meta[name=\"description\"]').attr('content') || 'No description found.';\r\n\r\n const jsonLdScripts: any[] = [];\r\n $('script[type=\"application/ld+json\"]').each((_, el) => {\r\n try {\r\n const raw = $(el).html() || '';\r\n const parsed = JSON.parse(raw);\r\n jsonLdScripts.push(parsed);\r\n } catch {\r\n // ignore bad json\r\n }\r\n });\r\n\r\n // 2. Strip noise (React boilerplate, styles, unnecessary tags)\r\n $('script, style, noscript, iframe, svg, nav, footer, meta, link, header').remove();\r\n\r\n // Optionally remove typical Next.js hidden wrappers if they don't contain real content.\r\n // Next.js uses <div id=\"__next\"> but we mostly just want semantic content.\r\n\r\n // 3. Find the entry point for content\r\n // Prefer <main> or <article> over <body>\r\n let contentHtml = '';\r\n if ($('main').length > 0) {\r\n contentHtml = $('main').html() || '';\r\n } else if ($('article').length > 0) {\r\n contentHtml = $('article').html() || '';\r\n } else {\r\n contentHtml = $('body').html() || '';\r\n }\r\n\r\n // 4. Convert to Markdown\r\n let markdown = turndownService.turndown(contentHtml);\r\n\r\n // 5. Optionally inject Metadata header\r\n const headerLines = [\r\n `# ${title}`,\r\n `> ${description}`,\r\n ``,\r\n `**Source:** ${sourceUrl}`,\r\n `**Extracted:** ${new Date().toISOString()}`,\r\n ``,\r\n `---`,\r\n ``\r\n ];\r\n\r\n let finalMarkdown = headerLines.join('\\n') + markdown;\r\n\r\n // Add JSON-LD section if exists\r\n if (jsonLdScripts.length > 0) {\r\n finalMarkdown += '\\n\\n---\\n## Structured Data (JSON-LD)\\n```json\\n';\r\n jsonLdScripts.forEach(j => {\r\n finalMarkdown += JSON.stringify(j, null, 2) + '\\n';\r\n });\r\n finalMarkdown += '```\\n';\r\n }\r\n\r\n const markdownSize = finalMarkdown.length;\r\n const tokenReductionRatio = originalSize > 0 ? ((originalSize - markdownSize) / originalSize) * 100 : 0;\r\n\r\n return {\r\n markdown: finalMarkdown,\r\n metadata: {\r\n title,\r\n description,\r\n jsonLd: jsonLdScripts\r\n },\r\n stats: {\r\n originalHtmlSize: originalSize,\r\n markdownSize,\r\n tokenReductionRatio\r\n }\r\n };\r\n}\r\n\r\nexport async function generateStaticPayloads(nextAppDirDir: string, ontoPublicDir: string) {\r\n const fs = await import('fs');\r\n const path = await import('path');\r\n const { glob } = await import('glob');\r\n\r\n if (!fs.existsSync(nextAppDirDir)) {\r\n return;\r\n }\r\n\r\n const files = await glob('**/*.html', { cwd: nextAppDirDir });\r\n if (files.length === 0) return;\r\n\r\n if (!fs.existsSync(ontoPublicDir)) {\r\n fs.mkdirSync(ontoPublicDir, { recursive: true });\r\n }\r\n\r\n let totalFilesProcessed = 0;\r\n\r\n for (const file of files) {\r\n const inputPath = path.join(nextAppDirDir, file);\r\n const outputPathRelative = file.replace(/\\.html$/, '.md');\r\n const outputPath = path.join(ontoPublicDir, outputPathRelative);\r\n\r\n try {\r\n const htmlContent = fs.readFileSync(inputPath, 'utf8');\r\n\r\n let routeName = file.replace(/\\.html$/, '');\r\n if (routeName === 'index') routeName = '/';\r\n else routeName = `/${routeName}`;\r\n\r\n const result = extractContent(htmlContent, routeName);\r\n\r\n const outputDir = path.dirname(outputPath);\r\n if (!fs.existsSync(outputDir)) {\r\n fs.mkdirSync(outputDir, { recursive: true });\r\n }\r\n\r\n fs.writeFileSync(outputPath, result.markdown, 'utf8');\r\n totalFilesProcessed++;\r\n } catch (e: any) {\r\n console.error(`[Onto] Failed to process ${file}: ${e.message}`);\r\n }\r\n }\r\n console.log(`[Onto] Successfully generated ${totalFilesProcessed} semantic markdown endpoints.`);\r\n}\r\n","/**\r\n * Configuration schema for onto.config.ts\r\n * Used to dynamically generate llms.txt and other AI discovery files\r\n */\r\n\r\nexport type PageType = 'scoring' | 'about' | 'default';\r\n\r\nexport interface OntoRoute {\r\n /**\r\n * The URL path (e.g., '/docs', '/api/reference')\r\n */\r\n path: string;\r\n /**\r\n * Description of what this route contains\r\n */\r\n description: string;\r\n /**\r\n * Optional: Page type for automatic JSON-LD schema injection\r\n * - 'scoring': Injects Methodology schema with AIO scoring weights (40/35/25)\r\n * - 'about': Injects Organization/AboutPage schema\r\n * - 'default': No automatic schema injection\r\n */\r\n pageType?: PageType;\r\n}\r\n\r\nexport interface OntoConfig {\r\n /**\r\n * The name of your project or site (required)\r\n * Used as the H1 heading in llms.txt\r\n */\r\n name: string;\r\n\r\n /**\r\n * A short summary of your project (required)\r\n * Displayed as a blockquote in llms.txt\r\n * Should contain key information necessary for understanding the rest of the file\r\n */\r\n summary: string;\r\n\r\n /**\r\n * The base URL of your site (e.g., 'https://example.com')\r\n */\r\n baseUrl: string;\r\n\r\n /**\r\n * Optional: Additional sections to include in llms.txt\r\n * Each section can contain any markdown content\r\n */\r\n sections?: {\r\n heading: string;\r\n content: string;\r\n }[];\r\n\r\n /**\r\n * Key routes that AI agents should know about\r\n * These will be formatted as a markdown list in llms.txt\r\n */\r\n routes?: OntoRoute[];\r\n\r\n /**\r\n * Optional: Links to external resources (documentation, API references, etc.)\r\n */\r\n externalLinks?: {\r\n title: string;\r\n url: string;\r\n description?: string;\r\n }[];\r\n\r\n /**\r\n * Optional: Organization information for JSON-LD schemas\r\n */\r\n organization?: {\r\n name: string;\r\n description?: string;\r\n url?: string;\r\n logo?: string;\r\n foundingDate?: string;\r\n };\r\n}\r\n\r\n/**\r\n * Generate llms.txt content from OntoConfig\r\n * Follows the llms.txt specification:\r\n * - H1 with project name\r\n * - Blockquote with summary\r\n * - Additional markdown sections\r\n */\r\nexport function generateLlmsTxt(config: OntoConfig): string {\r\n const lines: string[] = [];\r\n\r\n // H1: Project name (required)\r\n lines.push(`# ${config.name}`);\r\n lines.push('');\r\n\r\n // Blockquote: Summary (required)\r\n lines.push(`> ${config.summary}`);\r\n lines.push('');\r\n\r\n // Key Routes section (if provided)\r\n if (config.routes && config.routes.length > 0) {\r\n lines.push('## Key Routes');\r\n lines.push('');\r\n for (const route of config.routes) {\r\n const fullUrl = `${config.baseUrl}${route.path}`;\r\n lines.push(`- [${route.path}](${fullUrl}): ${route.description}`);\r\n }\r\n lines.push('');\r\n }\r\n\r\n // External Links section (if provided)\r\n if (config.externalLinks && config.externalLinks.length > 0) {\r\n lines.push('## Resources');\r\n lines.push('');\r\n for (const link of config.externalLinks) {\r\n if (link.description) {\r\n lines.push(`- [${link.title}](${link.url}): ${link.description}`);\r\n } else {\r\n lines.push(`- [${link.title}](${link.url})`);\r\n }\r\n }\r\n lines.push('');\r\n }\r\n\r\n // Custom sections (if provided)\r\n if (config.sections && config.sections.length > 0) {\r\n for (const section of config.sections) {\r\n lines.push(`## ${section.heading}`);\r\n lines.push('');\r\n lines.push(section.content);\r\n lines.push('');\r\n }\r\n }\r\n\r\n return lines.join('\\n').trim() + '\\n';\r\n}\r\n","/**\r\n * JSON-LD Schema generators for automatic structured data injection\r\n * Follows Schema.org standards for AI-friendly metadata\r\n */\r\n\r\nimport { OntoConfig } from './config';\r\n\r\n/**\r\n * Standard AIO (AI Optimization) scoring methodology\r\n * Based on the Onto scoring algorithm:\r\n * - Content Negotiation: 40% (30 points)\r\n * - React Tax / Token Efficiency: 35% (30 points)\r\n * - Structured Data: 25% (25 points)\r\n * - Semantic HTML: Bonus (15 points)\r\n */\r\nexport interface AIOMethodologySchema {\r\n '@context': 'https://schema.org';\r\n '@type': 'HowTo';\r\n name: string;\r\n description: string;\r\n step: Array<{\r\n '@type': 'HowToStep';\r\n name: string;\r\n text: string;\r\n position: number;\r\n }>;\r\n}\r\n\r\n/**\r\n * Generate AIO Scoring Methodology JSON-LD schema\r\n * This explains to AI agents how the scoring system works\r\n */\r\nexport function generateAIOMethodologySchema(\r\n config: OntoConfig,\r\n pageUrl: string\r\n): AIOMethodologySchema {\r\n return {\r\n '@context': 'https://schema.org',\r\n '@type': 'HowTo',\r\n name: 'AIO Score Calculation Methodology',\r\n description: 'AI Optimization (AIO) Score measures how well a website is optimized for AI agents and LLM crawlers. Scored out of 100 points based on four key metrics.',\r\n step: [\r\n {\r\n '@type': 'HowToStep',\r\n name: 'Content Negotiation',\r\n text: 'Check if the site responds to Accept: text/markdown header. Weight: 40%. Penalty: -30 points if missing. This ensures AI bots receive optimized content instead of heavy HTML.',\r\n position: 1\r\n },\r\n {\r\n '@type': 'HowToStep',\r\n name: 'Token Efficiency (React Tax)',\r\n text: 'Measure the ratio of visible text to total HTML size. Weight: 35%. Penalty: -30 points if HTML > 100KB but text < 1KB. Detects JavaScript-heavy sites that are difficult for AI to parse.',\r\n position: 2\r\n },\r\n {\r\n '@type': 'HowToStep',\r\n name: 'Structured Data',\r\n text: 'Verify presence of JSON-LD structured data (Schema.org). Weight: 25%. Penalty: -25 points if missing. Enables AI to confidently extract pricing, products, and entities.',\r\n position: 3\r\n },\r\n {\r\n '@type': 'HowToStep',\r\n name: 'Semantic HTML',\r\n text: 'Check for semantic tags like <main> and <article>. Bonus: +15 points if present. Helps AI agents separate navigation from core content.',\r\n position: 4\r\n }\r\n ]\r\n };\r\n}\r\n\r\n/**\r\n * Organization schema for About pages\r\n */\r\nexport interface OrganizationSchema {\r\n '@context': 'https://schema.org';\r\n '@type': 'Organization';\r\n name: string;\r\n url?: string;\r\n description?: string;\r\n logo?: string;\r\n foundingDate?: string;\r\n}\r\n\r\n/**\r\n * Generate Organization JSON-LD schema for About pages\r\n */\r\nexport function generateOrganizationSchema(\r\n config: OntoConfig,\r\n pageUrl: string\r\n): OrganizationSchema | null {\r\n if (!config.organization) {\r\n return null;\r\n }\r\n\r\n const schema: OrganizationSchema = {\r\n '@context': 'https://schema.org',\r\n '@type': 'Organization',\r\n name: config.organization.name\r\n };\r\n\r\n if (config.organization.url) {\r\n schema.url = config.organization.url;\r\n }\r\n\r\n if (config.organization.description) {\r\n schema.description = config.organization.description;\r\n }\r\n\r\n if (config.organization.logo) {\r\n schema.logo = config.organization.logo;\r\n }\r\n\r\n if (config.organization.foundingDate) {\r\n schema.foundingDate = config.organization.foundingDate;\r\n }\r\n\r\n return schema;\r\n}\r\n\r\n/**\r\n * AboutPage schema combining Organization and WebPage\r\n */\r\nexport interface AboutPageSchema {\r\n '@context': 'https://schema.org';\r\n '@type': 'AboutPage';\r\n name: string;\r\n url: string;\r\n description?: string;\r\n mainEntity?: OrganizationSchema;\r\n}\r\n\r\n/**\r\n * Generate AboutPage JSON-LD schema\r\n */\r\nexport function generateAboutPageSchema(\r\n config: OntoConfig,\r\n pageUrl: string\r\n): AboutPageSchema {\r\n const orgSchema = generateOrganizationSchema(config, pageUrl);\r\n\r\n const schema: AboutPageSchema = {\r\n '@context': 'https://schema.org',\r\n '@type': 'AboutPage',\r\n name: `About ${config.name}`,\r\n url: pageUrl\r\n };\r\n\r\n if (config.summary) {\r\n schema.description = config.summary;\r\n }\r\n\r\n if (orgSchema) {\r\n schema.mainEntity = orgSchema;\r\n }\r\n\r\n return schema;\r\n}\r\n\r\n/**\r\n * Determine which schema to generate based on page type\r\n */\r\nexport function generateSchemaForPageType(\r\n pageType: 'scoring' | 'about' | 'default',\r\n config: OntoConfig,\r\n pageUrl: string\r\n): any | null {\r\n switch (pageType) {\r\n case 'scoring':\r\n return generateAIOMethodologySchema(config, pageUrl);\r\n case 'about':\r\n return generateAboutPageSchema(config, pageUrl);\r\n case 'default':\r\n default:\r\n return null;\r\n }\r\n}\r\n\r\n/**\r\n * Serialize schema to JSON-LD script tag content\r\n */\r\nexport function serializeSchema(schema: any | null): string | null {\r\n if (!schema) {\r\n return null;\r\n }\r\n return JSON.stringify(schema, null, 2);\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,iCAAAC,EAAA,4BAAAC,EAAA,oBAAAC,EAAA,+BAAAC,EAAA,8BAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAT,GCAA,IAAAU,EAAyB,sBACzBC,EAA4B,uBAEtBC,EAAkB,IAAI,EAAAC,QAAgB,CACxC,aAAc,MACd,eAAgB,QACpB,CAAC,EAwBM,SAASC,EAAeC,EAAcC,EAAoB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,WAAY,qBACZ,QAAS,QACT,KAAM,oCACN,YAAa,2JACb,KAAM,CACJ,CACE,QAAS,YACT,KAAM,sBACN,KAAM,iLACN,SAAU,CACZ,EACA,CACE,QAAS,YACT,KAAM,+BACN,KAAM,4LACN,SAAU,CACZ,EACA,CACE,QAAS,YACT,KAAM,kBACN,KAAM,2KACN,SAAU,CACZ,EACA,CACE,QAAS,YACT,KAAM,gBACN,KAAM,0IACN,SAAU,CACZ,CACF,CACF,CACF,CAkBO,SAASC,EACdF,EACAC,EAC2B,CAC3B,GAAI,CAACD,EAAO,aACV,OAAO,KAGT,IAAMG,EAA6B,CACjC,WAAY,qBACZ,QAAS,eACT,KAAMH,EAAO,aAAa,IAC5B,EAEA,OAAIA,EAAO,aAAa,MACtBG,EAAO,IAAMH,EAAO,aAAa,KAG/BA,EAAO,aAAa,cACtBG,EAAO,YAAcH,EAAO,aAAa,aAGvCA,EAAO,aAAa,OACtBG,EAAO,KAAOH,EAAO,aAAa,MAGhCA,EAAO,aAAa,eACtBG,EAAO,aAAeH,EAAO,aAAa,cAGrCG,CACT,CAiBO,SAASC,EACdJ,EACAC,EACiB,CACjB,IAAMI,EAAYH,EAA2BF,EAAQC,CAAO,EAEtDE,EAA0B,CAC9B,WAAY,qBACZ,QAAS,YACT,KAAM,SAASH,EAAO,IAAI,GAC1B,IAAKC,CACP,EAEA,OAAID,EAAO,UACTG,EAAO,YAAcH,EAAO,SAG1BK,IACFF,EAAO,WAAaE,GAGfF,CACT,CAKO,SAASG,EACdC,EACAP,EACAC,EACY,CACZ,OAAQM,EAAU,CAChB,IAAK,UACH,OAAOR,EAA6BC,EAAQC,CAAO,EACrD,IAAK,QACH,OAAOG,EAAwBJ,EAAQC,CAAO,EAEhD,QACE,OAAO,IACX,CACF,CAKO,SAASO,EAAgBL,EAAmC,CACjE,OAAKA,EAGE,KAAK,UAAUA,EAAQ,KAAM,CAAC,EAF5B,IAGX","names":["index_exports","__export","extractContent","generateAIOMethodologySchema","generateAboutPageSchema","generateLlmsTxt","generateOrganizationSchema","generateSchemaForPageType","serializeSchema","__toCommonJS","cheerio","import_turndown","turndownService","TurndownService","extractContent","html","sourceUrl","originalSize","$","title","description","jsonLdScripts","_","el","raw","parsed","contentHtml","markdown","finalMarkdown","j","markdownSize","tokenReductionRatio","generateLlmsTxt","config","lines","route","fullUrl","link","section","generateAIOMethodologySchema","config","pageUrl","generateOrganizationSchema","schema","generateAboutPageSchema","orgSchema","generateSchemaForPageType","pageType","serializeSchema"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import*as p from"cheerio";import O from"turndown";var w=new O({headingStyle:"atx",codeBlockStyle:"fenced"});function z(t,n="Generated Output"){let e=t.length,o=p.load(t),s=o("title").text()||o("h1").first().text()||"Untitled Page",c=o('meta[name="description"]').attr("content")||"No description found.",r=[];o('script[type="application/ld+json"]').each((
|
|
1
|
+
import*as p from"cheerio";import O from"turndown";var w=new O({headingStyle:"atx",codeBlockStyle:"fenced"});function z(t,n="Generated Output"){let e=t.length,o=p.load(t),s=o("title").text()||o("h1").first().text()||"Untitled Page",c=o('meta[name="description"]').attr("content")||"No description found.",r=[];o('script[type="application/ld+json"]').each((l,y)=>{try{let S=o(y).html()||"",x=JSON.parse(S);r.push(x)}catch{}}),o("script, style, noscript, iframe, svg, nav, footer, meta, link, header").remove();let a="";o("main").length>0?a=o("main").html()||"":o("article").length>0?a=o("article").html()||"":a=o("body").html()||"";let d=w.turndown(a),i=[`# ${s}`,`> ${c}`,"",`**Source:** ${n}`,`**Extracted:** ${new Date().toISOString()}`,"","---",""].join(`
|
|
2
2
|
`)+d;r.length>0&&(i+=`
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
## Structured Data (JSON-LD)
|
|
6
6
|
\`\`\`json
|
|
7
|
-
`,r.forEach(
|
|
8
|
-
`}),i+="```\n");let
|
|
7
|
+
`,r.forEach(l=>{i+=JSON.stringify(l,null,2)+`
|
|
8
|
+
`}),i+="```\n");let u=i.length,f=e>0?(e-u)/e*100:0;return{markdown:i,metadata:{title:s,description:c,jsonLd:r},stats:{originalHtmlSize:e,markdownSize:u,tokenReductionRatio:f}}}function k(t){let n=[];if(n.push(`# ${t.name}`),n.push(""),n.push(`> ${t.summary}`),n.push(""),t.routes&&t.routes.length>0){n.push("## Key Routes"),n.push("");for(let e of t.routes){let o=`${t.baseUrl}${e.path}`;n.push(`- [${e.path}](${o}): ${e.description}`)}n.push("")}if(t.externalLinks&&t.externalLinks.length>0){n.push("## Resources"),n.push("");for(let e of t.externalLinks)e.description?n.push(`- [${e.title}](${e.url}): ${e.description}`):n.push(`- [${e.title}](${e.url})`);n.push("")}if(t.sections&&t.sections.length>0)for(let e of t.sections)n.push(`## ${e.heading}`),n.push(""),n.push(e.content),n.push("");return n.join(`
|
|
9
9
|
`).trim()+`
|
|
10
10
|
`}function g(t,n){return{"@context":"https://schema.org","@type":"HowTo",name:"AIO Score Calculation Methodology",description:"AI Optimization (AIO) Score measures how well a website is optimized for AI agents and LLM crawlers. Scored out of 100 points based on four key metrics.",step:[{"@type":"HowToStep",name:"Content Negotiation",text:"Check if the site responds to Accept: text/markdown header. Weight: 40%. Penalty: -30 points if missing. This ensures AI bots receive optimized content instead of heavy HTML.",position:1},{"@type":"HowToStep",name:"Token Efficiency (React Tax)",text:"Measure the ratio of visible text to total HTML size. Weight: 35%. Penalty: -30 points if HTML > 100KB but text < 1KB. Detects JavaScript-heavy sites that are difficult for AI to parse.",position:2},{"@type":"HowToStep",name:"Structured Data",text:"Verify presence of JSON-LD structured data (Schema.org). Weight: 25%. Penalty: -25 points if missing. Enables AI to confidently extract pricing, products, and entities.",position:3},{"@type":"HowToStep",name:"Semantic HTML",text:"Check for semantic tags like <main> and <article>. Bonus: +15 points if present. Helps AI agents separate navigation from core content.",position:4}]}}function m(t,n){if(!t.organization)return null;let e={"@context":"https://schema.org","@type":"Organization",name:t.organization.name};return t.organization.url&&(e.url=t.organization.url),t.organization.description&&(e.description=t.organization.description),t.organization.logo&&(e.logo=t.organization.logo),t.organization.foundingDate&&(e.foundingDate=t.organization.foundingDate),e}function h(t,n){let e=m(t,n),o={"@context":"https://schema.org","@type":"AboutPage",name:`About ${t.name}`,url:n};return t.summary&&(o.description=t.summary),e&&(o.mainEntity=e),o}function T(t,n,e){switch(t){case"scoring":return g(n,e);case"about":return h(n,e);default:return null}}function $(t){return t?JSON.stringify(t,null,2):null}export{z as extractContent,g as generateAIOMethodologySchema,h as generateAboutPageSchema,k as generateLlmsTxt,m as generateOrganizationSchema,T as generateSchemaForPageType,$ as serializeSchema};
|
|
11
11
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { OntoConfig } from './config.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Comprehensive registry of AI bot user-agent strings.
|
|
6
|
+
* The middleware uses this list to detect AI crawlers and serve optimized markdown.
|
|
7
|
+
*/
|
|
8
|
+
interface AiBot {
|
|
9
|
+
/** The user-agent substring to match against */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The company operating this bot */
|
|
12
|
+
company: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Flat list of user-agent substrings for fast matching in the middleware.
|
|
16
|
+
*/
|
|
17
|
+
declare const AI_BOT_USER_AGENTS: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Given a raw user-agent string, returns the matched AiBot entry or undefined.
|
|
20
|
+
* Comparison is case-insensitive to handle inconsistent agent casing.
|
|
21
|
+
*/
|
|
22
|
+
declare function matchBot(userAgent: string | null): AiBot | undefined;
|
|
23
|
+
|
|
24
|
+
declare function ontoMiddleware(request: NextRequest, config?: OntoConfig): Promise<NextResponse<unknown>>;
|
|
25
|
+
|
|
26
|
+
export { AI_BOT_USER_AGENTS, type AiBot, matchBot, ontoMiddleware };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { OntoConfig } from './config.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Comprehensive registry of AI bot user-agent strings.
|
|
6
|
+
* The middleware uses this list to detect AI crawlers and serve optimized markdown.
|
|
7
|
+
*/
|
|
8
|
+
interface AiBot {
|
|
9
|
+
/** The user-agent substring to match against */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The company operating this bot */
|
|
12
|
+
company: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Flat list of user-agent substrings for fast matching in the middleware.
|
|
16
|
+
*/
|
|
17
|
+
declare const AI_BOT_USER_AGENTS: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Given a raw user-agent string, returns the matched AiBot entry or undefined.
|
|
20
|
+
* Comparison is case-insensitive to handle inconsistent agent casing.
|
|
21
|
+
*/
|
|
22
|
+
declare function matchBot(userAgent: string | null): AiBot | undefined;
|
|
23
|
+
|
|
24
|
+
declare function ontoMiddleware(request: NextRequest, config?: OntoConfig): Promise<NextResponse<unknown>>;
|
|
25
|
+
|
|
26
|
+
export { AI_BOT_USER_AGENTS, type AiBot, matchBot, ontoMiddleware };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { OntoConfig } from './config.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* JSON-LD Schema generators for automatic structured data injection
|
|
5
|
+
* Follows Schema.org standards for AI-friendly metadata
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Standard AIO (AI Optimization) scoring methodology
|
|
10
|
+
* Based on the Onto scoring algorithm:
|
|
11
|
+
* - Content Negotiation: 40% (30 points)
|
|
12
|
+
* - React Tax / Token Efficiency: 35% (30 points)
|
|
13
|
+
* - Structured Data: 25% (25 points)
|
|
14
|
+
* - Semantic HTML: Bonus (15 points)
|
|
15
|
+
*/
|
|
16
|
+
interface AIOMethodologySchema {
|
|
17
|
+
'@context': 'https://schema.org';
|
|
18
|
+
'@type': 'HowTo';
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
step: Array<{
|
|
22
|
+
'@type': 'HowToStep';
|
|
23
|
+
name: string;
|
|
24
|
+
text: string;
|
|
25
|
+
position: number;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generate AIO Scoring Methodology JSON-LD schema
|
|
30
|
+
* This explains to AI agents how the scoring system works
|
|
31
|
+
*/
|
|
32
|
+
declare function generateAIOMethodologySchema(config: OntoConfig, pageUrl: string): AIOMethodologySchema;
|
|
33
|
+
/**
|
|
34
|
+
* Organization schema for About pages
|
|
35
|
+
*/
|
|
36
|
+
interface OrganizationSchema {
|
|
37
|
+
'@context': 'https://schema.org';
|
|
38
|
+
'@type': 'Organization';
|
|
39
|
+
name: string;
|
|
40
|
+
url?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
logo?: string;
|
|
43
|
+
foundingDate?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generate Organization JSON-LD schema for About pages
|
|
47
|
+
*/
|
|
48
|
+
declare function generateOrganizationSchema(config: OntoConfig, pageUrl: string): OrganizationSchema | null;
|
|
49
|
+
/**
|
|
50
|
+
* AboutPage schema combining Organization and WebPage
|
|
51
|
+
*/
|
|
52
|
+
interface AboutPageSchema {
|
|
53
|
+
'@context': 'https://schema.org';
|
|
54
|
+
'@type': 'AboutPage';
|
|
55
|
+
name: string;
|
|
56
|
+
url: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
mainEntity?: OrganizationSchema;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generate AboutPage JSON-LD schema
|
|
62
|
+
*/
|
|
63
|
+
declare function generateAboutPageSchema(config: OntoConfig, pageUrl: string): AboutPageSchema;
|
|
64
|
+
/**
|
|
65
|
+
* Determine which schema to generate based on page type
|
|
66
|
+
*/
|
|
67
|
+
declare function generateSchemaForPageType(pageType: 'scoring' | 'about' | 'default', config: OntoConfig, pageUrl: string): any | null;
|
|
68
|
+
/**
|
|
69
|
+
* Serialize schema to JSON-LD script tag content
|
|
70
|
+
*/
|
|
71
|
+
declare function serializeSchema(schema: any | null): string | null;
|
|
72
|
+
|
|
73
|
+
export { type AIOMethodologySchema, type AboutPageSchema, type OrganizationSchema, generateAIOMethodologySchema, generateAboutPageSchema, generateOrganizationSchema, generateSchemaForPageType, serializeSchema };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { OntoConfig } from './config.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* JSON-LD Schema generators for automatic structured data injection
|
|
5
|
+
* Follows Schema.org standards for AI-friendly metadata
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Standard AIO (AI Optimization) scoring methodology
|
|
10
|
+
* Based on the Onto scoring algorithm:
|
|
11
|
+
* - Content Negotiation: 40% (30 points)
|
|
12
|
+
* - React Tax / Token Efficiency: 35% (30 points)
|
|
13
|
+
* - Structured Data: 25% (25 points)
|
|
14
|
+
* - Semantic HTML: Bonus (15 points)
|
|
15
|
+
*/
|
|
16
|
+
interface AIOMethodologySchema {
|
|
17
|
+
'@context': 'https://schema.org';
|
|
18
|
+
'@type': 'HowTo';
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
step: Array<{
|
|
22
|
+
'@type': 'HowToStep';
|
|
23
|
+
name: string;
|
|
24
|
+
text: string;
|
|
25
|
+
position: number;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generate AIO Scoring Methodology JSON-LD schema
|
|
30
|
+
* This explains to AI agents how the scoring system works
|
|
31
|
+
*/
|
|
32
|
+
declare function generateAIOMethodologySchema(config: OntoConfig, pageUrl: string): AIOMethodologySchema;
|
|
33
|
+
/**
|
|
34
|
+
* Organization schema for About pages
|
|
35
|
+
*/
|
|
36
|
+
interface OrganizationSchema {
|
|
37
|
+
'@context': 'https://schema.org';
|
|
38
|
+
'@type': 'Organization';
|
|
39
|
+
name: string;
|
|
40
|
+
url?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
logo?: string;
|
|
43
|
+
foundingDate?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generate Organization JSON-LD schema for About pages
|
|
47
|
+
*/
|
|
48
|
+
declare function generateOrganizationSchema(config: OntoConfig, pageUrl: string): OrganizationSchema | null;
|
|
49
|
+
/**
|
|
50
|
+
* AboutPage schema combining Organization and WebPage
|
|
51
|
+
*/
|
|
52
|
+
interface AboutPageSchema {
|
|
53
|
+
'@context': 'https://schema.org';
|
|
54
|
+
'@type': 'AboutPage';
|
|
55
|
+
name: string;
|
|
56
|
+
url: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
mainEntity?: OrganizationSchema;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generate AboutPage JSON-LD schema
|
|
62
|
+
*/
|
|
63
|
+
declare function generateAboutPageSchema(config: OntoConfig, pageUrl: string): AboutPageSchema;
|
|
64
|
+
/**
|
|
65
|
+
* Determine which schema to generate based on page type
|
|
66
|
+
*/
|
|
67
|
+
declare function generateSchemaForPageType(pageType: 'scoring' | 'about' | 'default', config: OntoConfig, pageUrl: string): any | null;
|
|
68
|
+
/**
|
|
69
|
+
* Serialize schema to JSON-LD script tag content
|
|
70
|
+
*/
|
|
71
|
+
declare function serializeSchema(schema: any | null): string | null;
|
|
72
|
+
|
|
73
|
+
export { type AIOMethodologySchema, type AboutPageSchema, type OrganizationSchema, generateAIOMethodologySchema, generateAboutPageSchema, generateOrganizationSchema, generateSchemaForPageType, serializeSchema };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// We cannot use Webpack plugins reliably in Next.js Turbopack due to WorkerError restrictions.
|
|
2
2
|
// Users must instead run `npx onto-next` as a postbuild script.
|
|
3
3
|
export { extractContent } from './extractor';
|
|
4
|
-
export { OntoConfig, OntoRoute,
|
|
4
|
+
export { OntoConfig, OntoRoute, generateLlmsTxt } from './config';
|
|
5
5
|
export type { OntoConfig as OntoConfigType, OntoRoute as OntoRouteType, PageType } from './config';
|
|
6
6
|
export {
|
|
7
7
|
generateAIOMethodologySchema,
|