minista 2.6.2 → 2.7.2
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 +19 -1
- package/dist/build.d.ts +32 -4
- package/dist/build.js +209 -12
- package/dist/cli.js +13 -5
- package/dist/config.js +22 -1
- package/dist/esbuild.js +2 -2
- package/dist/generate.d.ts +2 -1
- package/dist/generate.js +37 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +1 -0
- package/dist/path.d.ts +9 -3
- package/dist/path.js +24 -8
- package/dist/search.d.ts +50 -0
- package/dist/search.js +288 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +55 -1
- package/dist/system.js +6 -0
- package/dist/types.d.ts +45 -0
- package/dist/vite.js +7 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ https://minista.qranoko.jp
|
|
|
18
18
|
|
|
19
19
|
## About
|
|
20
20
|
|
|
21
|
-
minista(ミニスタ)は、React の JSX で書けるスタティックサイトジェネレーターです。Next.js 風の快適な環境で開発しながら 100%
|
|
21
|
+
minista(ミニスタ)は、React の JSX で書けるスタティックサイトジェネレーターです。Next.js 風の快適な環境で開発しながら 100% 静的に出力できます。SaaS の web テンプレートコーディング業務を想定しているため、ビルド後のデータが綺麗(ヒューマンリーダブル)です。
|
|
22
22
|
|
|
23
23
|
## How To Use
|
|
24
24
|
|
|
@@ -165,6 +165,24 @@ export default defineConfig({
|
|
|
165
165
|
rehypePlugins: [], // https://mdxjs.com/packages/mdx/#optionsrehypeplugins
|
|
166
166
|
},
|
|
167
167
|
},
|
|
168
|
+
search: {
|
|
169
|
+
useJson: false, // boolean
|
|
170
|
+
cache: false, // boolean
|
|
171
|
+
outDir: "assets", // string
|
|
172
|
+
outName: "search", // string
|
|
173
|
+
include: ["**/*"], // string[]
|
|
174
|
+
exclude: ["404"], // string[]
|
|
175
|
+
trimTitle: "", // string
|
|
176
|
+
targetSelector: "[data-search]", // string
|
|
177
|
+
hit: {
|
|
178
|
+
minLength: 3, // number
|
|
179
|
+
number: false, // boolean
|
|
180
|
+
english: true, // boolean
|
|
181
|
+
hiragana: false, // boolean
|
|
182
|
+
katakana: true, // boolean
|
|
183
|
+
kanji: true, // boolean
|
|
184
|
+
},
|
|
185
|
+
},
|
|
168
186
|
beautify: {
|
|
169
187
|
useHtml: true, // boolean
|
|
170
188
|
useAssets: false, // boolean
|
package/dist/build.d.ts
CHANGED
|
@@ -10,18 +10,38 @@ export declare function buildTempPages(entryPoints: string[], buildOptions: {
|
|
|
10
10
|
svgrOptions: SvgrOptions;
|
|
11
11
|
cssOptions: CssOptions;
|
|
12
12
|
}): Promise<void>;
|
|
13
|
-
export declare function buildStaticPages(entryPoints
|
|
13
|
+
export declare function buildStaticPages({ entryPoints, tempRootFilePath, outBase, outDir, assetsTagStr, showLog, }: {
|
|
14
|
+
entryPoints: string[];
|
|
15
|
+
tempRootFilePath: string;
|
|
14
16
|
outBase: string;
|
|
15
17
|
outDir: string;
|
|
16
|
-
|
|
18
|
+
assetsTagStr: string;
|
|
19
|
+
showLog: boolean;
|
|
20
|
+
}): Promise<void>;
|
|
17
21
|
export declare function buildRootEsmContent(tempRootFilePath: string): Promise<{
|
|
18
22
|
component: RootJsxContent;
|
|
19
23
|
staticData: GlobalStaticData;
|
|
20
24
|
}>;
|
|
21
25
|
export declare function buildGlobalStaticData(getGlobalStaticData: GetGlobalStaticData): Promise<GlobalStaticData>;
|
|
22
|
-
export declare function buildStaticPage(entryPoint
|
|
26
|
+
export declare function buildStaticPage({ entryPoint, outFile, rootStaticContent, assetsTagStr, outDir, showLog, }: {
|
|
27
|
+
entryPoint: string;
|
|
28
|
+
outFile: string;
|
|
29
|
+
rootStaticContent: RootStaticContent;
|
|
30
|
+
assetsTagStr: string;
|
|
31
|
+
outDir: string;
|
|
32
|
+
showLog: boolean;
|
|
33
|
+
}): Promise<void>;
|
|
23
34
|
export declare function buildStaticData(getStaticData: GetStaticData): Promise<StaticData>;
|
|
24
|
-
export declare function buildHtmlPage(pageJsxContent
|
|
35
|
+
export declare function buildHtmlPage({ pageJsxContent, staticDataItem, routePath, rootStaticContent, assetsTagStr, frontmatter, outDir, showLog, }: {
|
|
36
|
+
pageJsxContent: PageJsxContent;
|
|
37
|
+
staticDataItem: StaticDataItem;
|
|
38
|
+
routePath: string;
|
|
39
|
+
rootStaticContent: RootStaticContent;
|
|
40
|
+
assetsTagStr: string;
|
|
41
|
+
frontmatter: any;
|
|
42
|
+
outDir: string;
|
|
43
|
+
showLog: boolean;
|
|
44
|
+
}): Promise<void>;
|
|
25
45
|
export declare function buildTempAssets(viteConfig: InlineConfig, buildOptions: {
|
|
26
46
|
input: string;
|
|
27
47
|
bundleOutName: string;
|
|
@@ -62,4 +82,12 @@ export declare function buildPartialHydrateAssets(viteConfig: InlineConfig, buil
|
|
|
62
82
|
assetDir: string;
|
|
63
83
|
usePreact: boolean;
|
|
64
84
|
}): Promise<void>;
|
|
85
|
+
export declare function buildSearchJson({ config, useCacheExists, entryPoints, entryBase, outFile, showLog, }: {
|
|
86
|
+
config: MinistaResolveConfig;
|
|
87
|
+
useCacheExists: boolean;
|
|
88
|
+
entryPoints: string[];
|
|
89
|
+
entryBase: string;
|
|
90
|
+
outFile: string;
|
|
91
|
+
showLog: boolean;
|
|
92
|
+
}): Promise<void>;
|
|
65
93
|
export declare function buildCopyDir(targetDir: string, outDir: string, log?: "public" | "assets"): Promise<void>;
|
package/dist/build.js
CHANGED
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
defineConfig as defineViteConfig,
|
|
31
31
|
mergeConfig as mergeViteConfig
|
|
32
32
|
} from "vite";
|
|
33
|
+
import { parse } from "node-html-parser";
|
|
34
|
+
import mojigiri from "mojigiri";
|
|
33
35
|
import { systemConfig } from "./system.js";
|
|
34
36
|
import { getFilePath } from "./path.js";
|
|
35
37
|
import {
|
|
@@ -100,15 +102,29 @@ async function buildTempPages(entryPoints, buildOptions) {
|
|
|
100
102
|
]
|
|
101
103
|
}).catch(() => process.exit(1));
|
|
102
104
|
}
|
|
103
|
-
async function buildStaticPages(
|
|
105
|
+
async function buildStaticPages({
|
|
106
|
+
entryPoints,
|
|
107
|
+
tempRootFilePath,
|
|
108
|
+
outBase,
|
|
109
|
+
outDir,
|
|
110
|
+
assetsTagStr,
|
|
111
|
+
showLog
|
|
112
|
+
}) {
|
|
104
113
|
const rootStaticContent = await buildRootEsmContent(tempRootFilePath);
|
|
105
|
-
const winOutBase =
|
|
114
|
+
const winOutBase = outBase.replaceAll("/", "\\");
|
|
106
115
|
await Promise.all(entryPoints.map(async (entryPoint) => {
|
|
107
116
|
const extname = path.extname(entryPoint);
|
|
108
117
|
const basename = path.basename(entryPoint, extname);
|
|
109
|
-
const dirname = path.dirname(entryPoint).replace(
|
|
118
|
+
const dirname = path.dirname(entryPoint).replace(outBase, outDir).replace(winOutBase, outDir);
|
|
110
119
|
const filename = path.join(dirname, basename + ".html");
|
|
111
|
-
await buildStaticPage(
|
|
120
|
+
await buildStaticPage({
|
|
121
|
+
entryPoint,
|
|
122
|
+
outFile: filename,
|
|
123
|
+
rootStaticContent,
|
|
124
|
+
assetsTagStr,
|
|
125
|
+
outDir,
|
|
126
|
+
showLog
|
|
127
|
+
});
|
|
112
128
|
}));
|
|
113
129
|
}
|
|
114
130
|
async function buildRootEsmContent(tempRootFilePath) {
|
|
@@ -130,7 +146,14 @@ async function buildGlobalStaticData(getGlobalStaticData) {
|
|
|
130
146
|
const response = await getGlobalStaticData();
|
|
131
147
|
return response;
|
|
132
148
|
}
|
|
133
|
-
async function buildStaticPage(
|
|
149
|
+
async function buildStaticPage({
|
|
150
|
+
entryPoint,
|
|
151
|
+
outFile,
|
|
152
|
+
rootStaticContent,
|
|
153
|
+
assetsTagStr,
|
|
154
|
+
outDir,
|
|
155
|
+
showLog
|
|
156
|
+
}) {
|
|
134
157
|
const targetFilePath = url.pathToFileURL(entryPoint).href;
|
|
135
158
|
const pageEsmContent = await import(targetFilePath);
|
|
136
159
|
const pageJsxContent = pageEsmContent.default;
|
|
@@ -139,11 +162,29 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
|
|
|
139
162
|
const staticData = pageEsmContent.getStaticData ? await buildStaticData(pageEsmContent.getStaticData) : void 0;
|
|
140
163
|
if (!staticData) {
|
|
141
164
|
const staticDataItem = defaultStaticDataItem;
|
|
142
|
-
return await buildHtmlPage(
|
|
165
|
+
return await buildHtmlPage({
|
|
166
|
+
pageJsxContent,
|
|
167
|
+
staticDataItem,
|
|
168
|
+
routePath: outFile,
|
|
169
|
+
rootStaticContent,
|
|
170
|
+
assetsTagStr,
|
|
171
|
+
frontmatter,
|
|
172
|
+
outDir,
|
|
173
|
+
showLog
|
|
174
|
+
});
|
|
143
175
|
}
|
|
144
176
|
if ("props" in staticData && "paths" in staticData === false) {
|
|
145
177
|
const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
|
|
146
|
-
return await buildHtmlPage(
|
|
178
|
+
return await buildHtmlPage({
|
|
179
|
+
pageJsxContent,
|
|
180
|
+
staticDataItem,
|
|
181
|
+
routePath: outFile,
|
|
182
|
+
rootStaticContent,
|
|
183
|
+
assetsTagStr,
|
|
184
|
+
frontmatter,
|
|
185
|
+
outDir,
|
|
186
|
+
showLog
|
|
187
|
+
});
|
|
147
188
|
}
|
|
148
189
|
if ("paths" in staticData) {
|
|
149
190
|
const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
|
|
@@ -152,7 +193,16 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
|
|
|
152
193
|
const reg = new RegExp("\\[" + key + "\\]", "g");
|
|
153
194
|
fixedOutfile = fixedOutfile.replace(reg, `${value}`);
|
|
154
195
|
}
|
|
155
|
-
return await buildHtmlPage(
|
|
196
|
+
return await buildHtmlPage({
|
|
197
|
+
pageJsxContent,
|
|
198
|
+
staticDataItem,
|
|
199
|
+
routePath: fixedOutfile,
|
|
200
|
+
rootStaticContent,
|
|
201
|
+
assetsTagStr,
|
|
202
|
+
frontmatter,
|
|
203
|
+
outDir,
|
|
204
|
+
showLog
|
|
205
|
+
});
|
|
156
206
|
}
|
|
157
207
|
if (Array.isArray(staticData) && staticData.length > 0) {
|
|
158
208
|
const entryPoints = staticData;
|
|
@@ -163,7 +213,16 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
|
|
|
163
213
|
const reg = new RegExp("\\[" + key + "\\]", "g");
|
|
164
214
|
fixedOutfile = fixedOutfile.replace(reg, `${value}`);
|
|
165
215
|
}
|
|
166
|
-
return await buildHtmlPage(
|
|
216
|
+
return await buildHtmlPage({
|
|
217
|
+
pageJsxContent,
|
|
218
|
+
staticDataItem,
|
|
219
|
+
routePath: fixedOutfile,
|
|
220
|
+
rootStaticContent,
|
|
221
|
+
assetsTagStr,
|
|
222
|
+
frontmatter,
|
|
223
|
+
outDir,
|
|
224
|
+
showLog
|
|
225
|
+
});
|
|
167
226
|
}));
|
|
168
227
|
}
|
|
169
228
|
}
|
|
@@ -171,7 +230,16 @@ async function buildStaticData(getStaticData) {
|
|
|
171
230
|
const response = await getStaticData();
|
|
172
231
|
return response;
|
|
173
232
|
}
|
|
174
|
-
async function buildHtmlPage(
|
|
233
|
+
async function buildHtmlPage({
|
|
234
|
+
pageJsxContent,
|
|
235
|
+
staticDataItem,
|
|
236
|
+
routePath,
|
|
237
|
+
rootStaticContent,
|
|
238
|
+
assetsTagStr,
|
|
239
|
+
frontmatter,
|
|
240
|
+
outDir,
|
|
241
|
+
showLog
|
|
242
|
+
}) {
|
|
175
243
|
if (frontmatter == null ? void 0 : frontmatter.draft) {
|
|
176
244
|
return;
|
|
177
245
|
}
|
|
@@ -227,7 +295,7 @@ async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStat
|
|
|
227
295
|
}
|
|
228
296
|
const replacedHtml = html[0].replace(/<div class="minista-comment" hidden="">(.+?)<\/div>/g, "\n<!-- $1 -->");
|
|
229
297
|
await fs.outputFile(routePath, replacedHtml).then(() => {
|
|
230
|
-
console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(routePath)}`);
|
|
298
|
+
showLog && console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(routePath)}`);
|
|
231
299
|
}).catch((err) => {
|
|
232
300
|
console.error(err);
|
|
233
301
|
});
|
|
@@ -525,7 +593,7 @@ async function buildPartialHydrateAssets(viteConfig, buildOptions) {
|
|
|
525
593
|
resolve: {
|
|
526
594
|
alias: activePreact ? resolveAliasPreact : {}
|
|
527
595
|
},
|
|
528
|
-
|
|
596
|
+
logLevel: "error"
|
|
529
597
|
});
|
|
530
598
|
const mergedConfig = mergeViteConfig({}, customConfig);
|
|
531
599
|
const result = await viteBuild(mergedConfig);
|
|
@@ -545,6 +613,134 @@ async function buildPartialHydrateAssets(viteConfig, buildOptions) {
|
|
|
545
613
|
});
|
|
546
614
|
}
|
|
547
615
|
}
|
|
616
|
+
async function buildSearchJson({
|
|
617
|
+
config,
|
|
618
|
+
useCacheExists,
|
|
619
|
+
entryPoints,
|
|
620
|
+
entryBase,
|
|
621
|
+
outFile,
|
|
622
|
+
showLog
|
|
623
|
+
}) {
|
|
624
|
+
if (useCacheExists) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
const { trimTitle, targetSelector, hit } = config.search;
|
|
628
|
+
const tempWords = [];
|
|
629
|
+
const tempPages = [];
|
|
630
|
+
await Promise.all(entryPoints.map(async (filePath) => {
|
|
631
|
+
const html = await fs.readFile(filePath, { encoding: "utf-8" });
|
|
632
|
+
const parsedHtml = parse(html, {
|
|
633
|
+
blockTextElements: { script: false, style: false, pre: false }
|
|
634
|
+
});
|
|
635
|
+
const regTrimPath = new RegExp(`^${entryBase}|index|.html`, "g");
|
|
636
|
+
const path2 = filePath.replace(regTrimPath, "");
|
|
637
|
+
const regTrimTitle = new RegExp(trimTitle);
|
|
638
|
+
const pTitle = parsedHtml.querySelector("title");
|
|
639
|
+
const title = pTitle ? pTitle.rawText.replace(regTrimTitle, "") : "";
|
|
640
|
+
const titleArray = mojigiri(title);
|
|
641
|
+
const targetContent = parsedHtml.querySelector(targetSelector);
|
|
642
|
+
if (!targetContent) {
|
|
643
|
+
tempWords.push(title);
|
|
644
|
+
tempPages.push({
|
|
645
|
+
path: path2,
|
|
646
|
+
toc: [],
|
|
647
|
+
title: titleArray,
|
|
648
|
+
content: []
|
|
649
|
+
});
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
const contents = [];
|
|
653
|
+
async function getContent(element) {
|
|
654
|
+
if (element.id) {
|
|
655
|
+
contents.push({ type: "id", value: [element.id] });
|
|
656
|
+
}
|
|
657
|
+
if (element._rawText) {
|
|
658
|
+
const text = element._rawText.replace(/\n/g, "").replace(/\s{2,}/g, " ").trim();
|
|
659
|
+
const words2 = mojigiri(text);
|
|
660
|
+
if (words2.length > 0) {
|
|
661
|
+
contents.push({ type: "words", value: words2 });
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
if (element.childNodes) {
|
|
665
|
+
await Promise.all(element.childNodes.map(async (childNode) => {
|
|
666
|
+
return await getContent(childNode);
|
|
667
|
+
}));
|
|
668
|
+
}
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
await getContent(targetContent);
|
|
672
|
+
const toc = [];
|
|
673
|
+
const contentArray = [];
|
|
674
|
+
let contentCount = 0;
|
|
675
|
+
contents.forEach((content) => {
|
|
676
|
+
if (content.type === "id") {
|
|
677
|
+
toc.push([contentCount, content.value[0]]);
|
|
678
|
+
return;
|
|
679
|
+
} else if (content.type === "words") {
|
|
680
|
+
contentArray.push(content.value);
|
|
681
|
+
contentCount = contentCount + content.value.length;
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
const body = targetContent.rawText.replace(/\n/g, "").replace(/\s{2,}/g, " ").trim();
|
|
686
|
+
tempWords.push(title);
|
|
687
|
+
tempWords.push(body);
|
|
688
|
+
tempPages.push({
|
|
689
|
+
path: path2,
|
|
690
|
+
toc,
|
|
691
|
+
title: titleArray,
|
|
692
|
+
content: contentArray.flat()
|
|
693
|
+
});
|
|
694
|
+
}));
|
|
695
|
+
const words = mojigiri(tempWords.join(" "));
|
|
696
|
+
const sortedWords = [...new Set(words)].sort();
|
|
697
|
+
const regHitsArray = [
|
|
698
|
+
hit.number && "[0-9]",
|
|
699
|
+
hit.english && "[a-zA-Z]",
|
|
700
|
+
hit.hiragana && "[\u3041-\u3093]",
|
|
701
|
+
hit.katakana && "[\u30A1-\u30F4]",
|
|
702
|
+
hit.kanji && "[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3400-\u4DB5\u4E00-\u9FC3\uF900-\uFA2D\uFA30-\uFA6A\uFA70-\uFAD9]"
|
|
703
|
+
].filter((reg) => reg);
|
|
704
|
+
const regHits = new RegExp(`(${regHitsArray.join("|")})`);
|
|
705
|
+
const tempHits = sortedWords.filter((word) => word.length >= hit.minLength && regHits.test(word) && word !== "...");
|
|
706
|
+
const hits = tempHits.map((word) => {
|
|
707
|
+
return sortedWords.indexOf(word);
|
|
708
|
+
});
|
|
709
|
+
const pages = [];
|
|
710
|
+
await Promise.all(tempPages.map(async (page) => {
|
|
711
|
+
const path2 = page.path;
|
|
712
|
+
const toc = page.toc;
|
|
713
|
+
const title = page.title.map((word) => {
|
|
714
|
+
return sortedWords.indexOf(word);
|
|
715
|
+
});
|
|
716
|
+
const content = page.content.map((word) => {
|
|
717
|
+
return sortedWords.indexOf(word);
|
|
718
|
+
});
|
|
719
|
+
pages.push({ path: path2, title, toc, content });
|
|
720
|
+
}));
|
|
721
|
+
const sortedPages = pages.sort((a, b) => {
|
|
722
|
+
const pathA = a.path.toUpperCase();
|
|
723
|
+
const pathB = b.path.toUpperCase();
|
|
724
|
+
if (pathA < pathB) {
|
|
725
|
+
return -1;
|
|
726
|
+
}
|
|
727
|
+
if (pathA > pathB) {
|
|
728
|
+
return 1;
|
|
729
|
+
}
|
|
730
|
+
return 0;
|
|
731
|
+
});
|
|
732
|
+
const template = {
|
|
733
|
+
words: sortedWords,
|
|
734
|
+
hits,
|
|
735
|
+
pages: sortedPages
|
|
736
|
+
};
|
|
737
|
+
await fs.outputJson(outFile, template).then(() => {
|
|
738
|
+
showLog && console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(outFile)}`);
|
|
739
|
+
}).catch((err) => {
|
|
740
|
+
console.error(err);
|
|
741
|
+
});
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
548
744
|
async function buildCopyDir(targetDir, outDir, log) {
|
|
549
745
|
const checkTargetDir = await fs.pathExists(targetDir);
|
|
550
746
|
if (checkTargetDir) {
|
|
@@ -574,6 +770,7 @@ export {
|
|
|
574
770
|
buildPartialStringIndex,
|
|
575
771
|
buildPartialStringInitial,
|
|
576
772
|
buildRootEsmContent,
|
|
773
|
+
buildSearchJson,
|
|
577
774
|
buildStaticData,
|
|
578
775
|
buildStaticPage,
|
|
579
776
|
buildStaticPages,
|
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ import { systemConfig } from "./system.js";
|
|
|
23
23
|
import { getViteConfig } from "./vite.js";
|
|
24
24
|
import { getMdxConfig } from "./mdx.js";
|
|
25
25
|
import { emptyResolveDir } from "./empty.js";
|
|
26
|
-
import { createDevServer } from "./server.js";
|
|
26
|
+
import { createDevServer, createDevServerAssets } from "./server.js";
|
|
27
27
|
import { previewLocal } from "./preview.js";
|
|
28
28
|
import {
|
|
29
29
|
generateViteImporters,
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
generateAssets,
|
|
37
37
|
generatePublic,
|
|
38
38
|
generateDownload,
|
|
39
|
+
generateSearchJson,
|
|
39
40
|
generateBeautify
|
|
40
41
|
} from "./generate.js";
|
|
41
42
|
const cli = cac("minista");
|
|
@@ -58,11 +59,18 @@ cli.command("[root]", "start dev server").alias("dev").option("--host [host]", `
|
|
|
58
59
|
const mdxConfig = await getMdxConfig(config);
|
|
59
60
|
const viteConfig = await getViteConfig(config, mdxConfig, cliOptions);
|
|
60
61
|
await Promise.all([
|
|
62
|
+
emptyResolveDir(systemConfig.temp.root.outDir),
|
|
63
|
+
emptyResolveDir(systemConfig.temp.assets.outDir),
|
|
64
|
+
emptyResolveDir(systemConfig.temp.pages.outDir),
|
|
61
65
|
emptyResolveDir(systemConfig.temp.viteImporter.outDir),
|
|
62
|
-
emptyResolveDir(systemConfig.temp.icons.outDir)
|
|
66
|
+
emptyResolveDir(systemConfig.temp.icons.outDir),
|
|
67
|
+
emptyResolveDir(systemConfig.temp.partialHydration.outDir)
|
|
63
68
|
]);
|
|
64
69
|
await generateViteImporters(config, viteConfig);
|
|
65
|
-
await
|
|
70
|
+
await Promise.all([
|
|
71
|
+
createDevServer(viteConfig),
|
|
72
|
+
createDevServerAssets(config, mdxConfig)
|
|
73
|
+
]);
|
|
66
74
|
} catch (err) {
|
|
67
75
|
console.log(err);
|
|
68
76
|
process.exit(1);
|
|
@@ -94,11 +102,11 @@ cli.command("build [root]", "build for production").action(async () => {
|
|
|
94
102
|
generatePartialHydration(config, mdxConfig, viteConfig)
|
|
95
103
|
]);
|
|
96
104
|
await Promise.all([
|
|
97
|
-
generateHtmlPages(config),
|
|
105
|
+
generateHtmlPages(config, config.pagesOutDir, true),
|
|
98
106
|
generateAssets(config),
|
|
99
107
|
generatePublic(config)
|
|
100
108
|
]);
|
|
101
|
-
await Promise.all([generateDownload(config)]);
|
|
109
|
+
await Promise.all([generateDownload(config), generateSearchJson(config)]);
|
|
102
110
|
await Promise.all([
|
|
103
111
|
generateBeautify(config, "html"),
|
|
104
112
|
generateBeautify(config, "css"),
|
package/dist/config.js
CHANGED
|
@@ -109,6 +109,24 @@ const defaultConfig = {
|
|
|
109
109
|
rehypePlugins: []
|
|
110
110
|
}
|
|
111
111
|
},
|
|
112
|
+
search: {
|
|
113
|
+
useJson: false,
|
|
114
|
+
cache: false,
|
|
115
|
+
outDir: "assets",
|
|
116
|
+
outName: "search",
|
|
117
|
+
include: ["**/*"],
|
|
118
|
+
exclude: ["404"],
|
|
119
|
+
trimTitle: "",
|
|
120
|
+
targetSelector: "[data-search]",
|
|
121
|
+
hit: {
|
|
122
|
+
minLength: 3,
|
|
123
|
+
number: false,
|
|
124
|
+
english: true,
|
|
125
|
+
hiragana: false,
|
|
126
|
+
katakana: true,
|
|
127
|
+
kanji: true
|
|
128
|
+
}
|
|
129
|
+
},
|
|
112
130
|
beautify: {
|
|
113
131
|
useHtml: true,
|
|
114
132
|
useAssets: false,
|
|
@@ -171,12 +189,15 @@ async function resolveConfig(config) {
|
|
|
171
189
|
assetsOutHref: slashEnd(config.base) + noSlashEnd(config.assets.outDir),
|
|
172
190
|
downloadOutDir: slashEnd(config.out) + noSlashEnd(config.assets.download.outDir),
|
|
173
191
|
downloadOutHref: slashEnd(config.base) + noSlashEnd(config.assets.download.outDir),
|
|
192
|
+
searchJsonOutput: slashEnd(config.out) + slashEnd(config.search.outDir) + noSlashEnd(config.search.outName) + ".json",
|
|
174
193
|
viteAssetsOutput: slashEnd(config.assets.outDir) + noSlashEnd(config.assets.outName) + ".[ext]",
|
|
175
194
|
viteAssetsImagesOutput: slashEnd(config.assets.images.outDir) + noSlashEnd(config.assets.images.outName) + ".[ext]",
|
|
176
195
|
viteAssetsFontsOutput: slashEnd(config.assets.fonts.outDir) + noSlashEnd(config.assets.fonts.outName) + ".[ext]",
|
|
177
196
|
vitePluginSvgSpriteIconsSrcDir: noSlashEnd(config.assets.icons.srcDir),
|
|
178
197
|
vitePluginSvgSpriteIconsOutput: slashEnd("/") + slashEnd(config.assets.icons.outDir) + noSlashEnd(config.assets.icons.outName) + ".svg",
|
|
179
|
-
vitePluginSvgSpriteIconsTempOutput: slashEnd(systemConfig.temp.icons.outDir) + slashEnd(config.assets.icons.outDir) + noSlashEnd(config.assets.icons.outName) + ".svg"
|
|
198
|
+
vitePluginSvgSpriteIconsTempOutput: slashEnd(systemConfig.temp.icons.outDir) + slashEnd(config.assets.icons.outDir) + noSlashEnd(config.assets.icons.outName) + ".svg",
|
|
199
|
+
vitePluginSearchJsonOutput: slashEnd("/") + slashEnd(config.search.outDir) + noSlashEnd(config.search.outName) + ".json",
|
|
200
|
+
vitePluginSearchJsonTempOutput: slashEnd(systemConfig.temp.search.outDir) + slashEnd(config.search.outDir) + noSlashEnd(config.search.outName) + ".json"
|
|
180
201
|
});
|
|
181
202
|
return resolvedConfig;
|
|
182
203
|
}
|
package/dist/esbuild.js
CHANGED
|
@@ -28,9 +28,9 @@ function getEsbuildResolvePath(args, alias) {
|
|
|
28
28
|
}
|
|
29
29
|
const aliasKeys = Object.keys(aliasObject);
|
|
30
30
|
const aliasReg = new RegExp(`^(${aliasKeys.map((x) => escapeRegExp(x)).join("|")})`);
|
|
31
|
-
const aliasPath = args.path.replace(aliasReg, function(match) {
|
|
31
|
+
const aliasPath = alias.length ? args.path.replace(aliasReg, function(match) {
|
|
32
32
|
return aliasObject[match];
|
|
33
|
-
});
|
|
33
|
+
}) : args.path;
|
|
34
34
|
const absolutePath = path.isAbsolute(aliasPath) ? aliasPath : path.join(args.resolveDir, aliasPath);
|
|
35
35
|
const replacedPath = absolutePath.replaceAll("\\", "/");
|
|
36
36
|
return replacedPath;
|
package/dist/generate.d.ts
CHANGED
|
@@ -7,8 +7,9 @@ export declare function generateTempPages(config: MinistaResolveConfig, mdxConfi
|
|
|
7
7
|
export declare function generateTempAssets(config: MinistaResolveConfig, viteConfig: InlineConfig): Promise<void>;
|
|
8
8
|
export declare function generatePartialHydration(config: MinistaResolveConfig, mdxConfig: MdxOptions, viteConfig: InlineConfig): Promise<void>;
|
|
9
9
|
export declare function generateNoStyleTemp(targetDir: string): Promise<void>;
|
|
10
|
-
export declare function generateHtmlPages(config: MinistaResolveConfig): Promise<void>;
|
|
10
|
+
export declare function generateHtmlPages(config: MinistaResolveConfig, outDir: string, showLog: boolean): Promise<void>;
|
|
11
11
|
export declare function generateAssets(config: MinistaResolveConfig): Promise<void>;
|
|
12
12
|
export declare function generatePublic(config: MinistaResolveConfig): Promise<void>;
|
|
13
13
|
export declare function generateDownload(config: MinistaResolveConfig): Promise<void>;
|
|
14
|
+
export declare function generateSearchJson(config: MinistaResolveConfig): Promise<void>;
|
|
14
15
|
export declare function generateBeautify(config: MinistaResolveConfig, target: "html" | "css" | "js"): Promise<void>;
|
package/dist/generate.js
CHANGED
|
@@ -3,7 +3,12 @@ import fs from "fs-extra";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import url from "url";
|
|
5
5
|
import { systemConfig } from "./system.js";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
getFilePath,
|
|
8
|
+
getFilePaths,
|
|
9
|
+
getFilterFilePaths,
|
|
10
|
+
getSameFilePaths
|
|
11
|
+
} from "./path.js";
|
|
7
12
|
import { slashEnd, noSlashEnd } from "./utils.js";
|
|
8
13
|
import {
|
|
9
14
|
buildTempPages,
|
|
@@ -20,7 +25,8 @@ import {
|
|
|
20
25
|
buildPartialStringBundle,
|
|
21
26
|
buildPartialStringInitial,
|
|
22
27
|
buildPartialHydrateIndex,
|
|
23
|
-
buildPartialHydrateAssets
|
|
28
|
+
buildPartialHydrateAssets,
|
|
29
|
+
buildSearchJson
|
|
24
30
|
} from "./build.js";
|
|
25
31
|
import { optimizeCommentOutStyleImport } from "./optimize.js";
|
|
26
32
|
import { downloadFiles } from "./download.js";
|
|
@@ -119,7 +125,7 @@ async function generateNoStyleTemp(targetDir) {
|
|
|
119
125
|
await optimizeCommentOutStyleImport(targetFiles);
|
|
120
126
|
}
|
|
121
127
|
}
|
|
122
|
-
async function generateHtmlPages(config) {
|
|
128
|
+
async function generateHtmlPages(config, outDir, showLog) {
|
|
123
129
|
const tempRootName = config.root.srcName;
|
|
124
130
|
const tempRootOutDir = systemConfig.temp.root.outDir;
|
|
125
131
|
const tempPagesOutDir = systemConfig.temp.pages.outDir;
|
|
@@ -134,10 +140,14 @@ async function generateHtmlPages(config) {
|
|
|
134
140
|
outBase: tempAssetsOutDir,
|
|
135
141
|
outDir: config.assetsOutHref
|
|
136
142
|
});
|
|
137
|
-
await buildStaticPages(
|
|
143
|
+
await buildStaticPages({
|
|
144
|
+
entryPoints: tempPageFilePaths,
|
|
145
|
+
tempRootFilePath,
|
|
138
146
|
outBase: tempPagesOutDir,
|
|
139
|
-
outDir
|
|
140
|
-
|
|
147
|
+
outDir,
|
|
148
|
+
assetsTagStr,
|
|
149
|
+
showLog
|
|
150
|
+
});
|
|
141
151
|
}
|
|
142
152
|
async function generateAssets(config) {
|
|
143
153
|
await buildCopyDir(systemConfig.temp.assets.outDir, slashEnd(config.out) + noSlashEnd(config.assets.outDir), "assets");
|
|
@@ -152,6 +162,26 @@ async function generateDownload(config) {
|
|
|
152
162
|
}
|
|
153
163
|
return;
|
|
154
164
|
}
|
|
165
|
+
async function generateSearchJson(config) {
|
|
166
|
+
if (config.search.useJson) {
|
|
167
|
+
const entryPoints = await getFilterFilePaths({
|
|
168
|
+
targetDir: config.out,
|
|
169
|
+
include: config.search.include,
|
|
170
|
+
exclude: config.search.exclude,
|
|
171
|
+
exts: "html"
|
|
172
|
+
});
|
|
173
|
+
const outFile = config.searchJsonOutput;
|
|
174
|
+
await buildSearchJson({
|
|
175
|
+
config,
|
|
176
|
+
useCacheExists: false,
|
|
177
|
+
entryPoints,
|
|
178
|
+
entryBase: config.out,
|
|
179
|
+
outFile,
|
|
180
|
+
showLog: true
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
155
185
|
async function generateBeautify(config, target) {
|
|
156
186
|
switch (target) {
|
|
157
187
|
case "html":
|
|
@@ -187,6 +217,7 @@ export {
|
|
|
187
217
|
generateNoStyleTemp,
|
|
188
218
|
generatePartialHydration,
|
|
189
219
|
generatePublic,
|
|
220
|
+
generateSearchJson,
|
|
190
221
|
generateTempAssets,
|
|
191
222
|
generateTempPages,
|
|
192
223
|
generateTempRoot,
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
package/dist/path.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
export declare function getFilePath(targetDir: string, fileName: string,
|
|
2
|
-
export declare function getFilePaths(targetDir: string,
|
|
3
|
-
export declare function
|
|
1
|
+
export declare function getFilePath(targetDir: string, fileName: string, ext: string): string;
|
|
2
|
+
export declare function getFilePaths(targetDir: string, exts: string | string[]): Promise<string[]>;
|
|
3
|
+
export declare function getFilterFilePaths({ targetDir, include, exclude, exts, }: {
|
|
4
|
+
targetDir?: string;
|
|
5
|
+
include: string[];
|
|
6
|
+
exclude?: string[];
|
|
7
|
+
exts?: string | string[];
|
|
8
|
+
}): Promise<string[]>;
|
|
9
|
+
export declare function getSameFilePaths(targetDir: string, fileName: string, exts: string | string[]): Promise<string[]>;
|
package/dist/path.js
CHANGED
|
@@ -2,25 +2,41 @@ import React from "react";
|
|
|
2
2
|
import fs from "fs-extra";
|
|
3
3
|
import fg from "fast-glob";
|
|
4
4
|
import path from "path";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { slashEnd } from "./utils.js";
|
|
6
|
+
function getFilePath(targetDir, fileName, ext) {
|
|
7
|
+
const filePath = `${targetDir}/${fileName}.${ext}`;
|
|
7
8
|
const file = fs.existsSync(path.resolve(filePath)) ? path.resolve(filePath) : "";
|
|
8
9
|
return file;
|
|
9
10
|
}
|
|
10
|
-
async function getFilePaths(targetDir,
|
|
11
|
-
const
|
|
12
|
-
const globPattern = `${targetDir}/**/*.+(${
|
|
11
|
+
async function getFilePaths(targetDir, exts) {
|
|
12
|
+
const strExt = typeof exts === "string" ? exts : exts.join("|");
|
|
13
|
+
const globPattern = `${targetDir}/**/*.+(${strExt})`;
|
|
13
14
|
const files = await fg(globPattern, { extglob: true });
|
|
14
15
|
return files;
|
|
15
16
|
}
|
|
16
|
-
async function
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
async function getFilterFilePaths({
|
|
18
|
+
targetDir,
|
|
19
|
+
include,
|
|
20
|
+
exclude,
|
|
21
|
+
exts
|
|
22
|
+
}) {
|
|
23
|
+
const fixDir = targetDir ? slashEnd(targetDir) : "";
|
|
24
|
+
const fixExt = exts ? typeof exts === "string" ? `.${exts.replace(/^\./, "")}` : `.+(${exts.map((ext) => ext.replace(/^\./, "")).join("|")})` : "";
|
|
25
|
+
const includes = include.map((str) => `${fixDir}${str}${fixExt}`);
|
|
26
|
+
const excludes = exclude ? exclude.map((str) => `!${fixDir}${str}${fixExt}`) : [];
|
|
27
|
+
const globPattern = [includes, excludes].flat();
|
|
28
|
+
const files = await fg(globPattern, { extglob: fixExt ? true : false });
|
|
29
|
+
return files;
|
|
30
|
+
}
|
|
31
|
+
async function getSameFilePaths(targetDir, fileName, exts) {
|
|
32
|
+
const strExt = typeof exts === "string" ? exts : exts.join("|");
|
|
33
|
+
const globPattern = `${targetDir}/${fileName}.+(${strExt})`;
|
|
19
34
|
const files = await fg(globPattern, { extglob: true });
|
|
20
35
|
return files;
|
|
21
36
|
}
|
|
22
37
|
export {
|
|
23
38
|
getFilePath,
|
|
24
39
|
getFilePaths,
|
|
40
|
+
getFilterFilePaths,
|
|
25
41
|
getSameFilePaths
|
|
26
42
|
};
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type SearchData = {
|
|
3
|
+
words: string[];
|
|
4
|
+
hits: number[];
|
|
5
|
+
pages: SearchPage[];
|
|
6
|
+
};
|
|
7
|
+
export declare type SearchPage = {
|
|
8
|
+
path: string;
|
|
9
|
+
title: number[];
|
|
10
|
+
toc: [number, string][];
|
|
11
|
+
content: number[];
|
|
12
|
+
};
|
|
13
|
+
export declare type SearchResult = {
|
|
14
|
+
path: string;
|
|
15
|
+
content: string;
|
|
16
|
+
};
|
|
17
|
+
export interface SearchProps extends React.HTMLAttributes<HTMLElement> {
|
|
18
|
+
jsonPath: string;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
minHitLength?: number;
|
|
21
|
+
maxHitPages?: number;
|
|
22
|
+
maxHitWords?: number;
|
|
23
|
+
searchFieldClassName?: string;
|
|
24
|
+
searchFieldInsertBeforeElement?: React.ReactElement;
|
|
25
|
+
searchFieldInsertAfterElement?: React.ReactElement;
|
|
26
|
+
searchListClassName?: string;
|
|
27
|
+
attributes?: React.HTMLAttributes<HTMLElement>;
|
|
28
|
+
}
|
|
29
|
+
export interface SearchFieldProps extends React.HTMLAttributes<HTMLElement> {
|
|
30
|
+
jsonPath: string;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
minHitLength?: number;
|
|
33
|
+
maxHitPages?: number;
|
|
34
|
+
maxHitWords?: number;
|
|
35
|
+
insertBeforeElement?: React.ReactElement;
|
|
36
|
+
insertAfterElement?: React.ReactElement;
|
|
37
|
+
setSearchValues?: React.Dispatch<React.SetStateAction<string[]>>;
|
|
38
|
+
setSearchHitValues?: React.Dispatch<React.SetStateAction<string[]>>;
|
|
39
|
+
setSearchResults?: React.Dispatch<React.SetStateAction<SearchResult[]>>;
|
|
40
|
+
attributes?: React.HTMLAttributes<HTMLElement>;
|
|
41
|
+
}
|
|
42
|
+
export interface SearchListProps extends React.HTMLAttributes<HTMLElement> {
|
|
43
|
+
searchValues?: string[];
|
|
44
|
+
searchHitValues?: string[];
|
|
45
|
+
searchResults?: SearchResult[];
|
|
46
|
+
attributes?: React.HTMLAttributes<HTMLElement>;
|
|
47
|
+
}
|
|
48
|
+
export declare const Search: (props: SearchProps) => JSX.Element;
|
|
49
|
+
export declare const SearchField: (props: SearchFieldProps) => JSX.Element;
|
|
50
|
+
export declare const SearchList: (props: SearchListProps) => JSX.Element;
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
import React from "react";
|
|
30
|
+
import { useState, useEffect } from "react";
|
|
31
|
+
function compNum(a, b) {
|
|
32
|
+
return a - b;
|
|
33
|
+
}
|
|
34
|
+
const Search = (props) => {
|
|
35
|
+
const _a = props, {
|
|
36
|
+
jsonPath,
|
|
37
|
+
placeholder = props.placeholder || "",
|
|
38
|
+
minHitLength = props.minHitLength || 2,
|
|
39
|
+
maxHitPages = props.maxHitPages || 5,
|
|
40
|
+
maxHitWords = props.maxHitWords || 20,
|
|
41
|
+
searchFieldInsertBeforeElement,
|
|
42
|
+
searchFieldInsertAfterElement,
|
|
43
|
+
searchFieldClassName,
|
|
44
|
+
searchListClassName
|
|
45
|
+
} = _a, attributes = __objRest(_a, [
|
|
46
|
+
"jsonPath",
|
|
47
|
+
"placeholder",
|
|
48
|
+
"minHitLength",
|
|
49
|
+
"maxHitPages",
|
|
50
|
+
"maxHitWords",
|
|
51
|
+
"searchFieldInsertBeforeElement",
|
|
52
|
+
"searchFieldInsertAfterElement",
|
|
53
|
+
"searchFieldClassName",
|
|
54
|
+
"searchListClassName"
|
|
55
|
+
]);
|
|
56
|
+
const [searchValues, setSearchValues] = useState([]);
|
|
57
|
+
const [searchHitValues, setSearchHitValues] = useState([]);
|
|
58
|
+
const [searchResults, setSearchResults] = useState([]);
|
|
59
|
+
return /* @__PURE__ */ React.createElement("div", __spreadValues({}, attributes), /* @__PURE__ */ React.createElement(SearchField, {
|
|
60
|
+
className: searchFieldClassName,
|
|
61
|
+
jsonPath,
|
|
62
|
+
placeholder,
|
|
63
|
+
minHitLength,
|
|
64
|
+
maxHitPages,
|
|
65
|
+
maxHitWords,
|
|
66
|
+
insertBeforeElement: searchFieldInsertBeforeElement,
|
|
67
|
+
insertAfterElement: searchFieldInsertAfterElement,
|
|
68
|
+
setSearchValues,
|
|
69
|
+
setSearchHitValues,
|
|
70
|
+
setSearchResults
|
|
71
|
+
}), /* @__PURE__ */ React.createElement(SearchList, {
|
|
72
|
+
className: searchListClassName,
|
|
73
|
+
searchValues,
|
|
74
|
+
searchHitValues,
|
|
75
|
+
searchResults
|
|
76
|
+
}));
|
|
77
|
+
};
|
|
78
|
+
const SearchField = (props) => {
|
|
79
|
+
const _a = props, {
|
|
80
|
+
jsonPath,
|
|
81
|
+
placeholder = props.placeholder || "",
|
|
82
|
+
minHitLength = props.minHitLength || 2,
|
|
83
|
+
maxHitPages = props.maxHitPages || 5,
|
|
84
|
+
maxHitWords = props.maxHitWords || 20,
|
|
85
|
+
insertBeforeElement,
|
|
86
|
+
insertAfterElement,
|
|
87
|
+
setSearchValues,
|
|
88
|
+
setSearchHitValues,
|
|
89
|
+
setSearchResults
|
|
90
|
+
} = _a, attributes = __objRest(_a, [
|
|
91
|
+
"jsonPath",
|
|
92
|
+
"placeholder",
|
|
93
|
+
"minHitLength",
|
|
94
|
+
"maxHitPages",
|
|
95
|
+
"maxHitWords",
|
|
96
|
+
"insertBeforeElement",
|
|
97
|
+
"insertAfterElement",
|
|
98
|
+
"setSearchValues",
|
|
99
|
+
"setSearchHitValues",
|
|
100
|
+
"setSearchResults"
|
|
101
|
+
]);
|
|
102
|
+
const [callSearchData, setCallSearchData] = useState(false);
|
|
103
|
+
const [searchData, setSearchData] = useState({
|
|
104
|
+
words: [],
|
|
105
|
+
hits: [],
|
|
106
|
+
pages: []
|
|
107
|
+
});
|
|
108
|
+
const [searchHits, setSearchHits] = useState([]);
|
|
109
|
+
const [searchPages, setSearchPages] = useState([]);
|
|
110
|
+
const searchHandler = (event) => {
|
|
111
|
+
if (!callSearchData) {
|
|
112
|
+
setCallSearchData(true);
|
|
113
|
+
}
|
|
114
|
+
if (!searchData || !searchHits || !searchPages) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const inputValues = event.target.value.split(" ");
|
|
118
|
+
const mergedInputValues = [...new Set(inputValues)].sort();
|
|
119
|
+
const hitValues = mergedInputValues.map((value) => {
|
|
120
|
+
if (value.length >= minHitLength) {
|
|
121
|
+
return searchHits.filter((hit) => {
|
|
122
|
+
return new RegExp(value, "i").test(hit);
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const mergedHitValues = [...new Set(hitValues.flat())].sort();
|
|
129
|
+
const hitIndexes = mergedHitValues.map((value) => {
|
|
130
|
+
return searchData.words.indexOf(value);
|
|
131
|
+
});
|
|
132
|
+
const hitPages = searchPages.flatMap((page) => {
|
|
133
|
+
const titleIndexs = page.title.filter((i) => hitIndexes.indexOf(i) !== -1);
|
|
134
|
+
const contentIndexs = page.content.filter((i) => hitIndexes.indexOf(i) !== -1);
|
|
135
|
+
if (titleIndexs.length || contentIndexs.length) {
|
|
136
|
+
return {
|
|
137
|
+
path: page.path,
|
|
138
|
+
title: titleIndexs,
|
|
139
|
+
toc: page.toc,
|
|
140
|
+
content: contentIndexs
|
|
141
|
+
};
|
|
142
|
+
} else {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
const sortedHitPages = [...new Set(hitPages)].sort((a, b) => {
|
|
147
|
+
if (a.title.length !== b.title.length) {
|
|
148
|
+
return (a.title.length - b.title.length) * -1;
|
|
149
|
+
}
|
|
150
|
+
if (a.content.length !== b.content.length) {
|
|
151
|
+
return (a.content.length - b.content.length) * -1;
|
|
152
|
+
}
|
|
153
|
+
return 0;
|
|
154
|
+
}).slice(0, maxHitPages);
|
|
155
|
+
const resultHitPages = sortedHitPages.map((page) => {
|
|
156
|
+
const targetPage = searchData.pages.find((dataPage) => dataPage.path === page.path);
|
|
157
|
+
if (page.title.length) {
|
|
158
|
+
const targetContent = targetPage.title.map((num) => searchData.words[num]).join(" ");
|
|
159
|
+
return {
|
|
160
|
+
path: targetPage.path,
|
|
161
|
+
content: targetContent
|
|
162
|
+
};
|
|
163
|
+
} else {
|
|
164
|
+
let getTargetId = function(targetIndex2, toc) {
|
|
165
|
+
if (!toc.length) {
|
|
166
|
+
return "";
|
|
167
|
+
}
|
|
168
|
+
const targetToc = page.toc.filter((item) => targetIndex2 >= item[0]).slice(-1)[0];
|
|
169
|
+
const targetId2 = targetToc ? "#" + targetToc[1] : "";
|
|
170
|
+
return targetId2;
|
|
171
|
+
};
|
|
172
|
+
const targetWord = page.content[0];
|
|
173
|
+
const targetIndex = targetPage.content.indexOf(targetWord);
|
|
174
|
+
const targetIndexes = targetPage.content.slice(targetIndex, targetIndex + maxHitWords);
|
|
175
|
+
const targetWords = targetIndexes.map((num) => searchData.words[num]).join("");
|
|
176
|
+
const targetContent = "..." + targetWords + "...";
|
|
177
|
+
const targetId = getTargetId(targetIndex, page.toc);
|
|
178
|
+
return {
|
|
179
|
+
path: targetPage.path + targetId,
|
|
180
|
+
content: targetContent
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
if (setSearchValues) {
|
|
185
|
+
const filterdInputValues = mergedInputValues.filter((value) => value && !value.includes(" "));
|
|
186
|
+
setSearchValues(filterdInputValues);
|
|
187
|
+
}
|
|
188
|
+
if (setSearchHitValues) {
|
|
189
|
+
setSearchHitValues(mergedHitValues);
|
|
190
|
+
}
|
|
191
|
+
if (setSearchResults) {
|
|
192
|
+
setSearchResults(resultHitPages);
|
|
193
|
+
}
|
|
194
|
+
return;
|
|
195
|
+
};
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
if (callSearchData) {
|
|
198
|
+
const getSearchData = async () => {
|
|
199
|
+
const response = await fetch(jsonPath);
|
|
200
|
+
const data = await response.json();
|
|
201
|
+
setSearchData(data);
|
|
202
|
+
if (data.words && data.hits) {
|
|
203
|
+
const hitWords = [];
|
|
204
|
+
await Promise.all(data.hits.map(async (hit) => {
|
|
205
|
+
return hitWords.push(data.words[hit]);
|
|
206
|
+
}));
|
|
207
|
+
setSearchHits(hitWords);
|
|
208
|
+
}
|
|
209
|
+
if (data.words && data.pages) {
|
|
210
|
+
const optimizePages = [];
|
|
211
|
+
await Promise.all(data.pages.map(async (page) => {
|
|
212
|
+
return optimizePages.push({
|
|
213
|
+
path: page.path,
|
|
214
|
+
title: [...new Set(page.title)].sort(compNum),
|
|
215
|
+
toc: page.toc,
|
|
216
|
+
content: [...new Set(page.content)].sort(compNum)
|
|
217
|
+
});
|
|
218
|
+
}));
|
|
219
|
+
setSearchPages(optimizePages);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
getSearchData();
|
|
223
|
+
}
|
|
224
|
+
}, [callSearchData]);
|
|
225
|
+
return /* @__PURE__ */ React.createElement("div", __spreadValues({}, attributes), insertBeforeElement, /* @__PURE__ */ React.createElement("input", {
|
|
226
|
+
type: "search",
|
|
227
|
+
placeholder,
|
|
228
|
+
onChange: searchHandler
|
|
229
|
+
}), insertAfterElement);
|
|
230
|
+
};
|
|
231
|
+
const SearchList = (props) => {
|
|
232
|
+
const _a = props, { searchValues, searchHitValues, searchResults } = _a, attributes = __objRest(_a, ["searchValues", "searchHitValues", "searchResults"]);
|
|
233
|
+
const checkValues = searchValues && searchValues.length;
|
|
234
|
+
const checkHitValues = searchHitValues && searchHitValues.length;
|
|
235
|
+
const checkResults = searchResults && searchResults.length;
|
|
236
|
+
if (checkValues && checkHitValues && checkResults) {
|
|
237
|
+
const regValues = new RegExp(`(${searchValues.join("|")})`, "ig");
|
|
238
|
+
const regHitValues = new RegExp(`(${searchHitValues.join("|")})`, "ig");
|
|
239
|
+
return /* @__PURE__ */ React.createElement("ul", __spreadValues({}, attributes), searchResults.map((item, index) => {
|
|
240
|
+
const words = item.content.split(regHitValues);
|
|
241
|
+
const filteredWords = words.filter((word) => word && word.length > 0);
|
|
242
|
+
const renderdWords = filteredWords.map((word, wordIndex) => {
|
|
243
|
+
if (word.match(regHitValues)) {
|
|
244
|
+
const glyphs = word.split(regValues);
|
|
245
|
+
const renderdGlyphs = glyphs.map((glyph, glyphIndex) => {
|
|
246
|
+
if (glyph.match(regValues)) {
|
|
247
|
+
return /* @__PURE__ */ React.createElement("mark", {
|
|
248
|
+
key: glyphIndex
|
|
249
|
+
}, glyph);
|
|
250
|
+
} else {
|
|
251
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
252
|
+
key: glyphIndex
|
|
253
|
+
}, glyph);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
257
|
+
key: wordIndex
|
|
258
|
+
}, renderdGlyphs);
|
|
259
|
+
} else {
|
|
260
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
261
|
+
key: wordIndex
|
|
262
|
+
}, word);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
const content = renderdWords;
|
|
266
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
267
|
+
key: index
|
|
268
|
+
}, /* @__PURE__ */ React.createElement("a", {
|
|
269
|
+
href: item.path
|
|
270
|
+
}, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, content)), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("small", null, item.path)))));
|
|
271
|
+
}));
|
|
272
|
+
} else if (checkResults) {
|
|
273
|
+
return /* @__PURE__ */ React.createElement("ul", __spreadValues({}, attributes), searchResults.map((item, index) => {
|
|
274
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
275
|
+
key: index
|
|
276
|
+
}, /* @__PURE__ */ React.createElement("a", {
|
|
277
|
+
href: item.path
|
|
278
|
+
}, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, item.content)), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("small", null, item.path)))));
|
|
279
|
+
}));
|
|
280
|
+
} else {
|
|
281
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
export {
|
|
285
|
+
Search,
|
|
286
|
+
SearchField,
|
|
287
|
+
SearchList
|
|
288
|
+
};
|
package/dist/server.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { InlineConfig } from "vite";
|
|
2
|
+
import type { Options as MdxOptions } from "@mdx-js/esbuild";
|
|
3
|
+
import type { MinistaResolveConfig } from "./types.js";
|
|
2
4
|
export declare function createDevServer(viteConfig: InlineConfig): Promise<void>;
|
|
5
|
+
export declare function createDevServerAssets(config: MinistaResolveConfig, mdxConfig: MdxOptions): Promise<void>;
|
package/dist/server.js
CHANGED
|
@@ -1,10 +1,64 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "path";
|
|
2
4
|
import { createServer } from "vite";
|
|
5
|
+
import { systemConfig } from "./system.js";
|
|
6
|
+
import { getFilterFilePaths } from "./path.js";
|
|
7
|
+
import { emptyResolveDir } from "./empty.js";
|
|
8
|
+
import {
|
|
9
|
+
generateTempRoot,
|
|
10
|
+
generateTempPages,
|
|
11
|
+
generateNoStyleTemp,
|
|
12
|
+
generateHtmlPages
|
|
13
|
+
} from "./generate.js";
|
|
14
|
+
import { buildSearchJson } from "./build.js";
|
|
3
15
|
async function createDevServer(viteConfig) {
|
|
4
16
|
const server = await createServer(viteConfig);
|
|
5
17
|
await server.listen();
|
|
6
18
|
server.printUrls();
|
|
7
19
|
}
|
|
20
|
+
async function createDevServerAssets(config, mdxConfig) {
|
|
21
|
+
const stopUseTriggers = [!config.search.useJson];
|
|
22
|
+
const stopUseTrigger = stopUseTriggers.every((trigger) => trigger);
|
|
23
|
+
if (stopUseTrigger) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const searchFile = config.vitePluginSearchJsonTempOutput;
|
|
27
|
+
const searchFileRelative = path.relative(".", searchFile);
|
|
28
|
+
const searchFileExists = fs.existsSync(searchFileRelative);
|
|
29
|
+
const searchUseCacheExists = config.search.cache && searchFileExists;
|
|
30
|
+
const stopCacheTriggers = [searchUseCacheExists];
|
|
31
|
+
const stopCacheTrigger = stopCacheTriggers.every((cache) => cache);
|
|
32
|
+
if (stopCacheTrigger) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await emptyResolveDir(systemConfig.temp.html.outDir);
|
|
36
|
+
await Promise.all([
|
|
37
|
+
generateTempRoot(config, mdxConfig),
|
|
38
|
+
generateTempPages(config, mdxConfig)
|
|
39
|
+
]);
|
|
40
|
+
await Promise.all([
|
|
41
|
+
generateNoStyleTemp(systemConfig.temp.root.outDir),
|
|
42
|
+
generateNoStyleTemp(systemConfig.temp.pages.outDir)
|
|
43
|
+
]);
|
|
44
|
+
await generateHtmlPages(config, systemConfig.temp.html.outDir, false);
|
|
45
|
+
const searchEntryPoints = await getFilterFilePaths({
|
|
46
|
+
targetDir: systemConfig.temp.html.outDir,
|
|
47
|
+
include: config.search.include,
|
|
48
|
+
exclude: config.search.exclude,
|
|
49
|
+
exts: "html"
|
|
50
|
+
});
|
|
51
|
+
await buildSearchJson({
|
|
52
|
+
config,
|
|
53
|
+
useCacheExists: searchUseCacheExists,
|
|
54
|
+
entryPoints: searchEntryPoints,
|
|
55
|
+
entryBase: systemConfig.temp.html.outDir,
|
|
56
|
+
outFile: searchFile,
|
|
57
|
+
showLog: false
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
8
61
|
export {
|
|
9
|
-
createDevServer
|
|
62
|
+
createDevServer,
|
|
63
|
+
createDevServerAssets
|
|
10
64
|
};
|
package/dist/system.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -78,6 +78,24 @@ export declare type MinistaConfig = {
|
|
|
78
78
|
highlightOptions: HighlightOptions;
|
|
79
79
|
mdxOptions: MdxOptions;
|
|
80
80
|
};
|
|
81
|
+
search: {
|
|
82
|
+
useJson: boolean;
|
|
83
|
+
cache: boolean;
|
|
84
|
+
outDir: string;
|
|
85
|
+
outName: string;
|
|
86
|
+
include: string[];
|
|
87
|
+
exclude: string[];
|
|
88
|
+
trimTitle: string;
|
|
89
|
+
targetSelector: string;
|
|
90
|
+
hit: {
|
|
91
|
+
minLength: number;
|
|
92
|
+
number: boolean;
|
|
93
|
+
english: boolean;
|
|
94
|
+
hiragana: boolean;
|
|
95
|
+
katakana: boolean;
|
|
96
|
+
kanji: boolean;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
81
99
|
beautify: {
|
|
82
100
|
useHtml: boolean;
|
|
83
101
|
useAssets: boolean;
|
|
@@ -157,6 +175,24 @@ export declare type MinistaUserConfig = {
|
|
|
157
175
|
highlightOptions?: HighlightOptions;
|
|
158
176
|
mdxOptions?: MdxOptions;
|
|
159
177
|
};
|
|
178
|
+
search?: {
|
|
179
|
+
useJson?: boolean;
|
|
180
|
+
cache?: boolean;
|
|
181
|
+
outDir?: string;
|
|
182
|
+
outName?: string;
|
|
183
|
+
include?: string[];
|
|
184
|
+
exclude?: string[];
|
|
185
|
+
trimTitle?: string;
|
|
186
|
+
targetSelector?: string;
|
|
187
|
+
hit?: {
|
|
188
|
+
minLength?: number;
|
|
189
|
+
number?: boolean;
|
|
190
|
+
english?: boolean;
|
|
191
|
+
hiragana?: boolean;
|
|
192
|
+
katakana?: boolean;
|
|
193
|
+
kanji?: boolean;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
160
196
|
beautify?: {
|
|
161
197
|
useHtml?: boolean;
|
|
162
198
|
useAssets?: boolean;
|
|
@@ -178,12 +214,15 @@ export declare type MinistaResolvePathConfig = {
|
|
|
178
214
|
assetsOutHref: string;
|
|
179
215
|
downloadOutDir: string;
|
|
180
216
|
downloadOutHref: string;
|
|
217
|
+
searchJsonOutput: string;
|
|
181
218
|
viteAssetsOutput: string;
|
|
182
219
|
viteAssetsImagesOutput: string;
|
|
183
220
|
viteAssetsFontsOutput: string;
|
|
184
221
|
vitePluginSvgSpriteIconsSrcDir: string;
|
|
185
222
|
vitePluginSvgSpriteIconsOutput: string;
|
|
186
223
|
vitePluginSvgSpriteIconsTempOutput: string;
|
|
224
|
+
vitePluginSearchJsonOutput: string;
|
|
225
|
+
vitePluginSearchJsonTempOutput: string;
|
|
187
226
|
};
|
|
188
227
|
export declare type MinistaSystemConfig = {
|
|
189
228
|
temp: {
|
|
@@ -209,6 +248,12 @@ export declare type MinistaSystemConfig = {
|
|
|
209
248
|
icons: {
|
|
210
249
|
outDir: string;
|
|
211
250
|
};
|
|
251
|
+
html: {
|
|
252
|
+
outDir: string;
|
|
253
|
+
};
|
|
254
|
+
search: {
|
|
255
|
+
outDir: string;
|
|
256
|
+
};
|
|
212
257
|
};
|
|
213
258
|
};
|
|
214
259
|
export declare type MinistaCliDevOptions = {
|
package/dist/vite.js
CHANGED
|
@@ -108,6 +108,13 @@ async function getViteConfig(config, mdxConfig, cliOptions) {
|
|
|
108
108
|
mergedViteConfig.plugins.push(iconsPlugin);
|
|
109
109
|
mergedViteConfig.resolve.alias.push(iconsResolveAlias);
|
|
110
110
|
}
|
|
111
|
+
if (config.search.useJson) {
|
|
112
|
+
const searchResolveAlias = {
|
|
113
|
+
find: config.vitePluginSearchJsonOutput,
|
|
114
|
+
replacement: path.resolve(config.vitePluginSearchJsonTempOutput)
|
|
115
|
+
};
|
|
116
|
+
mergedViteConfig.resolve.alias.push(searchResolveAlias);
|
|
117
|
+
}
|
|
111
118
|
const mdxPlugin = mdx(mdxConfig);
|
|
112
119
|
mergedViteConfig.plugins.push(mdxPlugin);
|
|
113
120
|
return cliOptions ? mergeViteConfig(mergedViteConfig, { server: cliOptions }) : mergedViteConfig;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minista",
|
|
3
3
|
"description": "Next.js Like Development with 100% Static Generate",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.7.2",
|
|
5
5
|
"bin": {
|
|
6
6
|
"minista": "./bin/minista.js"
|
|
7
7
|
},
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"fs-extra": "^10.1.0",
|
|
98
98
|
"js-beautify": "^1.14.3",
|
|
99
99
|
"mime-types": "^2.1.35",
|
|
100
|
+
"mojigiri": "^0.3.0",
|
|
100
101
|
"node-fetch": "^3.2.5",
|
|
101
102
|
"node-html-parser": "^5.3.3",
|
|
102
103
|
"picocolors": "^1.0.0",
|