Skip to content

Commit b14c894

Browse files
Patch/sercurity update (#22)
* Add: Upgrade the package for security update * Fix: Fix the resolve image in Vite 5 * fix: for new ant menu cursor style * Update getImageUrl utility and add @types/throttle Refactored getImageUrl to simplify asset URL retrieval using import.meta.glob with 'query' and 'import' options. Added @types/throttle to devDependencies for improved type support. * Improve NavigationBar brand styling * Refine NavigationBar styling and menu logic Removes unnecessary margin from the brand image and disables the border under the first menu item. Also updates menu item selection logic to handle leading/trailing slashes in the pathname and removes the disabled state from the brand menu item. --------- Co-authored-by: 猴貓 <a102009102009@gmail.com>
1 parent c560651 commit b14c894

4 files changed

Lines changed: 1972 additions & 3338 deletions

File tree

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
"dependencies": {
1616
"@ant-design/icons": "^5.3.0",
1717
"@swc/core": "^1.4.8",
18-
"@swc/plugin-styled-components": "^1.5.119",
18+
"@swc/plugin-styled-components": "^12.0.1",
1919
"@types/i18next-browser-languagedetector": "^3.0.0",
2020
"@types/react-lazy-load-image-component": "^1.6.3",
2121
"antd": "^5.14.1",
2222
"axios": "^1.12.0",
2323
"i18next": "^23.9.0",
2424
"i18next-browser-languagedetector": "^7.2.0",
25+
"lodash": "^4.17.21",
2526
"react": "^18.2.0",
2627
"react-dom": "^18.2.0",
2728
"react-i18next": "^14.0.5",
@@ -31,20 +32,20 @@
3132
"react-share": "^5.1.0",
3233
"react-typed": "^2.0.12",
3334
"styled-components": "^6.1.8",
34-
"vite": "^5.4.21",
35+
"vite": "^6.4.1",
3536
"youtube-iframe": "^1.0.3"
3637
},
3738
"devDependencies": {
38-
"@childrentime/devcert": "^1.2.8",
3939
"@types/estree": "^1.0.5",
4040
"@types/node": "^20.11.19",
4141
"@types/react": "^18.2.55",
4242
"@types/react-dom": "^18.2.19",
4343
"@types/styled-components": "^5.1.34",
44+
"@types/throttle": "^1.0.5",
4445
"@typescript-eslint/eslint-plugin": "^6.21.0",
4546
"@typescript-eslint/parser": "^6.21.0",
46-
"@vitejs/plugin-react-swc": "^3.5.0",
47-
"critters": "^0.0.20",
47+
"@vitejs/plugin-react-swc": "^4.2.2",
48+
"critters": "^0.0.24",
4849
"eslint": "^8.56.0",
4950
"eslint-config-prettier": "^9.1.0",
5051
"eslint-plugin-prettier": "^5.1.3",
@@ -63,6 +64,6 @@
6364
"typescript": "^5.2.2",
6465
"vite-plugin-compression": "^0.5.1",
6566
"vite-plugin-image-optimizer": "^1.1.7",
66-
"vite-react-ssg": "^0.6.0"
67+
"vite-react-ssg": "^0.8.9"
6768
}
6869
}

src/components/common/NavigationBar.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const NavigationBarContainer = styled.div<{
3737

3838
const Brand = styled.img`
3939
height: 40px;
40-
margin-right: 20px;
4140
4241
@media (max-width: 290px) {
4342
display: none;
@@ -63,6 +62,11 @@ const StyledMenu = styled(Menu)`
6362
color: #b1dde6;
6463
}
6564
}
65+
66+
/* brand */
67+
.ant-menu-item:first-child::after {
68+
border-bottom: none !important;
69+
}
6670
`;
6771

6872
/**
@@ -105,7 +109,6 @@ const NavigationBar: React.FC = () => {
105109
<Brand src='/brand.webp' alt='brand' />
106110
</Link>
107111
),
108-
disabled: true,
109112
},
110113
{
111114
key: 'home',
@@ -174,7 +177,9 @@ const NavigationBar: React.FC = () => {
174177
mode='horizontal'
175178
items={[...menuItems]}
176179
selectedKeys={
177-
location.pathname === '/' ? ['home'] : [location.pathname.slice(1)]
180+
location.pathname === '/'
181+
? ['home']
182+
: [location.pathname.replace(/^\/+|\/+$/g, '')]
178183
}
179184
/>
180185
</NavigationBarContainer>

src/utils/getImageUrl.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
const images = import.meta.glob('/src/assets/**/*', {
2+
query: '?url',
3+
eager: true,
4+
import: 'default',
5+
});
6+
17
/**
28
* Get the URL of an image in the assets folder
39
* @param snippet {string} - The snippet of the image URL
410
*/
511
const getImageUrl = (snippet: string) => {
6-
return new URL(`/src/assets/${snippet}`, import.meta.url).href;
12+
return images[`/src/assets/${snippet}`] ?? '';
713
};
814

915
export default getImageUrl;

0 commit comments

Comments
 (0)