Yansen преди 1 година
родител
ревизия
9b0a679375
променени са 6 файла, в които са добавени 38 реда и са изтрити 16 реда
  1. 3
    3
      src/components/NavMenu/index.jsx
  2. 1
    1
      src/components/NavMenu/style.less
  3. 0
    0
      src/data/zh/homepage.js
  4. 0
    0
      src/data/zh/menu.js
  5. 32
    10
      src/middleware.js
  6. 2
    2
      src/pages/[lang]/index.astro

+ 3
- 3
src/components/NavMenu/index.jsx Целия файл

@@ -31,10 +31,10 @@ export default function NavMenu (props) {
31 31
   }, [])
32 32
 
33 33
   return (
34
-    <Fragment>
34
+    <div ref={elementRef}>
35 35
       <nav
36 36
         id="pageNav"
37
-        ref={elementRef}
37
+        
38 38
         className="navbar navbar-expand-lg navbar-light bg-light fixed-top p-0"
39 39
         style={{ '--bs-bg-opacity': 0.9 }}
40 40
       >
@@ -93,6 +93,6 @@ export default function NavMenu (props) {
93 93
         menus={current?.children}
94 94
         onShowChange={setShow}
95 95
       />
96
-    </Fragment>
96
+    </div>
97 97
   );
98 98
 }

+ 1
- 1
src/components/NavMenu/style.less Целия файл

@@ -1,7 +1,7 @@
1 1
 
2 2
 #sub-menu {
3 3
   visibility: hidden;
4
-  position: absolute;
4
+  position: fixed;
5 5
   max-height: 0;
6 6
   left: 0;
7 7
   opacity: 0;

src/data/homepage.js → src/data/zh/homepage.js Целия файл


src/data/menu.js → src/data/zh/menu.js Целия файл


+ 32
- 10
src/middleware.js Целия файл

@@ -1,14 +1,36 @@
1
-// import { sequence } from "astro:middleware";
2
-// // import { getCategary } from "./services/apis";
3
-// import menus from './data/menu';
1
+import { sequence } from "astro:middleware";
4 2
 
5
-// async function getGloalData(context, next) {
6
-//   // const menus = await getCategary();
7
-//   context.locals._menus = menus;
3
+let globalData = null;
8 4
 
9
-//   context.data = { ...(context.data || {}), menus };
5
+function getKey(path) {
6
+  // 去掉 .js 后缀
7
+  const parts = path.replace(/\.js$/, '').split('/');
8
+  // 去掉 /data/zh/
9
+  return parts.slice(3).join('.');
10
+}
11
+
12
+async function impData() {
13
+  const data = await import.meta.glob('./data/zh/*.js');
14
+
15
+  Object.keys(data).forEach(async (key) => {
16
+    const dt = await data[key]();
17
+    globalData = {
18
+      ...(globalData || {}),
19
+      [getKey(key)]: dt.default,
20
+    }
21
+  });
22
+}
23
+
24
+async function getGloalData(context, next) {
25
+
26
+  if (!globalData) {
27
+    await impData();
28
+  }
29
+
30
+  context.locals.globalData = globalData;
31
+  console.log('globalData', globalData);
10 32
   
11
-//   return next();
12
-// }
33
+  return next();
34
+}
13 35
 
14
-// export const onRequest = sequence(getGloalData);
36
+export const onRequest = sequence(getGloalData);

+ 2
- 2
src/pages/[lang]/index.astro Целия файл

@@ -10,8 +10,8 @@ import LeftRightCarousel from '@/components/LeftRightCarousel.astro'
10 10
 import VerticalNavigationContent from '@/components/VerticalNavigationContent.astro'
11 11
 import LeftImgRightText from '@/components/LeftImgRightText.astro'
12 12
 import FooterMenu from '@/components/NavMenu/FooterMenu.jsx'
13
-import menus from '@/data/menu'
14
-import pageData from '@/data/homepage'
13
+import menus from '@/data/zh/menuenu'
14
+import pageData from '@/data/zh/homepageage'
15 15
 
16 16
 import Container from '@/components/Container.astro'
17 17
 import MediaCard from '@/components/MediaCard/MediaCard1.astro'