peam 0.1.1
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/LICENSE +201 -0
- package/README.md +67 -0
- package/dist/chunk-BJTO5JO5.mjs +10 -0
- package/dist/chunk-BJTO5JO5.mjs.map +1 -0
- package/dist/cli.js +251 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.mts +5 -0
- package/dist/client.d.ts +5 -0
- package/dist/client.js +14 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +3 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +250 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +238 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.d.mts +1 -0
- package/dist/logger.d.ts +1 -0
- package/dist/logger.js +12 -0
- package/dist/logger.js.map +1 -0
- package/dist/logger.mjs +4 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/parser.d.mts +1 -0
- package/dist/parser.d.ts +1 -0
- package/dist/parser.js +24 -0
- package/dist/parser.js.map +1 -0
- package/dist/parser.mjs +4 -0
- package/dist/parser.mjs.map +1 -0
- package/dist/search.d.mts +1 -0
- package/dist/search.d.ts +1 -0
- package/dist/search.js +16 -0
- package/dist/search.js.map +1 -0
- package/dist/search.mjs +4 -0
- package/dist/search.mjs.map +1 -0
- package/dist/server.d.mts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +14 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +3 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Peam
|
|
2
|
+
|
|
3
|
+
AI that knows your website.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
For detailed documentation, visit [peam.ai/docs](https://peam.ai/docs)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install peam
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Client Components
|
|
18
|
+
|
|
19
|
+
Add the `AskAI` component to your app (e.g. Next.js):
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { AskAI } from 'peam/client';
|
|
23
|
+
|
|
24
|
+
export default function Layout({ children }) {
|
|
25
|
+
return (
|
|
26
|
+
<html>
|
|
27
|
+
<body>
|
|
28
|
+
{children}
|
|
29
|
+
<AskAI />
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Server Handler
|
|
37
|
+
|
|
38
|
+
Create an API route handler:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { createHandler } from 'peam/server';
|
|
42
|
+
import { openai } from '@ai-sdk/openai';
|
|
43
|
+
|
|
44
|
+
export const POST = createHandler({
|
|
45
|
+
model: openai('gpt-4o'),
|
|
46
|
+
getSearchEngine: async () => mySearchEngine,
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### CLI
|
|
51
|
+
|
|
52
|
+
Extract and index your static site:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Index your built site
|
|
56
|
+
peam ./out
|
|
57
|
+
|
|
58
|
+
# Exclude specific paths
|
|
59
|
+
peam ./out --exclude "/admin/**,/api/*"
|
|
60
|
+
|
|
61
|
+
# Specify output directory
|
|
62
|
+
peam ./out --output .peam
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
Apache-2.0
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export { __require };
|
|
9
|
+
//# sourceMappingURL=chunk-BJTO5JO5.mjs.map
|
|
10
|
+
//# sourceMappingURL=chunk-BJTO5JO5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-BJTO5JO5.mjs"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var parser = require('@peam-ai/parser');
|
|
5
|
+
var search = require('@peam-ai/search');
|
|
6
|
+
var chalk = require('chalk');
|
|
7
|
+
var commander = require('commander');
|
|
8
|
+
var fg = require('fast-glob');
|
|
9
|
+
var fs = require('fs');
|
|
10
|
+
var path = require('path');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
15
|
+
var fg__default = /*#__PURE__*/_interopDefault(fg);
|
|
16
|
+
|
|
17
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
18
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
19
|
+
}) : x)(function(x) {
|
|
20
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
21
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
22
|
+
});
|
|
23
|
+
var packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../package.json"), "utf-8"));
|
|
24
|
+
function parseExcludePatterns(value) {
|
|
25
|
+
return value.split(",").map((p) => p.trim()).filter(Boolean);
|
|
26
|
+
}
|
|
27
|
+
var log = {
|
|
28
|
+
success: (message) => console.log(chalk__default.default.green("\u2713 ") + message),
|
|
29
|
+
error: (message) => console.error(chalk__default.default.red("\u2717 ") + message),
|
|
30
|
+
warn: (message) => console.warn(chalk__default.default.yellow("\u26A0 ") + message),
|
|
31
|
+
info: (message) => console.log(chalk__default.default.blue("\u2139 ") + message),
|
|
32
|
+
text: (message) => console.log(message),
|
|
33
|
+
cyan: (text) => chalk__default.default.cyan(text),
|
|
34
|
+
gray: (text) => chalk__default.default.gray(text),
|
|
35
|
+
bold: (text) => chalk__default.default.bold(text),
|
|
36
|
+
yellow: (text) => chalk__default.default.yellow(text),
|
|
37
|
+
red: (text) => chalk__default.default.red(text),
|
|
38
|
+
green: (text) => chalk__default.default.green(text)
|
|
39
|
+
};
|
|
40
|
+
async function discoverHtmlFiles(sourceDir, globPattern, projectDir) {
|
|
41
|
+
const pages = [];
|
|
42
|
+
try {
|
|
43
|
+
const sourceFullPath = path.join(projectDir, sourceDir);
|
|
44
|
+
const htmlFiles = await fg__default.default(globPattern, {
|
|
45
|
+
cwd: sourceFullPath,
|
|
46
|
+
absolute: true,
|
|
47
|
+
onlyFiles: true,
|
|
48
|
+
dot: false,
|
|
49
|
+
ignore: ["**/_next/**", "**/_astro/**", "**/404.{html,htm}", "**/500.{html,htm}"]
|
|
50
|
+
});
|
|
51
|
+
for (const htmlFilePath of htmlFiles) {
|
|
52
|
+
const relativePath = path.relative(sourceFullPath, htmlFilePath);
|
|
53
|
+
const pathname = parser.filePathToPathname(relativePath);
|
|
54
|
+
pages.push({
|
|
55
|
+
pathname,
|
|
56
|
+
htmlFilePath,
|
|
57
|
+
relativeHtmlPath: relativePath
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
} catch (error) {
|
|
61
|
+
log.warn(`Error discovering HTML files: ${error}`);
|
|
62
|
+
}
|
|
63
|
+
return pages;
|
|
64
|
+
}
|
|
65
|
+
async function indexPages(config) {
|
|
66
|
+
var _a;
|
|
67
|
+
log.text("\n" + log.bold(log.cyan("Peam Static Site Indexer")) + "\n");
|
|
68
|
+
log.text(log.bold("Configuration:"));
|
|
69
|
+
log.text(` Project Directory: ${log.gray(config.projectDir)}`);
|
|
70
|
+
log.text(` Source Directory: ${log.gray(config.source)}`);
|
|
71
|
+
log.text(` Glob Pattern: ${log.gray(config.glob)}`);
|
|
72
|
+
log.text(` Output Directory: ${log.gray(config.outputDir)}`);
|
|
73
|
+
log.text(` Index Filename: ${log.gray(config.indexFilename)}`);
|
|
74
|
+
log.text(` Respect robots.txt: ${log.gray(config.respectRobotsTxt.toString())}`);
|
|
75
|
+
if (config.exclude.length > 0) {
|
|
76
|
+
log.text(` Exclude Patterns: ${log.gray(config.exclude.join(", "))}`);
|
|
77
|
+
}
|
|
78
|
+
log.text("");
|
|
79
|
+
const sourcePath = path.join(config.projectDir, config.source);
|
|
80
|
+
if (!fs.existsSync(sourcePath)) {
|
|
81
|
+
log.error(`Source directory not found: ${sourcePath}`);
|
|
82
|
+
log.text(log.yellow(" Please build your site first or specify the correct --source directory"));
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
const searchPaths = [path.join(config.source, "robots.txt"), "public/robots.txt", "robots.txt"];
|
|
86
|
+
const robotsResult = config.respectRobotsTxt ? parser.loadRobotsTxt(config.projectDir, searchPaths, config.robotsTxtPath) : null;
|
|
87
|
+
if (robotsResult && config.respectRobotsTxt) {
|
|
88
|
+
log.info(`robots.txt loaded from ${log.cyan(path.relative(config.projectDir, robotsResult.path))}`);
|
|
89
|
+
} else if (config.respectRobotsTxt) {
|
|
90
|
+
log.info("No robots.txt found, all paths will be indexed");
|
|
91
|
+
}
|
|
92
|
+
log.text(log.bold("Discovering HTML files..."));
|
|
93
|
+
log.text("");
|
|
94
|
+
log.text(` Scanning: ${log.gray(config.source)}`);
|
|
95
|
+
log.text(` Pattern: ${log.gray(config.glob)}`);
|
|
96
|
+
log.text("");
|
|
97
|
+
const discoveredPages = await discoverHtmlFiles(config.source, config.glob, config.projectDir);
|
|
98
|
+
if (discoveredPages.length === 0) {
|
|
99
|
+
log.text("");
|
|
100
|
+
log.warn("No HTML files found");
|
|
101
|
+
log.text(log.yellow(" Check that your source directory contains HTML files"));
|
|
102
|
+
log.text(log.yellow(` Source: ${sourcePath}`));
|
|
103
|
+
log.text(log.yellow(` Pattern: ${config.glob}`));
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
const uniquePages = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const page of discoveredPages) {
|
|
108
|
+
if (!uniquePages.has(page.pathname)) {
|
|
109
|
+
uniquePages.set(page.pathname, page);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
log.text("");
|
|
113
|
+
log.success(`Found ${log.bold(uniquePages.size.toString())} unique pages`);
|
|
114
|
+
log.text("");
|
|
115
|
+
log.text(log.bold("Processing pages..."));
|
|
116
|
+
log.text("");
|
|
117
|
+
const processedPages = [];
|
|
118
|
+
for (const [pathname, page] of uniquePages) {
|
|
119
|
+
const result = parser.shouldIncludePath(pathname, (_a = robotsResult == null ? void 0 : robotsResult.parser) != null ? _a : null, config.exclude, config.respectRobotsTxt);
|
|
120
|
+
if (!result.included) {
|
|
121
|
+
if (result.reason === "robots-txt") {
|
|
122
|
+
log.error(`Excluded by robots.txt: ${pathname}`);
|
|
123
|
+
} else if (result.reason === "exclude-pattern") {
|
|
124
|
+
log.error(`Excluded by pattern: ${pathname}`);
|
|
125
|
+
}
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const html = fs.readFileSync(page.htmlFilePath, "utf-8");
|
|
130
|
+
const structuredPage = parser.parseHTML(html);
|
|
131
|
+
if (!structuredPage) {
|
|
132
|
+
log.warn(`No content extracted from ${log.gray(pathname)}`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
log.success(`${log.cyan(pathname)}`);
|
|
136
|
+
processedPages.push({
|
|
137
|
+
path: pathname,
|
|
138
|
+
htmlFile: page.relativeHtmlPath,
|
|
139
|
+
structuredPage
|
|
140
|
+
});
|
|
141
|
+
} catch (error) {
|
|
142
|
+
log.error(`Error processing ${log.gray(pathname)}: ${error}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
log.text("");
|
|
146
|
+
log.success(`Successfully processed ${log.bold(processedPages.length.toString())} pages`);
|
|
147
|
+
log.text("");
|
|
148
|
+
log.text(log.bold("Creating search index..."));
|
|
149
|
+
log.text("");
|
|
150
|
+
const searchIndexData = await search.buildSearchIndex(processedPages);
|
|
151
|
+
log.success(`Added ${log.bold(processedPages.length.toString())} pages to search index`);
|
|
152
|
+
log.text("");
|
|
153
|
+
log.text(log.bold("Saving index..."));
|
|
154
|
+
log.text("");
|
|
155
|
+
const outputPath = path.join(config.projectDir, config.outputDir);
|
|
156
|
+
fs.mkdirSync(outputPath, { recursive: true });
|
|
157
|
+
const generatedPath = path.join(outputPath, "generated");
|
|
158
|
+
fs.mkdirSync(generatedPath, { recursive: true });
|
|
159
|
+
const searchIndexFile = path.join(generatedPath, config.indexFilename);
|
|
160
|
+
fs.writeFileSync(searchIndexFile, JSON.stringify(searchIndexData));
|
|
161
|
+
const indexJsContent = `// Auto-generated by Peam - DO NOT EDIT THIS FILE
|
|
162
|
+
import index from "./generated/${config.indexFilename}";
|
|
163
|
+
export default index;
|
|
164
|
+
`;
|
|
165
|
+
const indexJsFile = path.join(outputPath, "index.js");
|
|
166
|
+
fs.writeFileSync(indexJsFile, indexJsContent);
|
|
167
|
+
log.success(`Index saved to: ${log.cyan(path.relative(config.projectDir, searchIndexFile))}`);
|
|
168
|
+
log.text(` Total pages indexed: ${log.bold(processedPages.length.toString())}`);
|
|
169
|
+
log.text(
|
|
170
|
+
` Index size: ${log.bold((Buffer.byteLength(JSON.stringify(searchIndexData), "utf8") / 1024).toFixed(2))} KB`
|
|
171
|
+
);
|
|
172
|
+
log.text("");
|
|
173
|
+
log.success(log.bold("Indexing complete!"));
|
|
174
|
+
log.text("");
|
|
175
|
+
}
|
|
176
|
+
function probeSourceDirectory(projectDir) {
|
|
177
|
+
const commonDirs = [".next", ".build", ".out"];
|
|
178
|
+
for (const dir of commonDirs) {
|
|
179
|
+
const fullPath = path.join(projectDir, dir);
|
|
180
|
+
if (fs.existsSync(fullPath)) {
|
|
181
|
+
return dir;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
async function main() {
|
|
187
|
+
const program = new commander.Command();
|
|
188
|
+
program.name("peam").description("Peam static site indexer (Next.js, Hugo, etc.)").version(packageJson.version).option("--source <path>", "Source directory containing HTML files (auto-detected if not provided)").option("--glob <pattern>", "Glob pattern for HTML files", "**/*.{html,htm}").option("--output-dir <path>", "Output directory for index", ".peam").option("--index-filename <name>", "Name of index file", "index.json").option("--ignore-robots-txt", "Disable robots.txt checking").option("--robots-path <path>", "Custom path to robots.txt file").option("--exclude <patterns>", "Comma-separated exclude patterns", parseExcludePatterns, []).option("--project-dir <path>", "Project root directory", process.cwd()).addHelpText(
|
|
189
|
+
"after",
|
|
190
|
+
`
|
|
191
|
+
Examples:
|
|
192
|
+
# Auto-detect build directory
|
|
193
|
+
$ peam
|
|
194
|
+
|
|
195
|
+
# Hugo
|
|
196
|
+
$ peam --source public
|
|
197
|
+
|
|
198
|
+
# Next.js
|
|
199
|
+
$ peam --source .next
|
|
200
|
+
|
|
201
|
+
# Custom output directory
|
|
202
|
+
$ peam --source dist --glob "**/*.html"
|
|
203
|
+
|
|
204
|
+
# Exclude patterns
|
|
205
|
+
$ peam --exclude "/admin/**,/api/*,/private-*"
|
|
206
|
+
|
|
207
|
+
For Next.js 15+, the @peam-ai/next integration is recommended for production use.
|
|
208
|
+
|
|
209
|
+
More information: https://peam.ai
|
|
210
|
+
`
|
|
211
|
+
).parse();
|
|
212
|
+
const options = program.opts();
|
|
213
|
+
try {
|
|
214
|
+
let sourceDir = options.source;
|
|
215
|
+
if (!sourceDir) {
|
|
216
|
+
const probedDir = probeSourceDirectory(options.projectDir);
|
|
217
|
+
if (probedDir) {
|
|
218
|
+
sourceDir = probedDir;
|
|
219
|
+
log.info(`Auto-detected source directory: ${log.cyan(probedDir)}`);
|
|
220
|
+
log.text("");
|
|
221
|
+
} else {
|
|
222
|
+
log.error("No build output directory found");
|
|
223
|
+
log.text(log.yellow(" Searched for: .next, .build, .out"));
|
|
224
|
+
log.text(log.yellow(" Please build your site first or specify --source <directory>"));
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const config = {
|
|
229
|
+
source: sourceDir,
|
|
230
|
+
glob: options.glob,
|
|
231
|
+
outputDir: options.outputDir,
|
|
232
|
+
indexFilename: options.indexFilename,
|
|
233
|
+
respectRobotsTxt: !options.ignoreRobotsTxt,
|
|
234
|
+
robotsTxtPath: options.robotsPath,
|
|
235
|
+
exclude: options.exclude,
|
|
236
|
+
projectDir: options.projectDir
|
|
237
|
+
};
|
|
238
|
+
await indexPages(config);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
log.text("");
|
|
241
|
+
log.error(`Fatal error: ${error}`);
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (__require.main === module) {
|
|
246
|
+
main();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
exports.indexPages = indexPages;
|
|
250
|
+
//# sourceMappingURL=cli.js.map
|
|
251
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"names":["readFileSync","join","chalk","fg","relative","filePathToPathname","existsSync","loadRobotsTxt","shouldIncludePath","parseHTML","buildSearchIndex","mkdirSync","writeFileSync","Command"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeA,IAAM,WAAA,GAAc,KAAK,KAAA,CAAMA,eAAA,CAAaC,UAAK,SAAA,EAAW,iBAAiB,CAAA,EAAG,OAAO,CAAC,CAAA;AAmBxF,SAAS,qBAAqB,KAAA,EAAyB;AACrD,EAAA,OAAO,KAAA,CACJ,KAAA,CAAM,GAAG,CAAA,CACT,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,EAAM,CAAA,CACnB,MAAA,CAAO,OAAO,CAAA;AACnB;AAEA,IAAM,GAAA,GAAM;AAAA,EACV,OAAA,EAAS,CAAC,OAAA,KAAoB,OAAA,CAAQ,IAAIC,sBAAA,CAAM,KAAA,CAAM,SAAI,CAAA,GAAI,OAAO,CAAA;AAAA,EACrE,KAAA,EAAO,CAAC,OAAA,KAAoB,OAAA,CAAQ,MAAMA,sBAAA,CAAM,GAAA,CAAI,SAAI,CAAA,GAAI,OAAO,CAAA;AAAA,EACnE,IAAA,EAAM,CAAC,OAAA,KAAoB,OAAA,CAAQ,KAAKA,sBAAA,CAAM,MAAA,CAAO,SAAI,CAAA,GAAI,OAAO,CAAA;AAAA,EACpE,IAAA,EAAM,CAAC,OAAA,KAAoB,OAAA,CAAQ,IAAIA,sBAAA,CAAM,IAAA,CAAK,SAAI,CAAA,GAAI,OAAO,CAAA;AAAA,EACjE,IAAA,EAAM,CAAC,OAAA,KAAoB,OAAA,CAAQ,IAAI,OAAO,CAAA;AAAA,EAE9C,IAAA,EAAM,CAAC,IAAA,KAAiBA,sBAAA,CAAM,KAAK,IAAI,CAAA;AAAA,EACvC,IAAA,EAAM,CAAC,IAAA,KAAiBA,sBAAA,CAAM,KAAK,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CAAC,CAAA,CAAE,CAAA;AACjE,QAAA,GAAA,CAAI,KAAK,EAAE,CAAA;AAAA,MACb,CAAA,MAAO;AACL,QAAA,GAAA,CAAI,MAAM,iCAAiC,CAAA;AAC3C,QAAA,GAAA,CAAI,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,sCAAsC,CAAC,CAAA;AAC3D,QAAA,GAAA,CAAI,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,iEAAiE,CAAC,CAAA;AACtF,QAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,MAChB;AAAA,IACF;AAEA,IAAA,MAAM,MAAA,GAAwB;AAAA,MAC5B,MAAA,EAAQ,SAAA;AAAA,MACR,MAAM,OAAA,CAAQ,IAAA;AAAA,MACd,WAAW,OAAA,CAAQ,SAAA;AAAA,MACnB,eAAe,OAAA,CAAQ,aAAA;AAAA,MACvB,gBAAA,EAAkB,CAAC,OAAA,CAAQ,eAAA;AAAA,MAC3B,eAAe,OAAA,CAAQ,UAAA;AAAA,MACvB,SAAS,OAAA,CAAQ,OAAA;AAAA,MACjB,YAAY,OAAA,CAAQ;AAAA,KACtB;AAEA,IAAA,MAAM,WAAW,MAAM,CAAA;AAAA,EACzB,SAAS,KAAA,EAAO;AACd,IAAA,GAAA,CAAI,KAAK,EAAE,CAAA;AACX,IAAA,GAAA,CAAI,KAAA,CAAM,CAAA,aAAA,EAAgB,KAAK,CAAA,CAAE,CAAA;AACjC,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF;AAEA,IAAI,SAAA,CAAQ,SAAS,MAAA,EAAQ;AAC3B,EAAA,IAAA,EAAK;AACP","file":"cli.js","sourcesContent":["/**\n * Peam Static Site Indexer\n *\n * Scans a static site output directory, discovers HTML files,\n * parses them into structured pages, and creates a searchable index.\n */\n\nimport { filePathToPathname, loadRobotsTxt, parseHTML, shouldIncludePath, type StructuredPage } from '@peam-ai/parser';\nimport { buildSearchIndex } from '@peam-ai/search';\nimport chalk from 'chalk';\nimport { Command } from 'commander';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\n\nconst packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));\n\ninterface IndexerConfig {\n source: string;\n outputDir: string;\n indexFilename: string;\n respectRobotsTxt: boolean;\n robotsTxtPath?: string;\n exclude: string[];\n glob: string;\n projectDir: string;\n}\n\ninterface DiscoveredPage {\n pathname: string;\n htmlFilePath: string;\n relativeHtmlPath: string;\n}\n\nfunction parseExcludePatterns(value: string): string[] {\n return value\n .split(',')\n .map((p) => p.trim())\n .filter(Boolean);\n}\n\nconst log = {\n success: (message: string) => console.log(chalk.green('✓ ') + message),\n error: (message: string) => console.error(chalk.red('✗ ') + message),\n warn: (message: string) => console.warn(chalk.yellow('⚠ ') + message),\n info: (message: string) => console.log(chalk.blue('ℹ ') + message),\n text: (message: string) => console.log(message),\n\n cyan: (text: string) => chalk.cyan(text),\n gray: (text: string) => chalk.gray(text),\n bold: (text: string) => chalk.bold(text),\n yellow: (text: string) => chalk.yellow(text),\n red: (text: string) => chalk.red(text),\n green: (text: string) => chalk.green(text),\n};\n\nasync function discoverHtmlFiles(\n sourceDir: string,\n globPattern: string,\n projectDir: string\n): Promise<DiscoveredPage[]> {\n const pages: DiscoveredPage[] = [];\n\n try {\n const sourceFullPath = join(projectDir, sourceDir);\n\n const htmlFiles = await fg(globPattern, {\n cwd: sourceFullPath,\n absolute: true,\n onlyFiles: true,\n dot: false,\n ignore: ['**/_next/**', '**/_astro/**', '**/404.{html,htm}', '**/500.{html,htm}'],\n });\n\n for (const htmlFilePath of htmlFiles) {\n const relativePath = relative(sourceFullPath, htmlFilePath);\n const pathname = filePathToPathname(relativePath);\n\n pages.push({\n pathname,\n htmlFilePath,\n relativeHtmlPath: relativePath,\n });\n }\n } catch (error) {\n log.warn(`Error discovering HTML files: ${error}`);\n }\n\n return pages;\n}\n\nasync function indexPages(config: IndexerConfig): Promise<void> {\n log.text('\\n' + log.bold(log.cyan('Peam Static Site Indexer')) + '\\n');\n log.text(log.bold('Configuration:'));\n log.text(` Project Directory: ${log.gray(config.projectDir)}`);\n log.text(` Source Directory: ${log.gray(config.source)}`);\n log.text(` Glob Pattern: ${log.gray(config.glob)}`);\n log.text(` Output Directory: ${log.gray(config.outputDir)}`);\n log.text(` Index Filename: ${log.gray(config.indexFilename)}`);\n log.text(` Respect robots.txt: ${log.gray(config.respectRobotsTxt.toString())}`);\n if (config.exclude.length > 0) {\n log.text(` Exclude Patterns: ${log.gray(config.exclude.join(', '))}`);\n }\n log.text('');\n\n const sourcePath = join(config.projectDir, config.source);\n if (!existsSync(sourcePath)) {\n log.error(`Source directory not found: ${sourcePath}`);\n log.text(log.yellow(' Please build your site first or specify the correct --source directory'));\n process.exit(1);\n }\n\n const searchPaths = [join(config.source, 'robots.txt'), 'public/robots.txt', 'robots.txt'];\n\n const robotsResult = config.respectRobotsTxt\n ? loadRobotsTxt(config.projectDir, searchPaths, config.robotsTxtPath)\n : null;\n\n if (robotsResult && config.respectRobotsTxt) {\n log.info(`robots.txt loaded from ${log.cyan(relative(config.projectDir, robotsResult.path))}`);\n } else if (config.respectRobotsTxt) {\n log.info('No robots.txt found, all paths will be indexed');\n }\n\n log.text(log.bold('Discovering HTML files...'));\n log.text('');\n log.text(` Scanning: ${log.gray(config.source)}`);\n log.text(` Pattern: ${log.gray(config.glob)}`);\n log.text('');\n\n const discoveredPages = await discoverHtmlFiles(config.source, config.glob, config.projectDir);\n\n if (discoveredPages.length === 0) {\n log.text('');\n log.warn('No HTML files found');\n log.text(log.yellow(' Check that your source directory contains HTML files'));\n log.text(log.yellow(` Source: ${sourcePath}`));\n log.text(log.yellow(` Pattern: ${config.glob}`));\n process.exit(1);\n }\n\n const uniquePages = new Map<string, DiscoveredPage>();\n for (const page of discoveredPages) {\n if (!uniquePages.has(page.pathname)) {\n uniquePages.set(page.pathname, page);\n }\n }\n\n log.text('');\n log.success(`Found ${log.bold(uniquePages.size.toString())} unique pages`);\n log.text('');\n log.text(log.bold('Processing pages...'));\n log.text('');\n\n const processedPages: Array<{\n path: string;\n htmlFile: string;\n structuredPage: StructuredPage;\n }> = [];\n\n for (const [pathname, page] of uniquePages) {\n const result = shouldIncludePath(pathname, robotsResult?.parser ?? null, config.exclude, config.respectRobotsTxt);\n\n if (!result.included) {\n // Log the specific reason for exclusion\n if (result.reason === 'robots-txt') {\n log.error(`Excluded by robots.txt: ${pathname}`);\n } else if (result.reason === 'exclude-pattern') {\n log.error(`Excluded by pattern: ${pathname}`);\n }\n continue;\n }\n\n try {\n const html = readFileSync(page.htmlFilePath, 'utf-8');\n\n const structuredPage = parseHTML(html);\n\n if (!structuredPage) {\n log.warn(`No content extracted from ${log.gray(pathname)}`);\n continue;\n }\n\n log.success(`${log.cyan(pathname)}`);\n\n processedPages.push({\n path: pathname,\n htmlFile: page.relativeHtmlPath,\n structuredPage,\n });\n } catch (error) {\n log.error(`Error processing ${log.gray(pathname)}: ${error}`);\n }\n }\n\n log.text('');\n log.success(`Successfully processed ${log.bold(processedPages.length.toString())} pages`);\n log.text('');\n log.text(log.bold('Creating search index...'));\n log.text('');\n\n const searchIndexData = await buildSearchIndex(processedPages);\n\n log.success(`Added ${log.bold(processedPages.length.toString())} pages to search index`);\n log.text('');\n log.text(log.bold('Saving index...'));\n log.text('');\n\n const outputPath = join(config.projectDir, config.outputDir);\n mkdirSync(outputPath, { recursive: true });\n\n const generatedPath = join(outputPath, 'generated');\n mkdirSync(generatedPath, { recursive: true });\n\n const searchIndexFile = join(generatedPath, config.indexFilename);\n writeFileSync(searchIndexFile, JSON.stringify(searchIndexData));\n\n const indexJsContent = `// Auto-generated by Peam - DO NOT EDIT THIS FILE\nimport index from \"./generated/${config.indexFilename}\";\nexport default index;\n`;\n const indexJsFile = join(outputPath, 'index.js');\n writeFileSync(indexJsFile, indexJsContent);\n\n log.success(`Index saved to: ${log.cyan(relative(config.projectDir, searchIndexFile))}`);\n log.text(` Total pages indexed: ${log.bold(processedPages.length.toString())}`);\n log.text(\n ` Index size: ${log.bold((Buffer.byteLength(JSON.stringify(searchIndexData), 'utf8') / 1024).toFixed(2))} KB`\n );\n log.text('');\n log.success(log.bold('Indexing complete!'));\n log.text('');\n}\n\nfunction probeSourceDirectory(projectDir: string): string | null {\n const commonDirs = ['.next', '.build', '.out'];\n\n for (const dir of commonDirs) {\n const fullPath = join(projectDir, dir);\n if (existsSync(fullPath)) {\n return dir;\n }\n }\n\n return null;\n}\n\nasync function main() {\n const program = new Command();\n\n program\n .name('peam')\n .description('Peam static site indexer (Next.js, Hugo, etc.)')\n .version(packageJson.version)\n .option('--source <path>', 'Source directory containing HTML files (auto-detected if not provided)')\n .option('--glob <pattern>', 'Glob pattern for HTML files', '**/*.{html,htm}')\n .option('--output-dir <path>', 'Output directory for index', '.peam')\n .option('--index-filename <name>', 'Name of index file', 'index.json')\n .option('--ignore-robots-txt', 'Disable robots.txt checking')\n .option('--robots-path <path>', 'Custom path to robots.txt file')\n .option('--exclude <patterns>', 'Comma-separated exclude patterns', parseExcludePatterns, [])\n .option('--project-dir <path>', 'Project root directory', process.cwd())\n .addHelpText(\n 'after',\n `\nExamples:\n # Auto-detect build directory\n $ peam\n\n # Hugo\n $ peam --source public\n\n # Next.js\n $ peam --source .next\n\n # Custom output directory\n $ peam --source dist --glob \"**/*.html\"\n\n # Exclude patterns\n $ peam --exclude \"/admin/**,/api/*,/private-*\"\n\nFor Next.js 15+, the @peam-ai/next integration is recommended for production use.\n\nMore information: https://peam.ai\n `\n )\n .parse();\n\n const options = program.opts();\n\n try {\n let sourceDir = options.source;\n if (!sourceDir) {\n const probedDir = probeSourceDirectory(options.projectDir);\n if (probedDir) {\n sourceDir = probedDir;\n log.info(`Auto-detected source directory: ${log.cyan(probedDir)}`);\n log.text('');\n } else {\n log.error('No build output directory found');\n log.text(log.yellow(' Searched for: .next, .build, .out'));\n log.text(log.yellow(' Please build your site first or specify --source <directory>'));\n process.exit(1);\n }\n }\n\n const config: IndexerConfig = {\n source: sourceDir,\n glob: options.glob,\n outputDir: options.outputDir,\n indexFilename: options.indexFilename,\n respectRobotsTxt: !options.ignoreRobotsTxt,\n robotsTxtPath: options.robotsPath,\n exclude: options.exclude,\n projectDir: options.projectDir,\n };\n\n await indexPages(config);\n } catch (error) {\n log.text('');\n log.error(`Fatal error: ${error}`);\n process.exit(1);\n }\n}\n\nif (require.main === module) {\n main();\n}\n\nexport { indexPages, type IndexerConfig };\n"]}
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@peam-ai/client');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.keys(client).forEach(function (k) {
|
|
8
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return client[k]; }
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=client.js.map
|
|
14
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"client.js","sourcesContent":[]}
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"client.mjs","sourcesContent":[]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Peam Static Site Indexer
|
|
3
|
+
*
|
|
4
|
+
* Scans a static site output directory, discovers HTML files,
|
|
5
|
+
* parses them into structured pages, and creates a searchable index.
|
|
6
|
+
*/
|
|
7
|
+
interface IndexerConfig {
|
|
8
|
+
source: string;
|
|
9
|
+
outputDir: string;
|
|
10
|
+
indexFilename: string;
|
|
11
|
+
respectRobotsTxt: boolean;
|
|
12
|
+
robotsTxtPath?: string;
|
|
13
|
+
exclude: string[];
|
|
14
|
+
glob: string;
|
|
15
|
+
projectDir: string;
|
|
16
|
+
}
|
|
17
|
+
declare function indexPages(config: IndexerConfig): Promise<void>;
|
|
18
|
+
|
|
19
|
+
export { type IndexerConfig, indexPages };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Peam Static Site Indexer
|
|
3
|
+
*
|
|
4
|
+
* Scans a static site output directory, discovers HTML files,
|
|
5
|
+
* parses them into structured pages, and creates a searchable index.
|
|
6
|
+
*/
|
|
7
|
+
interface IndexerConfig {
|
|
8
|
+
source: string;
|
|
9
|
+
outputDir: string;
|
|
10
|
+
indexFilename: string;
|
|
11
|
+
respectRobotsTxt: boolean;
|
|
12
|
+
robotsTxtPath?: string;
|
|
13
|
+
exclude: string[];
|
|
14
|
+
glob: string;
|
|
15
|
+
projectDir: string;
|
|
16
|
+
}
|
|
17
|
+
declare function indexPages(config: IndexerConfig): Promise<void>;
|
|
18
|
+
|
|
19
|
+
export { type IndexerConfig, indexPages };
|