mdorigin 0.1.3 → 0.1.5
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/README.md +2 -0
- package/dist/cli/build-cloudflare.js +10 -0
- package/dist/cli/build-index.js +10 -0
- package/dist/cli/build-search.js +18 -1
- package/dist/cli/dev.js +10 -0
- package/dist/cli/help.d.ts +4 -0
- package/dist/cli/help.js +32 -0
- package/dist/cli/init-cloudflare.js +10 -0
- package/dist/cli/main.js +39 -10
- package/dist/cli/search.js +17 -2
- package/dist/core/extensions.d.ts +2 -1
- package/dist/core/request-handler.js +1 -0
- package/dist/index-builder.js +42 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,6 +77,8 @@ Current stable hooks are:
|
|
|
77
77
|
- `renderPage(page, context, next)`
|
|
78
78
|
- `transformHtml(html, context)`
|
|
79
79
|
|
|
80
|
+
All render hooks that receive a `RenderHookContext` (`renderHeader`, `renderFooter`, `renderPage`, and `transformHtml`) can read the normalized markdown frontmatter for the current document via `context.page.meta`, including custom fields such as `syndication`.
|
|
81
|
+
|
|
80
82
|
The intended boundary is:
|
|
81
83
|
|
|
82
84
|
- `mdorigin` owns routing and normalized content semantics
|
|
@@ -4,6 +4,10 @@ import { writeCloudflareBundle } from '../cloudflare.js';
|
|
|
4
4
|
import { applySiteConfigFrontmatterDefaults, loadUserSiteConfig, } from '../core/site-config.js';
|
|
5
5
|
export async function runBuildCloudflareCommand(argv) {
|
|
6
6
|
const args = parseArgs(argv);
|
|
7
|
+
if (args.help) {
|
|
8
|
+
console.log('Usage: mdorigin build cloudflare --root <content-dir> [--out ./dist/cloudflare] [--config <config-file>] [--search ./dist/search]');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
7
11
|
if (!args.root) {
|
|
8
12
|
console.error('Usage: mdorigin build cloudflare --root <content-dir> [--out ./dist/cloudflare] [--config <config-file>] [--search ./dist/search]');
|
|
9
13
|
process.exitCode = 1;
|
|
@@ -31,6 +35,10 @@ function parseArgs(argv) {
|
|
|
31
35
|
for (let index = 0; index < argv.length; index += 1) {
|
|
32
36
|
const argument = argv[index];
|
|
33
37
|
const nextValue = argv[index + 1];
|
|
38
|
+
if (argument === '--help' || argument === '-h') {
|
|
39
|
+
result.help = true;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
34
42
|
if (argument === '--root' && nextValue) {
|
|
35
43
|
result.root = nextValue;
|
|
36
44
|
index += 1;
|
|
@@ -49,7 +57,9 @@ function parseArgs(argv) {
|
|
|
49
57
|
if (argument === '--search' && nextValue) {
|
|
50
58
|
result.search = nextValue;
|
|
51
59
|
index += 1;
|
|
60
|
+
continue;
|
|
52
61
|
}
|
|
62
|
+
throw new Error(`Unknown argument for mdorigin build cloudflare: ${argument}`);
|
|
53
63
|
}
|
|
54
64
|
return result;
|
|
55
65
|
}
|
package/dist/cli/build-index.js
CHANGED
|
@@ -3,6 +3,10 @@ import { buildDirectoryIndexes } from '../index-builder.js';
|
|
|
3
3
|
import { loadUserSiteConfig } from '../core/site-config.js';
|
|
4
4
|
export async function runBuildIndexCommand(argv) {
|
|
5
5
|
const args = parseArgs(argv);
|
|
6
|
+
if (args.help) {
|
|
7
|
+
console.log('Usage: mdorigin build index (--root <content-dir> | --dir <content-dir>) [--config <config-file>]');
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
6
10
|
if (!args.root && !args.dir) {
|
|
7
11
|
console.error('Usage: mdorigin build index (--root <content-dir> | --dir <content-dir>) [--config <config-file>]');
|
|
8
12
|
process.exitCode = 1;
|
|
@@ -30,6 +34,10 @@ function parseArgs(argv) {
|
|
|
30
34
|
for (let index = 0; index < argv.length; index += 1) {
|
|
31
35
|
const argument = argv[index];
|
|
32
36
|
const nextValue = argv[index + 1];
|
|
37
|
+
if (argument === '--help' || argument === '-h') {
|
|
38
|
+
result.help = true;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
33
41
|
if (argument === '--root' && nextValue) {
|
|
34
42
|
result.root = nextValue;
|
|
35
43
|
index += 1;
|
|
@@ -43,7 +51,9 @@ function parseArgs(argv) {
|
|
|
43
51
|
if (argument === '--config' && nextValue) {
|
|
44
52
|
result.config = nextValue;
|
|
45
53
|
index += 1;
|
|
54
|
+
continue;
|
|
46
55
|
}
|
|
56
|
+
throw new Error(`Unknown argument for mdorigin build index: ${argument}`);
|
|
47
57
|
}
|
|
48
58
|
return result;
|
|
49
59
|
}
|
package/dist/cli/build-search.js
CHANGED
|
@@ -4,6 +4,10 @@ import { applySiteConfigFrontmatterDefaults, loadUserSiteConfig, } from '../core
|
|
|
4
4
|
import { createFileSystemContentStore } from '../adapters/node.js';
|
|
5
5
|
export async function runBuildSearchCommand(rawArgs) {
|
|
6
6
|
const args = parseArgs(rawArgs);
|
|
7
|
+
if (args.help) {
|
|
8
|
+
console.log('Usage: mdorigin build search --root <content-dir> [--out ./dist/search] [--embedding-backend model2vec|hashing] [--model sentence-transformers/all-MiniLM-L6-v2] [--config <config-file>]');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
7
11
|
if (!args.root) {
|
|
8
12
|
throw new Error('Usage: mdorigin build search --root <content-dir> [--out ./dist/search] [--embedding-backend model2vec|hashing] [--model sentence-transformers/all-MiniLM-L6-v2] [--config <config-file>]');
|
|
9
13
|
}
|
|
@@ -25,15 +29,27 @@ export async function runBuildSearchCommand(rawArgs) {
|
|
|
25
29
|
}
|
|
26
30
|
function parseArgs(rawArgs) {
|
|
27
31
|
const parsed = {};
|
|
32
|
+
const supportedFlags = new Set(['root', 'out', 'embedding-backend', 'model', 'config']);
|
|
28
33
|
for (let index = 0; index < rawArgs.length; index += 1) {
|
|
29
34
|
const arg = rawArgs[index];
|
|
35
|
+
if (arg === '--help' || arg === '-h') {
|
|
36
|
+
parsed.help = 'true';
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
30
39
|
if (arg.startsWith('--')) {
|
|
40
|
+
const flag = arg.slice(2);
|
|
41
|
+
if (!supportedFlags.has(flag)) {
|
|
42
|
+
throw new Error(`Unknown argument for mdorigin build search: ${arg}`);
|
|
43
|
+
}
|
|
31
44
|
const value = rawArgs[index + 1];
|
|
32
45
|
if (value && !value.startsWith('--')) {
|
|
33
|
-
parsed[
|
|
46
|
+
parsed[flag] = value;
|
|
34
47
|
index += 1;
|
|
48
|
+
continue;
|
|
35
49
|
}
|
|
50
|
+
throw new Error(`Incomplete argument for mdorigin build search: ${arg}`);
|
|
36
51
|
}
|
|
52
|
+
throw new Error(`Unknown positional argument for mdorigin build search: ${arg}`);
|
|
37
53
|
}
|
|
38
54
|
return {
|
|
39
55
|
root: parsed.root,
|
|
@@ -41,5 +57,6 @@ function parseArgs(rawArgs) {
|
|
|
41
57
|
embeddingBackend: parsed['embedding-backend'],
|
|
42
58
|
model: parsed.model,
|
|
43
59
|
config: parsed.config,
|
|
60
|
+
help: parsed.help === 'true',
|
|
44
61
|
};
|
|
45
62
|
}
|
package/dist/cli/dev.js
CHANGED
|
@@ -4,6 +4,10 @@ import { applySiteConfigFrontmatterDefaults, loadUserSiteConfig, } from '../core
|
|
|
4
4
|
import { createSearchApiFromDirectory } from '../search.js';
|
|
5
5
|
export async function runDevCommand(argv) {
|
|
6
6
|
const args = parseArgs(argv);
|
|
7
|
+
if (args.help) {
|
|
8
|
+
console.log('Usage: mdorigin dev --root <content-dir> [--port 3000] [--config <config-file>] [--search ./dist/search]');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
7
11
|
if (!args.root) {
|
|
8
12
|
console.error('Usage: mdorigin dev --root <content-dir> [--port 3000] [--config <config-file>] [--search ./dist/search]');
|
|
9
13
|
process.exitCode = 1;
|
|
@@ -39,6 +43,10 @@ function parseArgs(argv) {
|
|
|
39
43
|
for (let index = 0; index < argv.length; index += 1) {
|
|
40
44
|
const argument = argv[index];
|
|
41
45
|
const nextValue = argv[index + 1];
|
|
46
|
+
if (argument === '--help' || argument === '-h') {
|
|
47
|
+
result.help = true;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
42
50
|
if (argument === '--root' && nextValue) {
|
|
43
51
|
result.root = nextValue;
|
|
44
52
|
index += 1;
|
|
@@ -57,7 +65,9 @@ function parseArgs(argv) {
|
|
|
57
65
|
if (argument === '--search' && nextValue) {
|
|
58
66
|
result.search = nextValue;
|
|
59
67
|
index += 1;
|
|
68
|
+
continue;
|
|
60
69
|
}
|
|
70
|
+
throw new Error(`Unknown argument for mdorigin dev: ${argument}`);
|
|
61
71
|
}
|
|
62
72
|
return result;
|
|
63
73
|
}
|
package/dist/cli/help.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const ROOT_USAGE_LINES = [
|
|
2
|
+
'Usage:',
|
|
3
|
+
' mdorigin dev --root <content-dir> [--port 3000] [--config <config-file>] [--search ./dist/search]',
|
|
4
|
+
' mdorigin build index (--root <content-dir> | --dir <content-dir>) [--config <config-file>]',
|
|
5
|
+
' mdorigin build search --root <content-dir> [--out ./dist/search] [--embedding-backend model2vec|hashing] [--model sentence-transformers/all-MiniLM-L6-v2] [--config <config-file>]',
|
|
6
|
+
' mdorigin build cloudflare --root <content-dir> [--out ./dist/cloudflare] [--config <config-file>] [--search ./dist/search]',
|
|
7
|
+
' mdorigin init cloudflare [--dir .] [--entry ./dist/cloudflare/worker.mjs] [--name <worker-name>] [--compatibility-date 2026-03-20] [--force]',
|
|
8
|
+
' mdorigin search --index <search-dir> [--top-k 10] <query>',
|
|
9
|
+
' mdorigin version',
|
|
10
|
+
'',
|
|
11
|
+
'Global options:',
|
|
12
|
+
' -h, --help Show help',
|
|
13
|
+
' -V, --version Show version',
|
|
14
|
+
];
|
|
15
|
+
export const BUILD_USAGE_LINES = [
|
|
16
|
+
'Usage:',
|
|
17
|
+
' mdorigin build index (--root <content-dir> | --dir <content-dir>) [--config <config-file>]',
|
|
18
|
+
' mdorigin build search --root <content-dir> [--out ./dist/search] [--embedding-backend model2vec|hashing] [--model sentence-transformers/all-MiniLM-L6-v2] [--config <config-file>]',
|
|
19
|
+
' mdorigin build cloudflare --root <content-dir> [--out ./dist/cloudflare] [--config <config-file>] [--search ./dist/search]',
|
|
20
|
+
];
|
|
21
|
+
export const INIT_USAGE_LINES = [
|
|
22
|
+
'Usage:',
|
|
23
|
+
' mdorigin init cloudflare [--dir .] [--entry ./dist/cloudflare/worker.mjs] [--name <worker-name>] [--compatibility-date 2026-03-20] [--force]',
|
|
24
|
+
];
|
|
25
|
+
export function printUsage(lines, error = false) {
|
|
26
|
+
const output = lines.join('\n');
|
|
27
|
+
if (error) {
|
|
28
|
+
console.error(output);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
console.log(output);
|
|
32
|
+
}
|
|
@@ -3,6 +3,10 @@ import { readFile } from 'node:fs/promises';
|
|
|
3
3
|
import { initCloudflareProject } from '../cloudflare.js';
|
|
4
4
|
export async function runInitCloudflareCommand(argv) {
|
|
5
5
|
const args = parseArgs(argv);
|
|
6
|
+
if (args.help) {
|
|
7
|
+
console.log('Usage: mdorigin init cloudflare [--dir .] [--entry ./dist/cloudflare/worker.mjs] [--name <worker-name>] [--compatibility-date 2026-03-20] [--force]');
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
6
10
|
const projectDir = path.resolve(args.dir ?? '.');
|
|
7
11
|
const workerEntry = path.resolve(projectDir, args.entry ?? 'dist/cloudflare/worker.mjs');
|
|
8
12
|
const siteTitle = args.name ? undefined : await inferSiteTitleFromWorkerEntry(workerEntry);
|
|
@@ -21,6 +25,10 @@ function parseArgs(argv) {
|
|
|
21
25
|
for (let index = 0; index < argv.length; index += 1) {
|
|
22
26
|
const argument = argv[index];
|
|
23
27
|
const nextValue = argv[index + 1];
|
|
28
|
+
if (argument === '--help' || argument === '-h') {
|
|
29
|
+
result.help = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
24
32
|
if (argument === '--dir' && nextValue) {
|
|
25
33
|
result.dir = nextValue;
|
|
26
34
|
index += 1;
|
|
@@ -43,7 +51,9 @@ function parseArgs(argv) {
|
|
|
43
51
|
}
|
|
44
52
|
if (argument === '--force') {
|
|
45
53
|
result.force = true;
|
|
54
|
+
continue;
|
|
46
55
|
}
|
|
56
|
+
throw new Error(`Unknown argument for mdorigin init cloudflare: ${argument}`);
|
|
47
57
|
}
|
|
48
58
|
return result;
|
|
49
59
|
}
|
package/dist/cli/main.js
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
2
5
|
import { runBuildIndexCommand } from './build-index.js';
|
|
3
6
|
import { runBuildCloudflareCommand } from './build-cloudflare.js';
|
|
4
7
|
import { runBuildSearchCommand } from './build-search.js';
|
|
5
8
|
import { runDevCommand } from './dev.js';
|
|
9
|
+
import { BUILD_USAGE_LINES, INIT_USAGE_LINES, ROOT_USAGE_LINES, printUsage } from './help.js';
|
|
6
10
|
import { runInitCloudflareCommand } from './init-cloudflare.js';
|
|
7
11
|
import { runSearchCommand } from './search.js';
|
|
8
12
|
async function main() {
|
|
9
|
-
const
|
|
13
|
+
const argv = process.argv.slice(2);
|
|
14
|
+
const [command, subcommand, ...rest] = argv;
|
|
15
|
+
if (argv.length === 0 || command === 'help' || command === '--help' || command === '-h') {
|
|
16
|
+
if (command === 'help' && subcommand === 'build') {
|
|
17
|
+
printUsage(BUILD_USAGE_LINES);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (command === 'help' && subcommand === 'init') {
|
|
21
|
+
printUsage(INIT_USAGE_LINES);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
printUsage(ROOT_USAGE_LINES);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (command === '--version' || command === '-V' || command === 'version') {
|
|
28
|
+
console.log(getCliVersion());
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
10
31
|
if (command === 'dev') {
|
|
11
32
|
await runDevCommand([subcommand, ...rest].filter(isDefined));
|
|
12
33
|
return;
|
|
13
34
|
}
|
|
35
|
+
if (command === 'build' && (subcommand === '--help' || subcommand === '-h' || !subcommand)) {
|
|
36
|
+
printUsage(BUILD_USAGE_LINES, subcommand === undefined);
|
|
37
|
+
process.exitCode = subcommand === undefined ? 1 : 0;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
14
40
|
if (command === 'build' && subcommand === 'cloudflare') {
|
|
15
41
|
await runBuildCloudflareCommand(rest);
|
|
16
42
|
return;
|
|
@@ -27,19 +53,17 @@ async function main() {
|
|
|
27
53
|
await runInitCloudflareCommand(rest);
|
|
28
54
|
return;
|
|
29
55
|
}
|
|
56
|
+
if (command === 'init' && (subcommand === '--help' || subcommand === '-h' || !subcommand)) {
|
|
57
|
+
printUsage(INIT_USAGE_LINES, subcommand === undefined);
|
|
58
|
+
process.exitCode = subcommand === undefined ? 1 : 0;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
30
61
|
if (command === 'search') {
|
|
31
62
|
await runSearchCommand([subcommand, ...rest].filter(isDefined));
|
|
32
63
|
return;
|
|
33
64
|
}
|
|
34
|
-
console.error(
|
|
35
|
-
|
|
36
|
-
' mdorigin dev --root <content-dir> [--port 3000] [--config <config-file>] [--search ./dist/search]',
|
|
37
|
-
' mdorigin build index (--root <content-dir> | --dir <content-dir>) [--config <config-file>]',
|
|
38
|
-
' mdorigin build search --root <content-dir> [--out ./dist/search] [--embedding-backend model2vec|hashing] [--model sentence-transformers/all-MiniLM-L6-v2] [--config <config-file>]',
|
|
39
|
-
' mdorigin build cloudflare --root <content-dir> [--out ./dist/cloudflare] [--config <config-file>] [--search ./dist/search]',
|
|
40
|
-
' mdorigin init cloudflare [--dir .] [--entry ./dist/cloudflare/worker.mjs] [--name <worker-name>] [--compatibility-date 2026-03-20] [--force]',
|
|
41
|
-
' mdorigin search --index <search-dir> [--top-k 10] <query>',
|
|
42
|
-
].join('\n'));
|
|
65
|
+
console.error(`Unknown command: ${argv.join(' ')}`);
|
|
66
|
+
printUsage(ROOT_USAGE_LINES, true);
|
|
43
67
|
process.exitCode = 1;
|
|
44
68
|
}
|
|
45
69
|
void main().catch((error) => {
|
|
@@ -49,3 +73,8 @@ void main().catch((error) => {
|
|
|
49
73
|
function isDefined(value) {
|
|
50
74
|
return value !== undefined;
|
|
51
75
|
}
|
|
76
|
+
function getCliVersion() {
|
|
77
|
+
const packageJsonPath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'package.json');
|
|
78
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
79
|
+
return packageJson.version ?? '0.0.0';
|
|
80
|
+
}
|
package/dist/cli/search.js
CHANGED
|
@@ -2,6 +2,10 @@ import path from 'node:path';
|
|
|
2
2
|
import { searchBundle } from '../search.js';
|
|
3
3
|
export async function runSearchCommand(rawArgs) {
|
|
4
4
|
const args = parseArgs(rawArgs);
|
|
5
|
+
if (args.help) {
|
|
6
|
+
console.log('Usage: mdorigin search --index <search-dir> [--top-k 10] <query>');
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
5
9
|
if (!args.indexDir || !args.query) {
|
|
6
10
|
throw new Error('Usage: mdorigin search --index <search-dir> [--top-k 10] <query>');
|
|
7
11
|
}
|
|
@@ -15,15 +19,25 @@ export async function runSearchCommand(rawArgs) {
|
|
|
15
19
|
function parseArgs(rawArgs) {
|
|
16
20
|
const flags = {};
|
|
17
21
|
const positionals = [];
|
|
22
|
+
const supportedFlags = new Set(['index', 'top-k']);
|
|
18
23
|
for (let index = 0; index < rawArgs.length; index += 1) {
|
|
19
24
|
const arg = rawArgs[index];
|
|
25
|
+
if (arg === '--help' || arg === '-h') {
|
|
26
|
+
flags.help = 'true';
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
20
29
|
if (arg.startsWith('--')) {
|
|
30
|
+
const flag = arg.slice(2);
|
|
31
|
+
if (!supportedFlags.has(flag)) {
|
|
32
|
+
throw new Error(`Unknown argument for mdorigin search: ${arg}`);
|
|
33
|
+
}
|
|
21
34
|
const value = rawArgs[index + 1];
|
|
22
35
|
if (value && !value.startsWith('--')) {
|
|
23
|
-
flags[
|
|
36
|
+
flags[flag] = value;
|
|
24
37
|
index += 1;
|
|
38
|
+
continue;
|
|
25
39
|
}
|
|
26
|
-
|
|
40
|
+
throw new Error(`Incomplete argument for mdorigin search: ${arg}`);
|
|
27
41
|
}
|
|
28
42
|
positionals.push(arg);
|
|
29
43
|
}
|
|
@@ -32,5 +46,6 @@ function parseArgs(rawArgs) {
|
|
|
32
46
|
indexDir: flags.index,
|
|
33
47
|
topK: Number.isInteger(topK) && topK > 0 ? topK : undefined,
|
|
34
48
|
query: positionals.join(' ').trim(),
|
|
49
|
+
help: flags.help === 'true',
|
|
35
50
|
};
|
|
36
51
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ManagedIndexEntry } from './markdown.js';
|
|
1
|
+
import type { ManagedIndexEntry, ParsedDocumentMeta } from './markdown.js';
|
|
2
2
|
import type { EditLinkConfig, ResolvedSiteConfig, SiteLogo, SiteNavItem, SiteSocialLink } from './site-config.js';
|
|
3
3
|
import type { TemplateName } from '../html/template-kind.js';
|
|
4
4
|
import type { BuiltInThemeName } from '../html/theme.js';
|
|
@@ -21,6 +21,7 @@ export interface PageRenderModel {
|
|
|
21
21
|
socialImage?: string;
|
|
22
22
|
logo?: SiteLogo;
|
|
23
23
|
title: string;
|
|
24
|
+
meta: ParsedDocumentMeta;
|
|
24
25
|
bodyHtml: string;
|
|
25
26
|
summary?: string;
|
|
26
27
|
date?: string;
|
|
@@ -150,6 +150,7 @@ function buildPageRenderModel(options) {
|
|
|
150
150
|
socialImage: options.siteConfig.socialImage,
|
|
151
151
|
logo: options.siteConfig.logo,
|
|
152
152
|
title: getDocumentTitle(options.parsed),
|
|
153
|
+
meta: options.parsed.meta,
|
|
153
154
|
bodyHtml: options.renderedBodyHtml,
|
|
154
155
|
summary: options.siteConfig.showSummary === false
|
|
155
156
|
? undefined
|
package/dist/index-builder.js
CHANGED
|
@@ -78,6 +78,9 @@ export async function buildManagedIndexBlock(directoryPath, plugins = []) {
|
|
|
78
78
|
const fullPath = path.join(directoryPath, entry.name);
|
|
79
79
|
const entryStats = await stat(fullPath);
|
|
80
80
|
if (entryStats.isDirectory()) {
|
|
81
|
+
if (!(await hasMeaningfulDirectoryContent(fullPath))) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
81
84
|
const resolvedEntry = await resolveDirectoryEntry(fullPath, entry.name);
|
|
82
85
|
if (resolvedEntry.draft) {
|
|
83
86
|
continue;
|
|
@@ -215,6 +218,9 @@ async function listDirectoriesRecursivelyInternal(rootDir, visitedRealDirectorie
|
|
|
215
218
|
if (!childStats.isDirectory()) {
|
|
216
219
|
continue;
|
|
217
220
|
}
|
|
221
|
+
if (!(await hasMeaningfulDirectoryContent(childPath))) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
218
224
|
directories.push(childPath);
|
|
219
225
|
const childIndexPath = await resolveDirectoryIndexFile(childPath);
|
|
220
226
|
if (childIndexPath !== null) {
|
|
@@ -229,6 +235,42 @@ async function listDirectoriesRecursivelyInternal(rootDir, visitedRealDirectorie
|
|
|
229
235
|
}
|
|
230
236
|
return directories;
|
|
231
237
|
}
|
|
238
|
+
async function hasMeaningfulDirectoryContent(directoryPath, visitedRealDirectories = new Set()) {
|
|
239
|
+
const realDirectoryPath = await realpath(directoryPath);
|
|
240
|
+
if (visitedRealDirectories.has(realDirectoryPath)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
visitedRealDirectories.add(realDirectoryPath);
|
|
244
|
+
const shape = await inspectDirectoryShape(directoryPath);
|
|
245
|
+
const indexPath = await resolveDirectoryIndexFile(directoryPath);
|
|
246
|
+
if (indexPath !== null ||
|
|
247
|
+
shape.hasExtraMarkdownFiles ||
|
|
248
|
+
shape.hasAssetFiles ||
|
|
249
|
+
shape.hasSkillIndex) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
if (!shape.hasChildDirectories) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
const entries = await readdir(directoryPath, { withFileTypes: true });
|
|
256
|
+
for (const entry of entries) {
|
|
257
|
+
if (entry.name.startsWith('.')) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (shape.hasSkillIndex && isIgnoredSkillSupportDirectory(entry.name)) {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const childPath = path.join(directoryPath, entry.name);
|
|
264
|
+
const childStats = await stat(childPath);
|
|
265
|
+
if (!childStats.isDirectory()) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (await hasMeaningfulDirectoryContent(childPath, visitedRealDirectories)) {
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
232
274
|
async function inspectDirectoryShape(directoryPath) {
|
|
233
275
|
const entries = await readdir(directoryPath, { withFileTypes: true });
|
|
234
276
|
let hasSkillIndex = false;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { defineConfig, type SiteConfig, type UserSiteConfig, type SiteNavItem, type SiteLogo, type SiteSocialLink, type EditLinkConfig, } from './core/site-config.js';
|
|
2
2
|
export type { MdoPlugin, PageRenderModel, RenderHookContext, IndexTransformContext, } from './core/extensions.js';
|
|
3
|
+
export type { ParsedDocumentMeta } from './core/markdown.js';
|