jeawin-astro 3.0.4 → 3.0.6
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jeawin-astro",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"author": "chaegumi <chaegumi@qq.com>",
|
|
5
5
|
"description": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"test": "mocha test"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@babel/core": "^7.26.
|
|
29
|
-
"@babel/preset-env": "^7.26.
|
|
28
|
+
"@babel/core": "^7.26.9",
|
|
29
|
+
"@babel/preset-env": "^7.26.9",
|
|
30
30
|
"@rollup/plugin-babel": "^6.0.4",
|
|
31
31
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
32
32
|
"@rollup/plugin-json": "^6.1.0",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"@types/lodash": "^4.17.15",
|
|
39
39
|
"@types/sprintf-js": "^1.1.4",
|
|
40
40
|
"autoprefixer": "^10.4.20",
|
|
41
|
-
"chai": "^5.
|
|
41
|
+
"chai": "^5.2.0",
|
|
42
42
|
"mocha": "^10.8.2",
|
|
43
|
-
"postcss": "^8.5.
|
|
44
|
-
"rollup": "^4.34.
|
|
43
|
+
"postcss": "^8.5.2",
|
|
44
|
+
"rollup": "^4.34.8",
|
|
45
45
|
"rollup-plugin-node-externals": "^7.1.3",
|
|
46
46
|
"rollup-plugin-postcss": "^4.0.2",
|
|
47
47
|
"typescript": "^5.7.3"
|
|
@@ -58,13 +58,14 @@
|
|
|
58
58
|
"@iconify-json/fa6-solid": "^1.2.3",
|
|
59
59
|
"@iconify/tools": "^4.1.1",
|
|
60
60
|
"@keyv/compress-brotli": "^2.0.3",
|
|
61
|
+
"@pagefind/default-ui": "^1.3.0",
|
|
61
62
|
"@tailwindcss/forms": "^0.5.10",
|
|
62
63
|
"@tailwindcss/typography": "^0.5.16",
|
|
63
|
-
"@tailwindcss/vite": "^4.0.
|
|
64
|
+
"@tailwindcss/vite": "^4.0.6",
|
|
64
65
|
"@types/alpinejs": "^3.13.11",
|
|
65
66
|
"alpinejs": "^3.14.8",
|
|
66
67
|
"aos": "3.0.0-beta.6",
|
|
67
|
-
"astro": "^5.
|
|
68
|
+
"astro": "^5.3.0",
|
|
68
69
|
"astro-color-scheme": "^1.1.5",
|
|
69
70
|
"astro-embed": "^0.9.0",
|
|
70
71
|
"astro-icon": "^1.1.5",
|
|
@@ -77,13 +78,15 @@
|
|
|
77
78
|
"keyv": "^5.2.3",
|
|
78
79
|
"keyv-lru": "^3.0.4",
|
|
79
80
|
"lodash": "^4.17.21",
|
|
81
|
+
"pagefind": "^1.3.0",
|
|
80
82
|
"photoswipe": "^5.4.4",
|
|
83
|
+
"sirv": "^3.0.1",
|
|
81
84
|
"smartmenus": "2.0.0-alpha.1",
|
|
82
85
|
"sprintf-js": "^1.1.3",
|
|
83
86
|
"string-strip-html": "^13.4.8",
|
|
84
|
-
"swiper": "^11.2.
|
|
87
|
+
"swiper": "^11.2.4",
|
|
85
88
|
"tailwind-scrollbar": "^4.0.0",
|
|
86
|
-
"tailwindcss": "^4.0.
|
|
89
|
+
"tailwindcss": "^4.0.6",
|
|
87
90
|
"tslib": "^2.8.1"
|
|
88
91
|
}
|
|
89
92
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -38,6 +38,7 @@ export {default as RelNodesList} from "./rel_nodes_list.astro";
|
|
|
38
38
|
export {default as RemoteImage} from "./remote_image.astro";
|
|
39
39
|
export {default as SearchInput} from "./search_input.astro";
|
|
40
40
|
export {default as SearchResult} from "./search_result.astro";
|
|
41
|
+
export {default as SearchPagefind} from "./search_pagefind.astro";
|
|
41
42
|
export {default as SectionContainer} from "./section_container.astro";
|
|
42
43
|
export {default as ShareButton} from "./share_button.astro";
|
|
43
44
|
export {default as SidebarSub} from "./sidebar_sub.astro";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
import "@pagefind/default-ui/css/ui.css";
|
|
3
|
+
|
|
4
|
+
export interface Props {
|
|
5
|
+
readonly id?: string;
|
|
6
|
+
readonly className?: string;
|
|
7
|
+
readonly query?: string;
|
|
8
|
+
readonly uiOptions?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const { id, className, query, uiOptions = {} } = Astro.props;
|
|
12
|
+
const bundlePath = `${import.meta.env.BASE_URL}pagefind/`;
|
|
13
|
+
---
|
|
14
|
+
<section class="py-12">
|
|
15
|
+
<div class="max-w-screen-lg mx-auto">
|
|
16
|
+
<div class="px-4">
|
|
17
|
+
<div
|
|
18
|
+
id={id}
|
|
19
|
+
class:list={[className, "pagefind-init"]}
|
|
20
|
+
data-pagefind-ui
|
|
21
|
+
data-bundle-path={bundlePath}
|
|
22
|
+
data-query={query}
|
|
23
|
+
data-ui-options={JSON.stringify(uiOptions)}
|
|
24
|
+
>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
</section>
|
|
29
|
+
<script>
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
import { PagefindUI } from "@pagefind/default-ui";
|
|
32
|
+
|
|
33
|
+
function initPageFind() {
|
|
34
|
+
const allSelector = "[data-pagefind-ui]";
|
|
35
|
+
for (const el of document.querySelectorAll(`${allSelector}.pagefind-init`)) {
|
|
36
|
+
const elSelector = [
|
|
37
|
+
...(el.id ? [`#${el.id}`] : []),
|
|
38
|
+
...[...el.classList.values()].map((c) => `.${c}`),
|
|
39
|
+
allSelector,
|
|
40
|
+
].join("");
|
|
41
|
+
const bundlePath = el.getAttribute("data-bundle-path");
|
|
42
|
+
const opts = JSON.parse(el.getAttribute("data-ui-options") ?? "{}");
|
|
43
|
+
new PagefindUI({
|
|
44
|
+
...opts,
|
|
45
|
+
element: elSelector,
|
|
46
|
+
bundlePath,
|
|
47
|
+
});
|
|
48
|
+
el.classList.remove("pagefind-init");
|
|
49
|
+
let query = el.getAttribute("data-query");
|
|
50
|
+
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
51
|
+
const params = Object.fromEntries(urlSearchParams.entries());
|
|
52
|
+
if(params.q){
|
|
53
|
+
query = params.q;
|
|
54
|
+
}
|
|
55
|
+
if (query) {
|
|
56
|
+
const input = el.querySelector<HTMLInputElement>(`input[type="text"]`);
|
|
57
|
+
if (input) {
|
|
58
|
+
input.value = query;
|
|
59
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
document.addEventListener("astro:page-load", initPageFind);
|
|
66
|
+
if (document.readyState === "loading") {
|
|
67
|
+
document.addEventListener("DOMContentLoaded", initPageFind);
|
|
68
|
+
} else {
|
|
69
|
+
initPageFind();
|
|
70
|
+
}
|
|
71
|
+
</script>
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {default as jeawinRuntimeConfig} from "./jeawin-runtime-config/index.ts";
|
|
1
|
+
export {default as jeawinRuntimeConfig} from "./jeawin-runtime-config/index.ts";
|
|
2
|
+
export {default as jeawinAstroPagefind} from "./jeawin-astro-pagefind/index.ts";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { AstroIntegration } from "astro";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createIndex, type PagefindServiceConfig } from "pagefind";
|
|
5
|
+
import sirv from "sirv";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pagefind Astro integration options.
|
|
9
|
+
*/
|
|
10
|
+
export interface PagefindOptions {
|
|
11
|
+
/**
|
|
12
|
+
* `PagefindServiceConfig` passed to pagefind's `createIndex`
|
|
13
|
+
*/
|
|
14
|
+
indexConfig?: PagefindServiceConfig;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default function pagefind({ indexConfig }: PagefindOptions = {}): AstroIntegration {
|
|
18
|
+
let outDir: string;
|
|
19
|
+
return {
|
|
20
|
+
name: "pagefind",
|
|
21
|
+
hooks: {
|
|
22
|
+
"astro:config:setup": ({ config, logger }: any) => {
|
|
23
|
+
if (config?.output === "server") {
|
|
24
|
+
logger.warn(
|
|
25
|
+
"Output type `server` does not produce static *.html pages in its output and thus will not work with astro-pagefind integration.",
|
|
26
|
+
);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (config.adapter?.name === "@astrojs/cloudflare") {
|
|
31
|
+
outDir = fileURLToPath(new URL(config.base?.replace(/^\//, ""), config.outDir));
|
|
32
|
+
} else if (config.adapter?.name === "@astrojs/node") {
|
|
33
|
+
outDir = fileURLToPath(config.build.client);
|
|
34
|
+
} else {
|
|
35
|
+
outDir = fileURLToPath(config.outDir);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"astro:server:setup": ({ server, logger }) => {
|
|
39
|
+
if (!outDir) {
|
|
40
|
+
logger.warn(
|
|
41
|
+
"astro-pagefind couldn't reliably determine the output directory. Search assets will not be served.",
|
|
42
|
+
);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const serve = sirv(outDir, {
|
|
47
|
+
dev: true,
|
|
48
|
+
etag: true,
|
|
49
|
+
});
|
|
50
|
+
server.middlewares.use((req, res, next) => {
|
|
51
|
+
if (req.url?.startsWith("/pagefind/")) {
|
|
52
|
+
serve(req, res, next);
|
|
53
|
+
} else {
|
|
54
|
+
next();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
"astro:build:done": async ({ logger }) => {
|
|
59
|
+
if (!outDir) {
|
|
60
|
+
logger.warn(
|
|
61
|
+
"astro-pagefind couldn't reliably determine the output directory. Search index will not be built.",
|
|
62
|
+
);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const { index, errors: createErrors } = await createIndex(indexConfig);
|
|
67
|
+
if (!index) {
|
|
68
|
+
logger.error("Pagefind failed to create index");
|
|
69
|
+
createErrors.forEach((e) => logger.error(e));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const { page_count, errors: addErrors } = await index.addDirectory({ path: outDir });
|
|
73
|
+
if (addErrors.length) {
|
|
74
|
+
logger.error("Pagefind failed to index files");
|
|
75
|
+
addErrors.forEach((e) => logger.error(e));
|
|
76
|
+
return;
|
|
77
|
+
} else {
|
|
78
|
+
logger.info(`Pagefind indexed ${page_count} pages`);
|
|
79
|
+
}
|
|
80
|
+
const { outputPath, errors: writeErrors } = await index.writeFiles({
|
|
81
|
+
outputPath: path.join(outDir, "pagefind"),
|
|
82
|
+
});
|
|
83
|
+
if (writeErrors.length) {
|
|
84
|
+
logger.error("Pagefind failed to write index");
|
|
85
|
+
writeErrors.forEach((e) => logger.error(e));
|
|
86
|
+
return;
|
|
87
|
+
} else {
|
|
88
|
+
logger.info(`Pagefind wrote index to ${outputPath}`);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
package/src/scripts/consts.js
CHANGED
|
@@ -2,7 +2,7 @@ export const ICONS_INCLUDE = {
|
|
|
2
2
|
'fa6-solid': ['magnifying-glass', 'clock', 'eye', 'envelope', 'phone', 'angle-right', 'angle-left', 'angle-up', 'angle-down', 'arrow-right',
|
|
3
3
|
'arrow-left', 'arrow-up', 'arrow-down', 'house', 'message', 'circle-question', 'xmark', 'video', 'download',
|
|
4
4
|
'file-pdf', 'file-csv', 'file-image', 'file-word', 'file-video', 'file-powerpoint', 'file-excel',
|
|
5
|
-
'file-code', 'file-audio', 'file', 'file-zipper', 'sun', 'moon'],
|
|
5
|
+
'file-code', 'file-audio', 'file', 'file-zipper', 'sun', 'moon', 'up-right-from-square'],
|
|
6
6
|
'fa6-brands': ['x-twitter', 'facebook', 'youtube', 'tiktok', 'linkedin',
|
|
7
7
|
'google-plus', 'flickr', 'pinterest', 'whatsapp', 'instagram', 'qq', 'weixin', 'weibo', 'bilibili', 'zhihu']
|
|
8
8
|
};
|