mirror of
https://github.com/usememos/memos.git
synced 2025-02-11 08:50:40 +01:00
chore: update memo resource url
This commit is contained in:
parent
55ecdae509
commit
f4ac7ff529
@ -46,7 +46,8 @@ func (v Visibility) String() string {
|
||||
}
|
||||
|
||||
type Memo struct {
|
||||
ID int32 `json:"id"`
|
||||
ID int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
// Standard fields
|
||||
RowStatus RowStatus `json:"rowStatus"`
|
||||
@ -832,6 +833,7 @@ func (s *APIV1Service) UpdateMemo(c echo.Context) error {
|
||||
func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Memo) (*Memo, error) {
|
||||
memoMessage := &Memo{
|
||||
ID: memo.ID,
|
||||
Name: memo.ResourceName,
|
||||
RowStatus: RowStatus(memo.RowStatus.String()),
|
||||
CreatorID: memo.CreatorID,
|
||||
CreatedTs: memo.CreatedTs,
|
||||
|
@ -3,7 +3,6 @@ package v1
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -127,10 +126,9 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
|
||||
}
|
||||
feed.Items[i] = &feeds.Item{
|
||||
Title: getRSSItemTitle(memoMessage.Content),
|
||||
Link: &feeds.Link{Href: baseURL + "/m/" + fmt.Sprintf("%d", memoMessage.ID)},
|
||||
Link: &feeds.Link{Href: baseURL + "/m/" + memoMessage.Name},
|
||||
Description: description,
|
||||
Created: time.Unix(memoMessage.CreatedTs, 0),
|
||||
Enclosure: &feeds.Enclosure{Url: baseURL + "/m/" + fmt.Sprintf("%d", memoMessage.ID) + "/image"},
|
||||
}
|
||||
if len(memoMessage.ResourceList) > 0 {
|
||||
resource := memoMessage.ResourceList[0]
|
||||
|
@ -43,7 +43,7 @@ func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
|
||||
Root: "dist",
|
||||
HTML5: true,
|
||||
Skipper: func(c echo.Context) bool {
|
||||
return util.HasPrefixes(c.Path(), "/api", "/memos.api.v2", "/robots.txt", "/sitemap.xml", "/m/:memoID")
|
||||
return util.HasPrefixes(c.Path(), "/api", "/memos.api.v2", "/robots.txt", "/sitemap.xml", "/m/:name")
|
||||
},
|
||||
}))
|
||||
|
||||
@ -54,16 +54,11 @@ func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
|
||||
func (s *FrontendService) registerRoutes(e *echo.Echo) {
|
||||
rawIndexHTML := getRawIndexHTML()
|
||||
|
||||
e.GET("/m/:memoID", func(c echo.Context) error {
|
||||
e.GET("/m/:name", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoID"))
|
||||
if err != nil {
|
||||
// Redirect to `index.html` if any error occurs.
|
||||
return c.HTML(http.StatusOK, rawIndexHTML)
|
||||
}
|
||||
|
||||
resourceName := c.Param("name")
|
||||
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{
|
||||
ID: &memoID,
|
||||
ResourceName: &resourceName,
|
||||
})
|
||||
if err != nil {
|
||||
return c.HTML(http.StatusOK, rawIndexHTML)
|
||||
@ -116,7 +111,7 @@ Sitemap: %s/sitemap.xml`, instanceURL, instanceURL)
|
||||
return err
|
||||
}
|
||||
for _, memo := range memoList {
|
||||
urlsets = append(urlsets, fmt.Sprintf(`<url><loc>%s</loc></url>`, fmt.Sprintf("%s/m/%d", instanceURL, memo.ID)))
|
||||
urlsets = append(urlsets, fmt.Sprintf(`<url><loc>%s</loc></url>`, fmt.Sprintf("%s/m/%s", instanceURL, memo.ResourceName)))
|
||||
}
|
||||
sitemap := fmt.Sprintf(`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">%s</urlset>`, strings.Join(urlsets, "\n"))
|
||||
return c.XMLBlob(http.StatusOK, []byte(sitemap))
|
||||
|
Loading…
x
Reference in New Issue
Block a user