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
4cd01ece
Commit
4cd01ece
authored
Dec 29, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update frontend metadata
parent
14b34edc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
24 deletions
+40
-24
frontend.go
server/frontend/frontend.go
+39
-23
index.html
web/index.html
+1
-1
No files found.
server/frontend/frontend.go
View file @
4cd01ece
...
...
@@ -3,7 +3,6 @@ package frontend
import
(
"context"
"fmt"
"html/template"
"net/http"
"os"
"strings"
...
...
@@ -80,7 +79,7 @@ func (s *FrontendService) registerRoutes(e *echo.Echo) {
}
// Inject memo metadata into `index.html`.
indexHTML
:=
strings
.
ReplaceAll
(
rawIndexHTML
,
"<!-- memos.metadata -->"
,
generateMemoMetadata
(
memo
,
creator
))
indexHTML
:=
strings
.
ReplaceAll
(
rawIndexHTML
,
"<!-- memos.metadata -->"
,
generateMemoMetadata
(
memo
,
creator
)
.
String
()
)
return
c
.
HTML
(
http
.
StatusOK
,
indexHTML
)
})
}
...
...
@@ -123,40 +122,57 @@ Sitemap: %s/sitemap.xml`, instanceURL, instanceURL)
})
}
func
generateMemoMetadata
(
memo
*
store
.
Memo
,
creator
*
store
.
User
)
string
{
description
:=
""
if
memo
.
Visibility
==
store
.
Private
{
description
=
"This memo is private."
}
else
if
memo
.
Visibility
==
store
.
Protected
{
description
=
"This memo is protected."
}
else
{
func
generateMemoMetadata
(
memo
*
store
.
Memo
,
creator
*
store
.
User
)
*
Metadata
{
metadata
:=
getDefaultMetadata
()
metadata
.
Title
=
fmt
.
Sprintf
(
"%s(@%s) on Memos"
,
creator
.
Nickname
,
creator
.
Username
)
if
memo
.
Visibility
==
store
.
Public
{
tokens
:=
tokenizer
.
Tokenize
(
memo
.
Content
)
nodes
,
_
:=
parser
.
Parse
(
tokens
)
description
=
renderer
.
NewStringRenderer
()
.
Render
(
nodes
)
description
:
=
renderer
.
NewStringRenderer
()
.
Render
(
nodes
)
if
len
(
description
)
==
0
{
description
=
memo
.
Content
}
if
len
(
description
)
>
maxMetadataDescriptionLength
{
description
=
description
[
:
maxMetadataDescriptionLength
]
+
"..."
}
metadata
.
Description
=
description
}
metadataList
:=
[]
string
{
fmt
.
Sprintf
(
`<meta name="description" content="%s" />`
,
template
.
HTMLEscapeString
(
description
)),
fmt
.
Sprintf
(
`<meta property="og:title" content="%s" />`
,
template
.
HTMLEscapeString
(
fmt
.
Sprintf
(
"%s(@%s) on Memos"
,
creator
.
Nickname
,
creator
.
Username
))),
fmt
.
Sprintf
(
`<meta property="og:description" content="%s" />`
,
template
.
HTMLEscapeString
(
description
)),
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" />`
,
template
.
HTMLEscapeString
(
fmt
.
Sprintf
(
"%s(@%s) on Memos"
,
creator
.
Nickname
,
creator
.
Username
))),
fmt
.
Sprintf
(
`<meta name="twitter:description" content="%s" />`
,
template
.
HTMLEscapeString
(
description
)),
fmt
.
Sprintf
(
`<meta name="twitter:image" content="%s" />`
,
"https://www.usememos.com/logo.png"
),
`<meta name="twitter:card" content="summary" />`
,
}
return
strings
.
Join
(
metadataList
,
"
\n
"
)
return
metadata
}
func
getRawIndexHTML
()
string
{
bytes
,
_
:=
os
.
ReadFile
(
"dist/index.html"
)
return
string
(
bytes
)
}
type
Metadata
struct
{
Title
string
Description
string
ImageURL
string
}
func
getDefaultMetadata
()
*
Metadata
{
return
&
Metadata
{
Title
:
"Memos"
,
Description
:
"A privacy-first, lightweight note-taking service. Easily capture and share your great thoughts."
,
ImageURL
:
"https://www.usememos.com/logo.png"
,
}
}
func
(
m
*
Metadata
)
String
()
string
{
metadataList
:=
[]
string
{
fmt
.
Sprintf
(
`<meta name="description" content="%s" />`
,
m
.
Description
),
fmt
.
Sprintf
(
`<meta property="og:title" content="%s" />`
,
m
.
Title
),
fmt
.
Sprintf
(
`<meta property="og:description" content="%s" />`
,
m
.
Description
),
fmt
.
Sprintf
(
`<meta property="og:image" content="%s" />`
,
m
.
ImageURL
),
`<meta property="og:type" content="website" />`
,
// Twitter related fields.
fmt
.
Sprintf
(
`<meta property="twitter:title" content="%s" />`
,
m
.
Title
),
fmt
.
Sprintf
(
`<meta property="twitter:description" content="%s" />`
,
m
.
Description
),
fmt
.
Sprintf
(
`<meta property="twitter:image" content="%s" />`
,
m
.
ImageURL
),
`<meta name="twitter:card" content="summary" />`
,
`<meta name="twitter:creator" content="memos" />`
,
}
return
strings
.
Join
(
metadataList
,
"
\n
"
)
}
web/index.html
View file @
4cd01ece
...
...
@@ -6,8 +6,8 @@
<meta
name=
"theme-color"
media=
"(prefers-color-scheme: light)"
content=
"#f4f4f5"
/>
<meta
name=
"theme-color"
media=
"(prefers-color-scheme: dark)"
content=
"#27272a"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, user-scalable=no"
/>
<title>
Memos
</title>
<!-- memos.metadata -->
<title>
Memos
</title>
</head>
<body>
<div
id=
"root"
></div>
...
...
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