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
e0290b94
Commit
e0290b94
authored
Dec 14, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: use gomark in rss api
parent
242f64fa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
12 deletions
+15
-12
rss.go
api/v1/rss.go
+15
-9
go.mod
go.mod
+0
-1
go.sum
go.sum
+0
-2
No files found.
api/v1/rss.go
View file @
e0290b94
package
v1
package
v1
import
(
import
(
"bytes"
"context"
"context"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
...
@@ -12,9 +11,11 @@ import (
...
@@ -12,9 +11,11 @@ import (
"github.com/gorilla/feeds"
"github.com/gorilla/feeds"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
"github.com/yuin/goldmark"
"github.com/usememos/memos/internal/util"
"github.com/usememos/memos/internal/util"
"github.com/usememos/memos/plugin/gomark/parser"
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
"github.com/usememos/memos/plugin/gomark/render/html"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
...
@@ -117,10 +118,14 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
...
@@ -117,10 +118,14 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
description
,
err
:=
getRSSItemDescription
(
memoMessage
.
Content
)
if
err
!=
nil
{
return
""
,
err
}
feed
.
Items
[
i
]
=
&
feeds
.
Item
{
feed
.
Items
[
i
]
=
&
feeds
.
Item
{
Title
:
getRSSItemTitle
(
memoMessage
.
Content
),
Title
:
getRSSItemTitle
(
memoMessage
.
Content
),
Link
:
&
feeds
.
Link
{
Href
:
baseURL
+
"/m/"
+
fmt
.
Sprintf
(
"%d"
,
memoMessage
.
ID
)},
Link
:
&
feeds
.
Link
{
Href
:
baseURL
+
"/m/"
+
fmt
.
Sprintf
(
"%d"
,
memoMessage
.
ID
)},
Description
:
getRSSItemDescription
(
memoMessage
.
Content
)
,
Description
:
description
,
Created
:
time
.
Unix
(
memoMessage
.
CreatedTs
,
0
),
Created
:
time
.
Unix
(
memoMessage
.
CreatedTs
,
0
),
Enclosure
:
&
feeds
.
Enclosure
{
Url
:
baseURL
+
"/m/"
+
fmt
.
Sprintf
(
"%d"
,
memoMessage
.
ID
)
+
"/image"
},
Enclosure
:
&
feeds
.
Enclosure
{
Url
:
baseURL
+
"/m/"
+
fmt
.
Sprintf
(
"%d"
,
memoMessage
.
ID
)
+
"/image"
},
}
}
...
@@ -182,7 +187,7 @@ func getRSSItemTitle(content string) string {
...
@@ -182,7 +187,7 @@ func getRSSItemTitle(content string) string {
return
title
return
title
}
}
func
getRSSItemDescription
(
content
string
)
string
{
func
getRSSItemDescription
(
content
string
)
(
string
,
error
)
{
var
description
string
var
description
string
if
isTitleDefined
(
content
)
{
if
isTitleDefined
(
content
)
{
var
firstLineEnd
=
strings
.
Index
(
content
,
"
\n
"
)
var
firstLineEnd
=
strings
.
Index
(
content
,
"
\n
"
)
...
@@ -191,12 +196,13 @@ func getRSSItemDescription(content string) string {
...
@@ -191,12 +196,13 @@ func getRSSItemDescription(content string) string {
description
=
content
description
=
content
}
}
// TODO: use our `./plugin/gomark` parser to handle markdown-like content.
tokens
:=
tokenizer
.
Tokenize
(
description
)
var
buf
bytes
.
Buffer
nodes
,
err
:=
parser
.
Parse
(
tokens
)
if
err
:=
goldmark
.
Convert
([]
byte
(
description
),
&
buf
);
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
return
""
,
err
}
}
return
buf
.
String
()
result
:=
html
.
NewHTMLRender
()
.
Render
(
nodes
)
return
result
,
nil
}
}
func
isTitleDefined
(
content
string
)
bool
{
func
isTitleDefined
(
content
string
)
bool
{
...
...
go.mod
View file @
e0290b94
...
@@ -25,7 +25,6 @@ require (
...
@@ -25,7 +25,6 @@ require (
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.8.4
github.com/swaggo/echo-swagger v1.4.1
github.com/swaggo/echo-swagger v1.4.1
github.com/swaggo/swag v1.16.2
github.com/swaggo/swag v1.16.2
github.com/yuin/goldmark v1.6.0
go.uber.org/zap v1.26.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.16.0
golang.org/x/crypto v0.16.0
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
...
...
go.sum
View file @
e0290b94
...
@@ -486,8 +486,6 @@ github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQ
...
@@ -486,8 +486,6 @@ github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQ
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68=
github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
...
...
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