mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update memo resource url
This commit is contained in:
@@ -47,6 +47,7 @@ func (v Visibility) String() string {
|
|||||||
|
|
||||||
type Memo struct {
|
type Memo struct {
|
||||||
ID int32 `json:"id"`
|
ID int32 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
// Standard fields
|
// Standard fields
|
||||||
RowStatus RowStatus `json:"rowStatus"`
|
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) {
|
func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Memo) (*Memo, error) {
|
||||||
memoMessage := &Memo{
|
memoMessage := &Memo{
|
||||||
ID: memo.ID,
|
ID: memo.ID,
|
||||||
|
Name: memo.ResourceName,
|
||||||
RowStatus: RowStatus(memo.RowStatus.String()),
|
RowStatus: RowStatus(memo.RowStatus.String()),
|
||||||
CreatorID: memo.CreatorID,
|
CreatorID: memo.CreatorID,
|
||||||
CreatedTs: memo.CreatedTs,
|
CreatedTs: memo.CreatedTs,
|
||||||
|
@@ -3,7 +3,6 @@ package v1
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -127,10 +126,9 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
|
|||||||
}
|
}
|
||||||
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/" + memoMessage.Name},
|
||||||
Description: description,
|
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"},
|
|
||||||
}
|
}
|
||||||
if len(memoMessage.ResourceList) > 0 {
|
if len(memoMessage.ResourceList) > 0 {
|
||||||
resource := memoMessage.ResourceList[0]
|
resource := memoMessage.ResourceList[0]
|
||||||
|
@@ -43,7 +43,7 @@ func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
|
|||||||
Root: "dist",
|
Root: "dist",
|
||||||
HTML5: true,
|
HTML5: true,
|
||||||
Skipper: func(c echo.Context) bool {
|
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) {
|
func (s *FrontendService) registerRoutes(e *echo.Echo) {
|
||||||
rawIndexHTML := getRawIndexHTML()
|
rawIndexHTML := getRawIndexHTML()
|
||||||
|
|
||||||
e.GET("/m/:memoID", func(c echo.Context) error {
|
e.GET("/m/:name", func(c echo.Context) error {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
memoID, err := util.ConvertStringToInt32(c.Param("memoID"))
|
resourceName := c.Param("name")
|
||||||
if err != nil {
|
|
||||||
// Redirect to `index.html` if any error occurs.
|
|
||||||
return c.HTML(http.StatusOK, rawIndexHTML)
|
|
||||||
}
|
|
||||||
|
|
||||||
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{
|
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{
|
||||||
ID: &memoID,
|
ResourceName: &resourceName,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.HTML(http.StatusOK, rawIndexHTML)
|
return c.HTML(http.StatusOK, rawIndexHTML)
|
||||||
@@ -116,7 +111,7 @@ Sitemap: %s/sitemap.xml`, instanceURL, instanceURL)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, memo := range memoList {
|
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"))
|
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))
|
return c.XMLBlob(http.StatusOK, []byte(sitemap))
|
||||||
|
Reference in New Issue
Block a user