Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit9db2af4

Browse files
committed
fix(digest): use list as backup digest source
1 parentd2cb379 commit9db2af4

File tree

11 files changed

+61
-30
lines changed

11 files changed

+61
-30
lines changed

‎lib/groupher_server/cms/delegates/article_curd.ex‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,31 +293,24 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
293293
{:ok,community}<-ORM.find(Community,cid)do
294294
Multi.new()
295295
|>Multi.run(:create_article,fn_,_->
296-
IO.inspect(attrs,label:"1 create article")
297296
do_create_article(info.model,attrs,author,community)
298297
end)
299298
|>Multi.run(:create_document,fn_,%{create_article:article}->
300-
IO.inspect(article,label:"2 article")
301299
Document.create(article,attrs)
302300
end)
303301
|>Multi.run(:mirror_article,fn_,%{create_article:article}->
304-
IO.inspect("3")
305302
ArticleCommunity.mirror_article(thread,article.id,community.id)
306303
end)
307304
|>Multi.run(:set_article_tags,fn_,%{create_article:article}->
308-
IO.inspect("4")
309305
ArticleTag.set_article_tags(community,thread,article,attrs)
310306
end)
311307
|>Multi.run(:set_active_at_timestamp,fn_,%{create_article:article}->
312-
IO.inspect("5")
313308
ORM.update(article,%{active_at:article.inserted_at})
314309
end)
315310
|>Multi.run(:update_community_article_count,fn_,_->
316-
IO.inspect("6")
317311
CommunityCURD.update_community_count_field(community,thread)
318312
end)
319313
|>Multi.run(:update_user_published_meta,fn_,_->
320-
IO.inspect("7")
321314
Accounts.update_published_states(uid,thread)
322315
end)
323316
|>Multi.run(:after_hooks,fn_,%{create_article:article}->

‎lib/helper/converter/article.ex‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ defmodule Helper.Converter.Article do
2929
with{:ok,body_map}<-to_editor_map(body),
3030
{:ok,body_html}<-EditorToHTML.to_html(body_map),
3131
{:ok,body_encode}<-Jason.encode(body_map)do
32-
%{body:body_encode,body_html:body_html,body_map:body_map}|>done
32+
%{body:body_encode,body_html:body_html,body_map:body_map}
33+
|>done
3334
end
3435
end
3536

@@ -39,18 +40,47 @@ defmodule Helper.Converter.Article do
3940
parse digest by concat all the paragraph blocks
4041
"""
4142
defparse_digest(%{"blocks"=>blocks}=body_map)whenis_map(body_map)do
42-
paragraph_blocks=Enum.filter(blocks,&(&1["type"]=="paragraph"))
43+
digest_blocks=Enum.filter(blocks,&(&1["type"]=="paragraph"))
4344

44-
Enum.reduce(paragraph_blocks,"",fnblock,acc->
45+
Enum.reduce(digest_blocks,"",fnblock,acc->
4546
text=block["data"]["text"]|>HtmlSanitizer.strip_all_tags()
4647
acc<>text<>" "
4748
end)
4849
|>String.trim_trailing()
50+
|>parse_other_blocks_ifneed(blocks)
4951
|>String.slice(0,@article_digest_length)
5052
|>done
5153
end
5254

53-
defparse_digest(_),do:{:ok,"unknow digest"}
55+
defparse_digest(_),do:{:ok,"无可预览摘要"}
56+
57+
# 如果文章里没有段落,可以使用列表内容(如果有的话)作为预览内容
58+
defpparse_other_blocks_ifneed("",blocks)do
59+
list_blocks=Enum.filter(blocks,&(&1["type"]=="list"))
60+
61+
digest=
62+
caselist_blocksdo
63+
[]->
64+
"无可预览摘要"
65+
66+
_->
67+
digest_block=list_blocks|>List.first()
68+
69+
Enum.reduce(digest_block["data"]["items"],"",fnitem,acc->
70+
text=item["text"]
71+
acc<>text<>" "
72+
end)
73+
|>String.trim_trailing()
74+
|>HtmlSanitizer.strip_all_tags()
75+
|>String.slice(0,@article_digest_length)
76+
end
77+
78+
digest
79+
end
80+
81+
defpparse_other_blocks_ifneed(paragraph_digest,_blocks)do
82+
paragraph_digest
83+
end
5484

5585
@doc"""
5686
decode article body string to editor map and assign id for each block

‎lib/helper/converter/editor_to_html/class.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule Helper.Converter.EditorToHTML.Class do
4040
"label__red"=>"list-label__red",
4141
"label__green"=>"list-label__green",
4242
"label__warn"=>"list-label__warn",
43-
"unorder_list_prefix"=>"list__item-unorder-prefix",
43+
"unordered_list_prefix"=>"list__item-unorder-prefix",
4444
"order_list_prefix"=>"list__item-order-prefix",
4545
"list_item"=>"list-item",
4646
"checklist_item"=>"list-checklist__item",

‎lib/helper/converter/editor_to_html/frags/list.ex‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ defmodule Helper.Converter.EditorToHTML.Frags.List do
99

1010
@classget_in(Class.article(),["list"])
1111

12-
@specget_item(:checklist|:unorder_list|:order_list,T.editor_list_item())::T.html()
12+
@specget_item(:checklist|:unordered_list|:order_list,T.editor_list_item())::T.html()
1313
defget_item(
14-
:unorder_list,
14+
:unordered_list,
1515
%{
1616
"hideLabel"=>hide_label,
1717
"indent"=>indent,
@@ -20,7 +20,7 @@ defmodule Helper.Converter.EditorToHTML.Frags.List do
2020
"text"=>text
2121
}
2222
)do
23-
prefix_frag=frag(:unorder_list_prefix)
23+
prefix_frag=frag(:unordered_list_prefix)
2424
label_frag=ifhide_label,do:"",else:frag(:label,label_type,indent,label)
2525
text_frag=frag(:text,text)
2626

@@ -91,9 +91,9 @@ defmodule Helper.Converter.EditorToHTML.Frags.List do
9191
</div>)
9292
end
9393

94-
@specfrag(:unorder_list_prefix)::T.html()
95-
deffrag(:unorder_list_prefix)do
96-
~s(<divpl-s1">#{@class["unorder_list_prefix"]}"></div>)
94+
@specfrag(:unordered_list_prefix)::T.html()
95+
deffrag(:unordered_list_prefix)do
96+
~s(<divpl-s1">#{@class["unordered_list_prefix"]}"></div>)
9797
end
9898

9999
@specfrag(:order_list_prefix,String.t())::T.html()

‎lib/helper/converter/editor_to_html/validator/editor_schema.ex‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ defmodule Helper.Converter.EditorToHTML.Validator.EditorSchema do
88
@valid_quote_mode["short","long"]
99

1010
# list
11-
@valid_list_mode["checklist","order_list","unorder_list"]
12-
@valid_list_label_type["green","red","warn","default"]
11+
@valid_list_mode["checklist","order_list","unordered_list"]
12+
@valid_list_label_type["green","red","warn","default",nil]
1313
@valid_list_indent[0,1,2,3]
1414

1515
# table
@@ -66,7 +66,7 @@ defmodule Helper.Converter.EditorToHTML.Validator.EditorSchema do
6666
item:%{
6767
"checked"=>[:boolean],
6868
"hideLabel"=>[:boolean],
69-
"label"=>[:string],
69+
"label"=>[:string,required:false],
7070
"labelType"=>[enum:@valid_list_label_type],
7171
"prefixIndex"=>[:string,required:false],
7272
"indent"=>[enum:@valid_list_indent],

‎lib/helper/converter/md_to_editor.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ defmodule Helper.Converter.MdToEditor do
108108
%{
109109
type:"list",
110110
data:%{
111-
mode:"unorder_list",
111+
mode:"unordered_list",
112112
items:items
113113
}
114114
}

‎lib/helper/types.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ defmodule Helper.Types do
121121
@typeeditor_list_label_type:::default|:red|:green|:warn
122122

123123
@typedoc"""
124-
editor.js's list item for order_list |unorder_list | checklist
124+
editor.js's list item for order_list |unordered_list | checklist
125125
"""
126126
@typeeditor_list_item::%{
127127
required(:hideLabel)=>String.t(),

‎test/groupher_server/cms/articles/pending_flag_test.exs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ defmodule GroupherServer.Test.CMS.PostPendingFlag do
137137

138138
aliasCMS.Delegate.Hooks
139139

140-
@tag:wip
141140
test"can audit paged audit failed posts",~m(post_m)ado
142141
{:ok,post}=ORM.find(CMS.Model.Post,post_m.id)
143142

‎test/groupher_server_web/mutation/cms/articles/post_test.exs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,24 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do
4848
}
4949
}
5050
"""
51+
@tag:wip
5152
test"create post with valid attrs and make sure author exsit"do
5253
{:ok,user}=db_insert(:user)
5354
user_conn=simu_conn(:user,user)
5455

5556
{:ok,community}=db_insert(:community)
5657
post_attr=mock_attrs(:post)|>Map.merge(%{linkAddr:"https://helloworld"})
5758

58-
variables=post_attr|>Map.merge(%{communityId:community.id})
59+
# body = """
60+
# {"time":1639375020110,"blocks":[{"type":"list","data":{"mode":"unordered_list","items":[{"text":"CP 的图标是字母 C (Coder / China) 和 Planet 的意象结合,斜向的条饰灵感来自于 NASA Logo 上的 \"red chevron\"。","label":null,"labelType":null,"checked":false,"hideLabel":true,"prefixIndex":"","indent":0},{"text":"所有的 Upvote 的图标都是小火箭,点击它会有一个起飞的动画 — 虽然它目前看起来像爆炸。。","label":null,"labelType":null,"checked":false,"hideLabel":true,"prefixIndex":"","indent":0}]}}],"version":"2.19.38"}
61+
# """
62+
body="""
63+
{"time":1639375020110,"blocks":[{"type":"list","data":{"mode":"unordered_list","items":[{"text":"CP 的图标是字母 C (Coder / China) 和 Planet 的意象结合,斜向的条饰灵感来自于 NASA Logo 上的 red chevron。","label":null,"labelType":null,"checked":false,"hideLabel":true,"prefixIndex":"","indent":0},{"text":"所有的 Upvote 的图标都是小火箭,点击它会有一个起飞的动画 — 虽然它目前看起来像爆炸。。","label":null,"labelType":null,"checked":false,"hideLabel":true,"prefixIndex":"","indent":0}]}}],"version":"2.19.38"}
64+
"""
65+
66+
variables=post_attr|>Map.merge(%{communityId:community.id,body:body})
5967
created=user_conn|>mutation_result(@create_post_query,variables,"createPost")
68+
6069
{:ok,post}=ORM.find(Post,created["id"])
6170

6271
assertcreated["id"]==to_string(post.id)

‎test/helper/converter/editor_to_html_test/image_test.exs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do
7070
{:ok,editor_string}=Jason.encode(editor_json)
7171
{:ok,converted}=Parser.to_html(editor_string)
7272

73-
#unorder_list_prefix_class = @class["unorder_list_prefix"]
73+
#unordered_list_prefix_class = @class["unordered_list_prefix"]
7474
assertUtils.str_occurence(converted,"<img")==1
7575
assertUtils.str_occurence(converted,"width:")==0
7676
assertUtils.str_occurence(converted,"height:")==0
@@ -91,7 +91,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do
9191
{:ok,editor_string}=Jason.encode(editor_json)
9292
{:ok,converted}=Parser.to_html(editor_string)
9393

94-
#unorder_list_prefix_class = @class["unorder_list_prefix"]
94+
#unordered_list_prefix_class = @class["unordered_list_prefix"]
9595
assertUtils.str_occurence(converted,"<img")==1
9696
assertUtils.str_occurence(converted,"width:")==0
9797
assertUtils.str_occurence(converted,"height:")==0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp