Skip to content

Commit

Permalink
Squashed 'memos-upstream/' changes from 0916ec35..749187e1
Browse files Browse the repository at this point in the history
749187e1 chore: update dockerfile
a9812592 chore: tweak editor border styles
e4070f77 chore: bump version
ff53187e chore: add sitemap and robots routes
89ef9b85 chore: add instance url system setting
56b55ad9 chore: update memo metadata
24672e0c chore: update memo metadata
52743017 chore: implement memo route
6cf7192d chore: add ssr placeholder in `index.html`
6763dab4 chore: handle newline in block parsers
e0290b94 chore: use gomark in rss api
242f64fa chore: implement html render
3edce174 chore: remove unused methods
5266a626 chore: implement html renderer
43ef9eac chore: implement part of html renderer
453707d1 feat: implement gomark parsers
2d9c5d16 chore: fix user string
b20e0097 chore: implement part of nodes
dd837825 chore: add line break node
aa3632e2 chore: implement gomark skeleton
7f1f6f77 chore: update i18n with weblate (#2614)
7eb5be0a chore: fix update user
603a6a49 chore: fix vacuum memo
6bda6406 fix: delete one memo will delete all memos on pgsql (#2611)
ec799255 chore: go mod update
e5de8c08 chore: clean debug code
c608877c chore: clean binary entries
52f399a1 chore: remove unused functions
88728906 fix(copydb): fix migration to Postgres (#2601)

git-subtree-dir: memos-upstream
git-subtree-split: 749187e1e9970377796a3eaf7c4ff89479dbeabb
  • Loading branch information
lincolnthalles committed Dec 15, 2023
1 parent 2b47e8d commit 91fecbe
Show file tree
Hide file tree
Showing 99 changed files with 2,100 additions and 2,058 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/frontend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
version: 8
- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "20"
cache: pnpm
cache-dependency-path: "web/pnpm-lock.yaml"
- run: pnpm install
Expand All @@ -40,7 +40,7 @@ jobs:
version: 8
- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "20"
cache: pnpm
cache-dependency-path: "web/pnpm-lock.yaml"
- run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tmp

# Frontend asset
web/dist
server/dist
server/frontend/dist

# build folder
build
Expand Down
6 changes: 6 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ linters-settings:
disabled: true
- name: early-return
disabled: true
- name: use-any
disabled: true
- name: exported
disabled: true
- name: unhandled-error
disabled: true
gocritic:
disabled-checks:
- ifElseChain
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build frontend dist.
FROM node:18-alpine AS frontend
FROM node:20-alpine AS frontend
WORKDIR /frontend-build

COPY . .
Expand All @@ -15,9 +15,9 @@ FROM golang:1.21-alpine AS backend
WORKDIR /backend-build

COPY . .
COPY --from=frontend /frontend-build/web/dist ./server/dist
COPY --from=frontend /frontend-build/web/dist ./server/frontend/dist

RUN CGO_ENABLED=0 go build -o memos ./main.go
RUN CGO_ENABLED=0 go build -o memos ./bin/memos/main.go

# Make workspace with above generated files.
FROM alpine:latest AS monolithic
Expand Down
24 changes: 15 additions & 9 deletions api/v1/rss.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v1

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand All @@ -12,9 +11,11 @@ import (

"github.com/gorilla/feeds"
"github.com/labstack/echo/v4"
"github.com/yuin/goldmark"

"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"
)

Expand Down Expand Up @@ -117,10 +118,14 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
if err != nil {
return "", err
}
description, err := getRSSItemDescription(memoMessage.Content)
if err != nil {
return "", err
}
feed.Items[i] = &feeds.Item{
Title: getRSSItemTitle(memoMessage.Content),
Link: &feeds.Link{Href: baseURL + "/m/" + fmt.Sprintf("%d", memoMessage.ID)},
Description: getRSSItemDescription(memoMessage.Content),
Description: description,
Created: time.Unix(memoMessage.CreatedTs, 0),
Enclosure: &feeds.Enclosure{Url: baseURL + "/m/" + fmt.Sprintf("%d", memoMessage.ID) + "/image"},
}
Expand Down Expand Up @@ -182,7 +187,7 @@ func getRSSItemTitle(content string) string {
return title
}

func getRSSItemDescription(content string) string {
func getRSSItemDescription(content string) (string, error) {
var description string
if isTitleDefined(content) {
var firstLineEnd = strings.Index(content, "\n")
Expand All @@ -191,12 +196,13 @@ func getRSSItemDescription(content string) string {
description = content
}

// TODO: use our `./plugin/gomark` parser to handle markdown-like content.
var buf bytes.Buffer
if err := goldmark.Convert([]byte(description), &buf); err != nil {
panic(err)
tokens := tokenizer.Tokenize(description)
nodes, err := parser.Parse(tokens)
if err != nil {
return "", err
}
return buf.String()
result := html.NewHTMLRender().Render(nodes)
return result, nil
}

func isTitleDefined(content string) bool {
Expand Down
2 changes: 1 addition & 1 deletion api/v1/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err)
}
for _, systemSetting := range systemSettingList {
if systemSetting.Name == SystemSettingServerIDName.String() || systemSetting.Name == SystemSettingSecretSessionName.String() || systemSetting.Name == SystemSettingTelegramBotTokenName.String() {
if systemSetting.Name == SystemSettingServerIDName.String() || systemSetting.Name == SystemSettingSecretSessionName.String() || systemSetting.Name == SystemSettingTelegramBotTokenName.String() || systemSetting.Name == SystemSettingInstanceURLName.String() {
continue
}

Expand Down
3 changes: 3 additions & 0 deletions api/v1/system_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const (
SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts"
// SystemSettingAutoBackupIntervalName is the name of auto backup interval as seconds.
SystemSettingAutoBackupIntervalName SystemSettingName = "auto-backup-interval"
// SystemSettingInstanceURLName is the name of instance url setting.
SystemSettingInstanceURLName SystemSettingName = "instance-url"
)
const systemSettingUnmarshalError = `failed to unmarshal value from system setting "%v"`

Expand Down Expand Up @@ -271,6 +273,7 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
return errors.Errorf(systemSettingUnmarshalError, settingName)
}
case SystemSettingInstanceURLName:
default:
return errors.New("invalid system setting name")
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/memos.go → bin/memos/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"context"
Expand Down Expand Up @@ -186,3 +186,10 @@ func printGreetings() {
fmt.Printf("👉GitHub: %s\n", "https://github.com/usememos/memos")
println("---")
}

func main() {
err := Execute()
if err != nil {
panic(err)
}
}
Loading

0 comments on commit 91fecbe

Please sign in to comment.