Skip to content

Commit

Permalink
Merge branch 'styling-page'
Browse files Browse the repository at this point in the history
  • Loading branch information
movsb committed Jan 15, 2025
2 parents ef76e5f + d11fc9c commit 05a0cbf
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 48 deletions.
37 changes: 37 additions & 0 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package client

import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"os/exec"
"os/user"
Expand All @@ -13,6 +16,7 @@ import (
"strings"
"time"

"github.com/PuerkitoBio/goquery"
"github.com/movsb/taoblog/modules/utils"
"github.com/movsb/taoblog/protocols/go/proto"
"github.com/movsb/taoblog/service/models"
Expand Down Expand Up @@ -333,6 +337,39 @@ func AddCommands(rootCmd *cobra.Command) {
}
postsCmd.AddCommand(postsDeleteCmd)

postsCreateStylingPageCmd := &cobra.Command{
Use: `create-styling-page`,
Short: `创建样式测试页面`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
source := utils.Must1(cmd.Flags().GetString(`source`))
url, err := url.Parse(source)
if err == nil && (url.Scheme == `http` || url.Scheme == `https`) {
rsp, err := http.Get(source)
if err != nil {
log.Fatalln(err)
}
if rsp.StatusCode != 200 {
log.Fatalln(`code != 200`)
}
doc := utils.Must1(goquery.NewDocumentFromReader(io.LimitReader(rsp.Body, 1<<20)))
body := doc.Find(`body`)
if len(body.Nodes) <= 0 {
log.Fatalln(`no body`)
}
source = utils.Must1(body.Html())
// log.Println(source)
} else if source != `` {
source = string(utils.Must1(os.ReadFile(source)))
}
utils.Must1(client.Blog.CreateStylingPage(client.Context(), &proto.CreateStylingPageRequest{
Source: source,
}))
},
}
postsCreateStylingPageCmd.Flags().StringP(`source`, `s`, ``, `文章源内容路径,支持指定网页。`)
postsCmd.AddCommand(postsCreateStylingPageCmd)

commentsCmd := &cobra.Command{
Use: `comments`,
Short: `Commands for managing comments`,
Expand Down
5 changes: 5 additions & 0 deletions protocols/post.proto
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ message PreviewPostResponse {
string html = 1;
}

message CreateStylingPageRequest {
string source = 1;
}
message CreateStylingPageResponse {}

message CheckTaskListItemsRequest {
// 文章/评论编号
int32 id = 1;
Expand Down
9 changes: 9 additions & 0 deletions protocols/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ service TaoBlog {
description: "完成/取消完成任务。";
};
}
rpc CreateStylingPage (CreateStylingPageRequest) returns (CreateStylingPageResponse) {
option (google.api.http) = {
post: "/v3/styling";
body: "*";
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
description: "创建样式测试页面";
};
}
}

message PingRequest {
Expand Down
54 changes: 53 additions & 1 deletion service/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/movsb/taoblog/service/modules/renderers/rooted_path"
"github.com/movsb/taoblog/service/modules/renderers/scoped_css"
task_list "github.com/movsb/taoblog/service/modules/renderers/tasklist"
"github.com/movsb/taoblog/theme/styling"
"github.com/movsb/taorm"
"github.com/yuin/goldmark/extension"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -673,7 +674,7 @@ func (s *Service) UpdatePost(ctx context.Context, in *proto.UpdatePostRequest) (
m[`title`] = title
}
// 除碎碎念外,文章不允许空标题
if ty != `tweet` && title == "" {
if ty != `tweet` && (title == "" && !hasTitle) {
return nil, status.Error(codes.InvalidArgument, "文章必须要有标题。")
}
}
Expand Down Expand Up @@ -973,3 +974,54 @@ func (s *Service) applyTaskChecks(modified int32, sourceType, rawSource string,

return string(source), nil
}

func (s *Service) CreateStylingPage(ctx context.Context, in *proto.CreateStylingPageRequest) (*proto.CreateStylingPageResponse, error) {
source := in.Source
if source == `` {
source = string(utils.Must1(styling.Root.ReadFile(`index.md`)))
}

id, err := s.GetIntegerOption(`styling_page_id`)
if err != nil {
if !taorm.IsNotFoundError(err) {
return nil, err
}
var p *proto.Post
p, err = s.CreatePost(ctx, &proto.Post{
Title: `测试页面📄`,
Slug: `styling`,
Type: `page`,
Status: `public`,
SourceType: `markdown`,
Source: source,
})
if err == nil {
s.SetOption(`styling_page_id`, p.Id)
}
} else {
var p *proto.Post
p, err = s.GetPost(ctx, &proto.GetPostRequest{Id: int32(id)})
if err != nil {
return nil, err
}
_, err = s.UpdatePost(ctx, &proto.UpdatePostRequest{
Post: &proto.Post{
Id: id,
Title: `测试页面📄`,
Modified: p.Modified,
Slug: `styling`,
SourceType: `markdown`,
Source: source,
},
UpdateMask: &fieldmaskpb.FieldMask{
Paths: []string{
`slug`,
`source_type`,
`source`,
`title`,
},
},
})
}
return &proto.CreateStylingPageResponse{}, err
}
2 changes: 1 addition & 1 deletion theme/blog/styles/comment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ body.signed-in {
}

> input[type=text], input[type=submit],input[type=email],input[type=url], .field {
margin-bottom: 8px;
margin: 0 0 8px 0;
display: block;
box-sizing: border-box;
width: 100%;
Expand Down
70 changes: 37 additions & 33 deletions theme/blog/styles/form.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
button, input[type=submit] {
// 默认不要挨着
button, input, textarea, select {
margin: 2px;
}

// 颜色
button, input, textarea, select {
&::-moz-focus-inner {
border: 0;
}
color: inherit;
background-color: transparent;
}

input[type=text],input[type=password],input[type=email],input[type=url], textarea {
// 边框
button, input, textarea, select {
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
}

// 内边距 & 行高
button, input {
line-height: 2;
}
button,input[type=button],input[type=submit],input[type=reset] {
padding: var(--button-padding);
}
input {
padding: var(--input-padding);
}
textarea {
padding: var(--textarea-padding);
line-height: inherit;
}

// 字体
input, button, textarea, select {
font-family: inherit;
font-size: inherit;
}

input, textarea {
&:focus {
outline: none;
}
Expand All @@ -20,31 +53,7 @@ input[type=datetime-local] {
box-sizing: border-box;
}

@media (prefers-color-scheme: dark) {
input[type=text], input[type=password],input[type=email],input[type=url],input[type=datetime-local], textarea {
color: var(--color-fg);
background-color: var(--color-bg);
}
}

input[type=text], input[type=password],input[type=email],input[type=url], textarea {
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: var(--input-padding);
}
button, select, input[type=datetime-local], input[type=submit] {
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding-left: .5em;
padding-right: .5em;
}
textarea {
padding: var(--textarea-padding);
line-height: inherit;
}
input, button, textarea, select {
font: inherit;
}
input, textarea, button, select {
&:hover {
border: 1px solid var(--accent-color);
Expand All @@ -66,12 +75,7 @@ input[type=text],input[type=password],input[type=email],input[type=url],textarea
}
}

// 只是为了自定义夜间默认(默认没有)。
// 只有在 Firefox 上看起来比较顺眼,Safari 上和默认的差异比较大。
select {
color: var(--color-fg);
background-color: var(--color-bg);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
height: 2em;
padding: var(--input-padding);
}

15 changes: 5 additions & 10 deletions theme/blog/styles/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,11 @@ body.wide #header .content {
}
}

.search {
input {
color: #fff6;
border: 1px solid #a9a9a933;
background-color: transparent;
border-radius: var(--border-radius);
padding: 4px 6px;
width: 120px;
}
}
.search {
input {
width: 120px;
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions theme/blog/styles/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
--line-height-loose: 2;
--line-height-tight: 1.5;

--input-padding: 5px 7px;
--button-padding: 5px 10px;
--textarea-padding: 7px;
--input-padding: 0 5px;
--button-padding: 0 8px;
--textarea-padding: 3px 5px;

// 其实我并不喜欢修改用户的选中色……
--selection-background-color: #ac53ac8f;
Expand Down
3 changes: 3 additions & 0 deletions theme/styling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 测试页面说明

可以参考:<https://cbracco.github.io/html5-test-page/>
6 changes: 6 additions & 0 deletions theme/styling/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package styling

import "embed"

//go:embed *
var Root embed.FS
Loading

0 comments on commit 05a0cbf

Please sign in to comment.