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.

Commit55c2a5f

Browse files
authored
refactor: seeds generator (#428)
* chore: wip* chore: wip* chore: extract tags* chore: wip* chore: wip* chore: wip* chore: add blackhole* chore: re-org codebase
1 parent246b74e commit55c2a5f

File tree

18 files changed

+1704
-1186
lines changed

18 files changed

+1704
-1186
lines changed

‎lib/groupher_server/cms/cms.ex‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ defmodule GroupherServer.CMS do
196196

197197
# seeds
198198
defdelegateseed_communities(opt),to:Seeds
199+
defdelegateseed_community(raw,type),to:Seeds
200+
defdelegateseed_community(raw),to:Seeds
199201
defdelegateseed_set_category(communities,category),to:Seeds
202+
200203
defdelegateseed_bot,to:Seeds
201204
end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
defmoduleGroupherServer.CMS.Delegate.Seeds.Categoriesdo
2+
@doc"""
3+
default categories seeds for general community
4+
"""
5+
defget()do
6+
[
7+
%{
8+
title:"编程语言",
9+
raw:"pl",
10+
index:0
11+
},
12+
%{
13+
title:"框架 & 库",
14+
raw:"framework",
15+
index:1
16+
},
17+
%{
18+
title:"数据库",
19+
raw:"database",
20+
index:2
21+
},
22+
%{
23+
title:"devops",
24+
raw:"devops",
25+
index:3
26+
},
27+
%{
28+
title:"开发工具",
29+
raw:"tools",
30+
index:4
31+
},
32+
%{
33+
title:"城市",
34+
raw:"city",
35+
index:5
36+
},
37+
%{
38+
title:"人工智能",
39+
raw:"ai",
40+
index:6
41+
},
42+
%{
43+
title:"作品",
44+
raw:"works",
45+
index:7
46+
},
47+
%{
48+
# blackhole, Feedback, dev
49+
title:"站务",
50+
raw:"feedback",
51+
index:8
52+
},
53+
%{
54+
# Makers, Adwall, Outwork
55+
title:"其他",
56+
raw:"others",
57+
index:9
58+
}
59+
]
60+
end
61+
end
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
defmoduleGroupherServer.CMS.Delegate.Seeds.Communitiesdo
2+
@moduledoc"""
3+
communities seeds
4+
"""
5+
6+
defget(:pl)do
7+
[
8+
"c",
9+
"clojure",
10+
"cpp",
11+
"csharp",
12+
"dart",
13+
"delphi",
14+
"elm",
15+
"erlang",
16+
"fsharp",
17+
"go",
18+
"gradle",
19+
"groovy",
20+
"java",
21+
"javascript",
22+
"julia",
23+
"kotlin",
24+
"lisp",
25+
"lua",
26+
"ocaml",
27+
"perl",
28+
"php",
29+
"python",
30+
"ruby",
31+
"r",
32+
"racket",
33+
"red",
34+
"reason",
35+
"rust",
36+
"scala",
37+
"haskell",
38+
"swift",
39+
"typescript",
40+
"elixir",
41+
# new
42+
"deno",
43+
"crystal",
44+
"hack",
45+
"nim",
46+
"fasm",
47+
"zig",
48+
"prolog"
49+
]
50+
end
51+
52+
defget(:framework)do
53+
[
54+
"backbone",
55+
"d3",
56+
"django",
57+
"drupal",
58+
"eggjs",
59+
"electron",
60+
"laravel",
61+
"meteor",
62+
"nestjs",
63+
"nuxtjs",
64+
"nodejs",
65+
"phoenix",
66+
"rails",
67+
"react",
68+
"sails",
69+
"zend",
70+
"vue",
71+
"angular",
72+
"tensorflow",
73+
# mobile
74+
"android",
75+
"ios",
76+
"react-native",
77+
"weex",
78+
"xamarin",
79+
"nativescript",
80+
"ionic",
81+
# new
82+
"rxjs",
83+
"flutter",
84+
"taro",
85+
"webrtc",
86+
"wasm"
87+
]
88+
end
89+
90+
defget(:editor)do
91+
["vim","atom","emacs","vscode","visualstudio","jetbrains"]
92+
end
93+
94+
defget(:database)do
95+
[
96+
"oracle",
97+
"hive",
98+
"spark",
99+
"hadoop",
100+
"cassandra",
101+
"elasticsearch",
102+
"sql-server",
103+
"neo4j",
104+
"mongodb",
105+
"mysql",
106+
"postgresql",
107+
"redis"
108+
]
109+
end
110+
111+
defget(:city)do
112+
[
113+
"beijing",
114+
"shanghai",
115+
"shenzhen",
116+
"hangzhou",
117+
"guangzhou",
118+
"chengdu",
119+
"wuhan",
120+
"xiamen",
121+
"nanjing"
122+
]
123+
end
124+
125+
defget(:devops)do
126+
# gcp -> google-cloud-platform
127+
# search google: devops tools
128+
["git","docker","kubernetes","jenkins","puppet","aws","azure","aliyun","gcp"]
129+
end
130+
end
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
defmoduleGroupherServer.CMS.Delegate.Seeds.Domaindo
2+
@moduledoc"""
3+
seeds data for init, should be called ONLY in new database, like migration
4+
"""
5+
6+
importEcto.Query,warn:false
7+
8+
importGroupherServer.CMS.Delegate.Seeds.Helper,
9+
only:[
10+
threadify_communities:2,
11+
tagfy_threads:4,
12+
categorify_communities:3,
13+
seed_bot:0,
14+
seed_threads:1,
15+
seed_categories_ifneed:1
16+
]
17+
18+
aliasHelper.ORM
19+
aliasGroupherServer.CMS
20+
21+
aliasCMS.Model.Community
22+
23+
@oss_endpoint"https://cps-oss.oss-cn-shanghai.aliyuncs.com"
24+
25+
# seed community
26+
@doc"""
27+
seed community for home
28+
"""
29+
defseed_community(:home)do
30+
with{:error,_}<-ORM.find_by(Community,%{raw:"home"}),
31+
{:ok,bot}<-seed_bot(),
32+
{:ok,threads}<-seed_threads(:home),
33+
{:ok,categories}<-seed_categories_ifneed(bot)do
34+
args=%{
35+
title:"coderplanets",
36+
desc:"the most sexy community for developers, ever.",
37+
logo:"#{@oss_endpoint}/icons/cmd/keyboard_logo.png",
38+
raw:"home",
39+
user_id:bot.id
40+
}
41+
42+
{:ok,community}=Community|>ORM.create(args)
43+
threadify_communities([community],threads.entries)
44+
tagfy_threads([community],threads.entries,bot,:home)
45+
46+
{:ok,community}
47+
# home 不设置分类,比较特殊
48+
end
49+
end
50+
51+
@doc"""
52+
seed community for blackhole
53+
"""
54+
defseed_community(:blackhole)do
55+
with{:error,_}<-ORM.find_by(Community,%{raw:"blackhole"}),
56+
{:ok,bot}<-seed_bot(),
57+
{:ok,threads}<-seed_threads(:blackhole),
58+
{:ok,categories}<-seed_categories_ifneed(bot)do
59+
args=%{
60+
title:"黑洞",
61+
desc:"这里收录不适合出现在本站的内容。",
62+
logo:"#{@oss_endpoint}/icons/cmd/keyboard_logo.png",
63+
raw:"blackhole",
64+
user_id:bot.id
65+
}
66+
67+
{:ok,community}=Community|>ORM.create(args)
68+
threadify_communities([community],threads.entries)
69+
tagfy_threads([community],threads.entries,bot,:blackhole)
70+
categorify_communities([community],categories,:feedback)
71+
72+
{:ok,community}
73+
end
74+
end
75+
76+
@doc"""
77+
seed community for feedback
78+
"""
79+
defseed_community(:feedback)do
80+
with{:error,_}<-ORM.find_by(Community,%{raw:"feedback"}),
81+
{:ok,bot}<-seed_bot(),
82+
{:ok,threads}<-seed_threads(:feedback),
83+
{:ok,categories}<-seed_categories_ifneed(bot)do
84+
args=%{
85+
title:"反馈与建议",
86+
desc:"关于本站的建议和反馈请发布在这里,谢谢。",
87+
logo:"#{@oss_endpoint}/icons/cmd/keyboard_logo.png",
88+
raw:"feedback",
89+
user_id:bot.id
90+
}
91+
92+
{:ok,community}=Community|>ORM.create(args)
93+
threadify_communities([community],threads.entries)
94+
tagfy_threads([community],threads.entries,bot,:feedback)
95+
categorify_communities([community],categories,:feedback)
96+
97+
{:ok,community}
98+
# home 不设置分类,比较特殊
99+
end
100+
end
101+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp