Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
57c00734
Commit
57c00734
authored
Nov 05, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: frontend build
parent
e25792be
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
21 deletions
+32
-21
frontend.go
server/router/frontend/frontend.go
+11
-11
MermaidBlock.tsx
web/src/components/MemoContent/MermaidBlock.tsx
+12
-10
vite.config.ts
web/vite.config.ts
+9
-0
No files found.
server/router/frontend/frontend.go
View file @
57c00734
...
...
@@ -14,7 +14,7 @@ import (
"github.com/usememos/memos/store"
)
//go:embed dist
//go:embed dist
/*
var
embeddedFiles
embed
.
FS
type
FrontendService
struct
{
...
...
@@ -34,16 +34,8 @@ func (*FrontendService) Serve(_ context.Context, e *echo.Echo) {
return
util
.
HasPrefixes
(
c
.
Path
(),
"/api"
,
"/memos.api.v1"
)
}
// Use echo static middleware to serve the built dist folder.
// Reference: https://github.com/labstack/echo/blob/master/middleware/static.go
e
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
HTML5
:
true
,
Filesystem
:
getFileSystem
(
"dist"
),
Skipper
:
skipper
,
}))
// Use echo gzip middleware to compress the response.
// Reference: https://echo.labstack.com/docs/middleware/gzip
e
.
Group
(
"assets"
)
.
Use
(
middleware
.
GzipWithConfig
(
middleware
.
GzipConfig
{
// Route to serve the assets folder without HTML5 fallback.
e
.
Group
(
"/assets"
)
.
Use
(
middleware
.
GzipWithConfig
(
middleware
.
GzipConfig
{
Level
:
5
,
}),
func
(
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
return
func
(
c
echo
.
Context
)
error
{
...
...
@@ -52,6 +44,14 @@ func (*FrontendService) Serve(_ context.Context, e *echo.Echo) {
}
},
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
Filesystem
:
getFileSystem
(
"dist/assets"
),
HTML5
:
false
,
// Disable fallback to index.html
}))
// Route to serve the main app with HTML5 fallback for SPA behavior.
e
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
Filesystem
:
getFileSystem
(
"dist"
),
HTML5
:
true
,
// Enable fallback to index.html
Skipper
:
skipper
,
}))
}
...
...
web/src/components/MemoContent/MermaidBlock.tsx
View file @
57c00734
import
mermaid
from
"mermaid"
;
import
{
useEffect
,
useRef
}
from
"react"
;
interface
Props
{
...
...
@@ -7,18 +6,21 @@ interface Props {
const
MermaidBlock
:
React
.
FC
<
Props
>
=
({
content
}:
Props
)
=>
{
const
mermaidDockBlock
=
useRef
<
null
>
(
null
);
mermaid
.
initialize
({
startOnLoad
:
false
,
theme
:
"default"
});
useEffect
(()
=>
{
if
(
!
mermaidDockBlock
.
current
)
{
return
;
}
// Render mermaid when mounted.
// Dynamically import mermaid to ensure compatibility with Vite
const
initializeMermaid
=
async
()
=>
{
const
mermaid
=
(
await
import
(
"mermaid"
)).
default
;
mermaid
.
initialize
({
startOnLoad
:
false
,
theme
:
"default"
});
if
(
mermaidDockBlock
.
current
)
{
mermaid
.
run
({
nodes
:
[
mermaidDockBlock
.
current
],
});
});
}
};
initializeMermaid
();
},
[
content
]);
return
(
<
pre
ref=
{
mermaidDockBlock
}
className=
"w-full p-2 whitespace-pre-wrap relative"
>
...
...
web/vite.config.ts
View file @
57c00734
...
...
@@ -34,4 +34,13 @@ export default defineConfig({
"@/"
:
`
${
resolve
(
__dirname
,
"src"
)}
/`
,
},
},
build
:
{
rollupOptions
:
{
output
:
{
entryFileNames
:
"app.[hash].js"
,
chunkFileNames
:
"assets/chunk-vendors.[hash].js"
,
assetFileNames
:
"assets/[name].[hash][extname]"
,
},
},
},
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment