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
24672e0c
Commit
24672e0c
authored
Dec 15, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update memo metadata
parent
52743017
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
frontend.go
server/frontend/frontend.go
+17
-8
No files found.
server/frontend/frontend.go
View file @
24672e0c
...
...
@@ -67,35 +67,44 @@ func (s *FrontendService) registerRoutes(e *echo.Echo) {
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoID"
))
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"invalid memo id"
)
// Redirect to `index.html` if any error occurs.
return
c
.
HTML
(
http
.
StatusOK
,
rawIndexHTML
)
}
memo
,
err
:=
s
.
Store
.
GetMemo
(
ctx
,
&
store
.
FindMemo
{
ID
:
&
memoID
,
})
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"failed to retrieve memo"
)
return
c
.
HTML
(
http
.
StatusOK
,
rawIndexHTML
)
}
if
memo
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
"memo not found"
)
return
c
.
HTML
(
http
.
StatusOK
,
rawIndexHTML
)
}
if
memo
.
Visibility
!=
store
.
Public
{
return
echo
.
NewHTTPError
(
http
.
StatusForbidden
,
"memo is not public"
)
return
c
.
HTML
(
http
.
StatusOK
,
rawIndexHTML
)
}
indexHTML
:=
strings
.
ReplaceAll
(
rawIndexHTML
,
"<!-- memos.metadata -->"
,
generateMemoMetadata
(
memo
))
creator
,
err
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
ID
:
&
memo
.
CreatorID
,
})
if
err
!=
nil
{
return
c
.
HTML
(
http
.
StatusOK
,
rawIndexHTML
)
}
// Inject memo metadata into `index.html`.
indexHTML
:=
strings
.
ReplaceAll
(
rawIndexHTML
,
"<!-- memos.metadata -->"
,
generateMemoMetadata
(
memo
,
creator
))
return
c
.
HTML
(
http
.
StatusOK
,
indexHTML
)
})
}
func
generateMemoMetadata
(
memo
*
store
.
Memo
)
string
{
func
generateMemoMetadata
(
memo
*
store
.
Memo
,
creator
*
store
.
User
)
string
{
metadataList
:=
[]
string
{
fmt
.
Sprintf
(
`<meta name="description" content="%s" />`
,
memo
.
Content
),
fmt
.
Sprintf
(
`<meta property="og:title" content="%s" />`
,
fmt
.
Sprintf
(
"
Memos - %d"
,
memo
.
ID
)),
fmt
.
Sprintf
(
`<meta property="og:title" content="%s" />`
,
fmt
.
Sprintf
(
"
%s(@%s) on Memos"
,
creator
.
Nickname
,
creator
.
Username
)),
fmt
.
Sprintf
(
`<meta property="og:description" content="%s" />`
,
memo
.
Content
),
fmt
.
Sprintf
(
`<meta property="og:image" content="%s" />`
,
"https://www.usememos.com/logo.png"
),
`<meta property="og:type" content="website" />`
,
// Twitter related metadata.
fmt
.
Sprintf
(
`<meta name="twitter:title" content="%s" />`
,
fmt
.
Sprintf
(
"
Memos - %d"
,
memo
.
ID
)),
fmt
.
Sprintf
(
`<meta name="twitter:title" content="%s" />`
,
fmt
.
Sprintf
(
"
%s(@%s) on Memos"
,
creator
.
Nickname
,
creator
.
Username
)),
fmt
.
Sprintf
(
`<meta name="twitter:description" content="%s" />`
,
memo
.
Content
),
fmt
.
Sprintf
(
`<meta name="twitter:image" content="%s" />`
,
"https://www.usememos.com/logo.png"
),
`<meta name="twitter:card" content="summary" />`
,
...
...
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