├── .editorconfig
├── .eslintrc.js
├── .gitignore
├── README.md
├── assets
├── README.md
├── atom-one-light.css
├── close.png
├── gitment
│ ├── constants.js
│ ├── constants.js.map
│ ├── default.css
│ ├── gitment.browser.js
│ ├── gitment.browser.js.map
│ ├── gitment.js
│ ├── gitment.js.map
│ ├── icons.js
│ ├── icons.js.map
│ ├── theme
│ │ ├── default.js
│ │ └── default.js.map
│ ├── utils.js
│ └── utils.js.map
├── hybrid.css
├── logo.jpg
├── logo.png
└── radiocolor.png
├── components
├── ArticleList.vue
├── Comment.vue
└── README.md
├── layouts
├── README.md
├── default.vue
└── error.vue
├── middleware
└── README.md
├── nuxt.config.js
├── package.json
├── pages
├── README.md
├── _tag.vue
├── details
│ └── _id.vue
├── index.vue
└── search
│ └── _search.vue
├── plugins
├── README.md
├── axios.js
└── element-ui.js
├── pull.js
├── static
├── README.md
└── favicon.ico
├── store
├── README.md
└── index.js
├── style
└── style.css
└── utils
└── index.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_size = 2
6 | indent_style = space
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: {
4 | browser: true,
5 | node: true
6 | },
7 | parserOptions: {
8 | parser: 'babel-eslint'
9 | },
10 | extends: [
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | 'plugin:vue/essential'
14 | ],
15 | // required to lint *.vue files
16 | plugins: [
17 | 'vue'
18 | ],
19 | // add your custom rules here
20 | rules: {}
21 | }
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # dependencies
2 | node_modules
3 |
4 | # logs
5 | npm-debug.log
6 |
7 | # Nuxt build
8 | .nuxt
9 |
10 | # Nuxt generate
11 | dist
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## vue服务端渲染[博客](http://binlive.cn "博客"),基于nuxt
2 |
3 | ## 安装
4 |
5 | ```
6 | git clone git@github.com:Hzy0913/my-blog.git
7 | ```
8 | 安装包依赖
9 | ```
10 | npm install
11 | ```
12 |
13 | ## 运行
14 | 运行发开环境
15 | ```js
16 | npm run dev
17 | ```
18 | 本地访问 `http://localhost:3000`
19 | ## 打包部署
20 | tip:生产环境打包需要在服务端进行!
21 | **首先打包编译项目**
22 | ```js
23 | npm run build
24 | ```
25 | **运行项目**
26 | ```js
27 | npm run start
28 | ```
29 | **推荐生产环境使用如下命令执行pm2部署**
30 | ###### 推荐全局安装pm2
31 | **第一次部署使用firstserver命令**
32 | ```js
33 | npm run firstserver
34 | ```
35 | **以后每次更新代码执行server命令**
36 | ```js
37 | npm run server
38 | ```
39 | **暂停服务执行stop命令**
40 | ```js
41 | npm run stop
42 | ```
43 | **查看服务状态执行list命令**
44 | ```js
45 | npm run list
46 | ```
47 | 该命令会编译打包项目,然后启动一个pm2守护进程服务,具体可见`package`中的npm script
48 | ## 项目说明
49 |
50 | - 使用nuxt.js的vue服务端渲染ssr.
51 | - 使用element-ui 组件库.
52 | - 使用axios请求库
53 | - 使用github的Oauth授权登录,评论系统
54 | - 使用marked解析markdown文档
55 | - 使用highlight完成代码格式语法高亮
56 |
57 | ## 在线预览
58 |
59 | See [BinLive](http://binlive.cn "BinLive").
60 | ## 本地预览
61 | 想要在本地开发环境运行完整线上模式,可以转发调用binlive线上环境接口。
62 | 修改`nuxt.config.js`文件
63 | ```javascript
64 | // 将下面接口调用地址
65 | proxy: [
66 | ['/api', { target: 'http://localhost:3080' }]
67 | ]
68 | // 修该成binlive线上地址
69 | proxy: [
70 | ['/api', { target: 'http://binlive.cn:3080' }]
71 | ]
72 | ```
73 | 修改`plugins/axios.js`文件
74 | ```javascript
75 | // 将下面接口调用地址
76 | if (process.server) {
77 | options.baseURL = 'http://localhost:3080'
78 | }
79 | // 修该成binlive线上地址
80 | if (process.server) {
81 | options.baseURL = 'http://binlive.cn:3080'
82 | }
83 | ```
84 | ## commit
85 | 由于spa对于seo不友好,重构了之前使用vue的spa形式的博客,使用[nuxt.js](https://nuxtjs.org "nuxt.js")
86 | ## 博客后端
87 | 博客的后端以及后台管理系统项目为[博客后端](https://github.com/Hzy0913/blog-server "博客后端")项目。
88 |
--------------------------------------------------------------------------------
/assets/README.md:
--------------------------------------------------------------------------------
1 | # ASSETS
2 |
3 | This directory contains your un-compiled assets such as LESS, SASS, or JavaScript.
4 |
5 | More information about the usage of this directory in the documentation:
6 | https://nuxtjs.org/guide/assets#webpacked
7 |
8 | **This directory is not required, you can delete it if you don't want to use it.**
9 |
--------------------------------------------------------------------------------
/assets/atom-one-light.css:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Atom One Light by Daniel Gamage
4 | Original One Light Syntax theme from https://github.com/atom/one-light-syntax
5 |
6 | base: #fafafa
7 | mono-1: #383a42
8 | mono-2: #686b77
9 | mono-3: #a0a1a7
10 | hue-1: #0184bb
11 | hue-2: #4078f2
12 | hue-3: #a626a4
13 | hue-4: #50a14f
14 | hue-5: #e45649
15 | hue-5-2: #c91243
16 | hue-6: #986801
17 | hue-6-2: #c18401
18 |
19 | */
20 |
21 | .hljs {
22 | display: block;
23 | overflow-x: auto;
24 | padding: 0.5em;
25 | color: #383a42;
26 | background: #fafafa;
27 | }
28 |
29 | .hljs-comment,
30 | .hljs-quote {
31 | color: #a0a1a7;
32 | font-style: italic;
33 | }
34 |
35 | .hljs-doctag,
36 | .hljs-keyword,
37 | .hljs-formula {
38 | color: #a626a4;
39 | }
40 |
41 | .hljs-section,
42 | .hljs-name,
43 | .hljs-selector-tag,
44 | .hljs-deletion,
45 | .hljs-subst {
46 | color: #e45649;
47 | }
48 |
49 | .hljs-literal {
50 | color: #0184bb;
51 | }
52 |
53 | .hljs-string,
54 | .hljs-regexp,
55 | .hljs-addition,
56 | .hljs-attribute,
57 | .hljs-meta-string {
58 | color: #50a14f;
59 | }
60 |
61 | .hljs-built_in,
62 | .hljs-class .hljs-title {
63 | color: #c18401;
64 | }
65 |
66 | .hljs-attr,
67 | .hljs-variable,
68 | .hljs-template-variable,
69 | .hljs-type,
70 | .hljs-selector-class,
71 | .hljs-selector-attr,
72 | .hljs-selector-pseudo,
73 | .hljs-number {
74 | color: #986801;
75 | }
76 |
77 | .hljs-symbol,
78 | .hljs-bullet,
79 | .hljs-link,
80 | .hljs-meta,
81 | .hljs-selector-id,
82 | .hljs-title {
83 | color: #4078f2;
84 | }
85 |
86 | .hljs-emphasis {
87 | font-style: italic;
88 | }
89 |
90 | .hljs-strong {
91 | font-weight: bold;
92 | }
93 |
94 | .hljs-link {
95 | text-decoration: underline;
96 | }
97 |
--------------------------------------------------------------------------------
/assets/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hzy0913/my-blog/0c9e4841d8bdfcbf87e3c75eaa5609dade53aef0/assets/close.png
--------------------------------------------------------------------------------
/assets/gitment/constants.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 | var LS_ACCESS_TOKEN_KEY = exports.LS_ACCESS_TOKEN_KEY = 'gitment-comments-token';
7 | var LS_USER_KEY = exports.LS_USER_KEY = 'gitment-user-info';
8 |
9 | var NOT_INITIALIZED_ERROR = exports.NOT_INITIALIZED_ERROR = new Error('Comments Not Initialized');
10 | //# sourceMappingURL=constants.js.map
--------------------------------------------------------------------------------
/assets/gitment/constants.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":["../src/constants.js"],"names":["LS_ACCESS_TOKEN_KEY","LS_USER_KEY","NOT_INITIALIZED_ERROR","Error"],"mappings":";;;;;AAAO,IAAMA,oDAAsB,wBAA5B;AACA,IAAMC,oCAAc,mBAApB;;AAEA,IAAMC,wDAAwB,IAAIC,KAAJ,CAAU,0BAAV,CAA9B","file":"constants.js","sourcesContent":["export const LS_ACCESS_TOKEN_KEY = 'gitment-comments-token'\nexport const LS_USER_KEY = 'gitment-user-info'\n\nexport const NOT_INITIALIZED_ERROR = new Error('Comments Not Initialized')\n"]}
--------------------------------------------------------------------------------
/assets/gitment/default.css:
--------------------------------------------------------------------------------
1 | .gitment-container {
2 | font-family: sans-serif;
3 | font-size: 14px;
4 | line-height: 1.5;
5 | color: #333;
6 | word-wrap: break-word;
7 | }
8 |
9 | .gitment-container * {
10 | box-sizing: border-box;
11 | }
12 |
13 | .gitment-container *:disabled {
14 | cursor: not-allowed;
15 | }
16 |
17 | .gitment-container a,
18 | .gitment-container a:visited {
19 | cursor: pointer;
20 | text-decoration: none;
21 | }
22 |
23 | .gitment-container a:hover {
24 | text-decoration: underline;
25 | }
26 |
27 | .gitment-container .gitment-hidden {
28 | display: none;
29 | }
30 |
31 | .gitment-container .gitment-spinner-icon {
32 | fill: #333;
33 |
34 | -webkit-animation: gitment-spin 1s steps(12) infinite;
35 | animation: gitment-spin 1s steps(12) infinite;
36 | }
37 |
38 | @-webkit-keyframes gitment-spin {
39 | 100% {
40 | -webkit-transform: rotate(360deg);
41 | transform: rotate(360deg)
42 | }
43 | }
44 |
45 | @keyframes gitment-spin {
46 | 100% {
47 | -webkit-transform: rotate(360deg);
48 | transform: rotate(360deg)
49 | }
50 | }
51 |
52 | .gitment-root-container {
53 | margin: 19px 0;
54 | }
55 |
56 | .gitment-header-container {
57 | margin: 19px 0;
58 | }
59 |
60 | .gitment-header-like-btn,
61 | .gitment-comment-like-btn {
62 | cursor: pointer;
63 | }
64 |
65 | .gitment-comment-like-btn {
66 | float: right;
67 | }
68 |
69 | .gitment-comment-like-btn.liked {
70 | color: #F44336;
71 | }
72 |
73 | .gitment-header-like-btn svg {
74 | vertical-align: middle;
75 | height: 30px;
76 | }
77 |
78 | .gitment-comment-like-btn svg {
79 | vertical-align: middle;
80 | height: 20px;
81 | }
82 |
83 | .gitment-header-like-btn.liked svg,
84 | .gitment-comment-like-btn.liked svg {
85 | fill: #F44336;
86 | }
87 |
88 | a.gitment-header-issue-link,
89 | a.gitment-header-issue-link:visited {
90 | float: right;
91 | line-height: 30px;
92 | color: #666;
93 | }
94 |
95 | a.gitment-header-issue-link:hover {
96 | color: #666;
97 | }
98 |
99 | .gitment-comments-loading,
100 | .gitment-comments-error,
101 | .gitment-comments-empty {
102 | text-align: center;
103 | margin: 50px 0;
104 | }
105 |
106 | .gitment-comments-list {
107 | list-style: none;
108 | padding-left: 0;
109 | margin: 0 0 38px;
110 | }
111 |
112 | .gitment-comment,
113 | .gitment-editor-container {
114 | position: relative;
115 | min-height: 60px;
116 | padding-left: 60px;
117 | margin: 19px 0;
118 | }
119 |
120 | .gitment-comment-avatar,
121 | .gitment-editor-avatar {
122 | float: left;
123 | margin-left: -60px;
124 | }
125 |
126 | .gitment-comment-avatar,
127 | .gitment-comment-avatar-img,
128 | .gitment-comment-avatar,
129 | .gitment-editor-avatar-img,
130 | .gitment-editor-avatar svg {
131 | width: 44px;
132 | height: 44px;
133 | border-radius: 3px;
134 | }
135 |
136 | .gitment-editor-avatar .gitment-github-icon {
137 | fill: #fff;
138 | background-color: #333;
139 | }
140 |
141 | .gitment-comment-main,
142 | .gitment-editor-main {
143 | position: relative;
144 | border: 1px solid #CFD8DC;
145 | border-radius: 0;
146 | }
147 |
148 | .gitment-editor-main::before,
149 | .gitment-editor-main::after,
150 | .gitment-comment-main::before,
151 | .gitment-comment-main::after {
152 | position: absolute;
153 | top: 11px;
154 | left: -16px;
155 | display: block;
156 | width: 0;
157 | height: 0;
158 | pointer-events: none;
159 | content: "";
160 | border-color: transparent;
161 | border-style: solid solid outset;
162 | }
163 |
164 | .gitment-editor-main::before,
165 | .gitment-comment-main::before {
166 | border-width: 8px;
167 | border-right-color: #CFD8DC;
168 | }
169 |
170 | .gitment-editor-main::after,
171 | .gitment-comment-main::after {
172 | margin-top: 1px;
173 | margin-left: 2px;
174 | border-width: 7px;
175 | border-right-color: #fff;
176 | }
177 |
178 | .gitment-comment-header {
179 | margin: 12px 15px;
180 | color: #666;
181 | background-color: #fff;
182 | border-radius: 3px;
183 | }
184 |
185 | .gitment-editor-header {
186 | padding: 0;
187 | margin: 0;
188 | border-bottom: 1px solid #CFD8DC;
189 | }
190 |
191 | a.gitment-comment-name,
192 | a.gitment-comment-name:visited {
193 | font-weight: 600;
194 | color: #666;
195 | }
196 |
197 | .gitment-editor-tabs {
198 | margin-bottom: -1px;
199 | margin-left: -1px;
200 | }
201 |
202 | .gitment-editor-tab {
203 | display: inline-block;
204 | padding: 11px 12px;
205 | font-size: 14px;
206 | line-height: 20px;
207 | color: #666;
208 | text-decoration: none;
209 | background-color: transparent;
210 | border-width: 0 1px;
211 | border-style: solid;
212 | border-color: transparent;
213 | border-radius: 0;
214 |
215 | white-space: nowrap;
216 | cursor: pointer;
217 | user-select: none;
218 |
219 | outline: none;
220 | }
221 |
222 | .gitment-editor-tab.gitment-selected {
223 | color: #333;
224 | background-color: #fff;
225 | border-color: #CFD8DC;
226 | }
227 |
228 | .gitment-editor-login {
229 | float: right;
230 | margin-top: -30px;
231 | margin-right: 15px;
232 | }
233 |
234 | a.gitment-footer-project-link,
235 | a.gitment-footer-project-link:visited,
236 | a.gitment-editor-login-link,
237 | a.gitment-editor-login-link:visited {
238 | color: #2196F3;
239 | }
240 |
241 | a.gitment-editor-logout-link,
242 | a.gitment-editor-logout-link:visited {
243 | color: #666;
244 | }
245 |
246 | a.gitment-editor-logout-link:hover {
247 | color: #2196F3;
248 | text-decoration: none;
249 | }
250 |
251 | .gitment-comment-body {
252 | position: relative;
253 | margin: 12px 15px;
254 | overflow: hidden;
255 | border-radius: 3px;
256 | }
257 |
258 | .gitment-comment-body-folded {
259 | cursor: pointer;
260 | }
261 |
262 | .gitment-comment-body-folded::before {
263 | display: block !important;
264 | content: "";
265 | position: absolute;
266 | width: 100%;
267 | left: 0;
268 | top: 0;
269 | bottom: 50px;
270 | pointer-events: none;
271 | background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0), rgba(255, 255, 255, .9));
272 | background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, .9));
273 | }
274 |
275 | .gitment-comment-body-folded::after {
276 | display: block !important;
277 | content: "Click to Expand" !important;
278 | text-align: center;
279 | color: #666;
280 | position: absolute;
281 | width: 100%;
282 | height: 50px;
283 | line-height: 50px;
284 | left: 0;
285 | bottom: 0;
286 | pointer-events: none;
287 | background: rgba(255, 255, 255, .9);
288 | }
289 |
290 | .gitment-editor-body {
291 | margin: 0;
292 | }
293 |
294 | .gitment-comment-body > *:first-child,
295 | .gitment-editor-preview > *:first-child {
296 | margin-top: 0 !important;
297 | }
298 |
299 | .gitment-comment-body > *:last-child,
300 | .gitment-editor-preview > *:last-child {
301 | margin-bottom: 0 !important;
302 | }
303 |
304 | .gitment-editor-body textarea {
305 | display: block;
306 | width: 100%;
307 | min-height: 150px;
308 | max-height: 500px;
309 | padding: 16px;
310 | resize: vertical;
311 |
312 | max-width: 100%;
313 | margin: 0;
314 | font-size: 14px;
315 | line-height: 1.6;
316 |
317 | background-color: #fff;
318 |
319 | color: #333;
320 | vertical-align: middle;
321 | border: none;
322 | border-radius: 0;
323 | outline: none;
324 | box-shadow: none;
325 |
326 | overflow: visible;
327 | }
328 |
329 | .gitment-editor-body textarea:focus {
330 | background-color: #fff;
331 | }
332 |
333 | .gitment-editor-preview {
334 | min-height: 150px;
335 |
336 | padding: 16px;
337 | background-color: transparent;
338 |
339 | width: 100%;
340 | font-size: 14px;
341 |
342 | line-height: 1.5;
343 | word-wrap: break-word;
344 | }
345 |
346 | .gitment-editor-footer {
347 | padding: 0;
348 | margin-top: 10px;
349 | }
350 |
351 | .gitment-editor-footer::after {
352 | display: table;
353 | clear: both;
354 | content: "";
355 | }
356 |
357 | a.gitment-editor-footer-tip {
358 | display: inline-block;
359 | padding-top: 10px;
360 | font-size: 12px;
361 | color: #666;
362 | }
363 |
364 | a.gitment-editor-footer-tip:hover {
365 | color: #2196F3;
366 | text-decoration: none;
367 | }
368 |
369 | .gitment-comments-pagination {
370 | list-style: none;
371 | text-align: right;
372 | border-radius: 0;
373 | margin: -19px 0 19px 0;
374 | }
375 |
376 | .gitment-comments-page-item {
377 | display: inline-block;
378 | cursor: pointer;
379 | border: 1px solid #CFD8DC;
380 | margin-left: -1px;
381 | padding: .25rem .5rem;
382 | }
383 |
384 | .gitment-comments-page-item:hover {
385 | background-color: #f5f5f5;
386 | }
387 |
388 | .gitment-comments-page-item.gitment-selected {
389 | background-color: #f5f5f5;
390 | }
391 |
392 | .gitment-editor-submit,
393 | .gitment-comments-init-btn {
394 | color: #fff;
395 | background-color: #32d1c1;
396 |
397 | position: relative;
398 | display: inline-block;
399 | padding: 7px 13px;
400 | font-size: 14px;
401 | font-weight: 600;
402 | line-height: 20px;
403 | white-space: nowrap;
404 | vertical-align: middle;
405 | cursor: pointer;
406 | -webkit-user-select: none;
407 | -moz-user-select: none;
408 | -ms-user-select: none;
409 | user-select: none;
410 | background-size: 110% 110%;
411 | border: none;
412 | -webkit-appearance: none;
413 | -moz-appearance: none;
414 | appearance: none;
415 | }
416 |
417 | .gitment-editor-submit:hover,
418 | .gitment-comments-init-btn:hover {
419 | background-color: #32d3c3;
420 | }
421 |
422 | .gitment-comments-init-btn:disabled,
423 | .gitment-editor-submit:disabled {
424 | color: rgba(255,255,255,0.75);
425 | background-color: #4DD0E1;
426 | box-shadow: none;
427 | }
428 |
429 | .gitment-editor-submit {
430 | float: right;
431 | }
432 |
433 | .gitment-footer-container {
434 | margin-top: 30px;
435 | margin-bottom: 20px;
436 | text-align: right;
437 | font-size: 12px;
438 | }
439 |
440 | /*
441 | * Markdown CSS
442 | * Copied from https://github.com/sindresorhus/github-markdown-css
443 | */
444 | .gitment-markdown {
445 | -ms-text-size-adjust: 100%;
446 | -webkit-text-size-adjust: 100%;
447 | line-height: 1.5;
448 | color: #333;
449 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
450 | font-size: 16px;
451 | line-height: 1.5;
452 | word-wrap: break-word;
453 | }
454 |
455 | .gitment-markdown .pl-c {
456 | color: #969896;
457 | }
458 |
459 | .gitment-markdown .pl-c1,
460 | .gitment-markdown .pl-s .pl-v {
461 | color: #0086b3;
462 | }
463 |
464 | .gitment-markdown .pl-e,
465 | .gitment-markdown .pl-en {
466 | color: #795da3;
467 | }
468 |
469 | .gitment-markdown .pl-smi,
470 | .gitment-markdown .pl-s .pl-s1 {
471 | color: #333;
472 | }
473 |
474 | .gitment-markdown .pl-ent {
475 | color: #63a35c;
476 | }
477 |
478 | .gitment-markdown .pl-k {
479 | color: #a71d5d;
480 | }
481 |
482 | .gitment-markdown .pl-s,
483 | .gitment-markdown .pl-pds,
484 | .gitment-markdown .pl-s .pl-pse .pl-s1,
485 | .gitment-markdown .pl-sr,
486 | .gitment-markdown .pl-sr .pl-cce,
487 | .gitment-markdown .pl-sr .pl-sre,
488 | .gitment-markdown .pl-sr .pl-sra {
489 | color: #183691;
490 | }
491 |
492 | .gitment-markdown .pl-v,
493 | .gitment-markdown .pl-smw {
494 | color: #ed6a43;
495 | }
496 |
497 | .gitment-markdown .pl-bu {
498 | color: #b52a1d;
499 | }
500 |
501 | .gitment-markdown .pl-ii {
502 | color: #f8f8f8;
503 | background-color: #b52a1d;
504 | }
505 |
506 | .gitment-markdown .pl-c2 {
507 | color: #f8f8f8;
508 | background-color: #b52a1d;
509 | }
510 |
511 | .gitment-markdown .pl-c2::before {
512 | content: "^M";
513 | }
514 |
515 | .gitment-markdown .pl-sr .pl-cce {
516 | font-weight: bold;
517 | color: #63a35c;
518 | }
519 |
520 | .gitment-markdown .pl-ml {
521 | color: #693a17;
522 | }
523 |
524 | .gitment-markdown .pl-mh,
525 | .gitment-markdown .pl-mh .pl-en,
526 | .gitment-markdown .pl-ms {
527 | font-weight: bold;
528 | color: #1d3e81;
529 | }
530 |
531 | .gitment-markdown .pl-mq {
532 | color: #008080;
533 | }
534 |
535 | .gitment-markdown .pl-mi {
536 | font-style: italic;
537 | color: #333;
538 | }
539 |
540 | .gitment-markdown .pl-mb {
541 | font-weight: bold;
542 | color: #333;
543 | }
544 |
545 | .gitment-markdown .pl-md {
546 | color: #bd2c00;
547 | background-color: #ffecec;
548 | }
549 |
550 | .gitment-markdown .pl-mi1 {
551 | color: #55a532;
552 | background-color: #eaffea;
553 | }
554 |
555 | .gitment-markdown .pl-mc {
556 | color: #ef9700;
557 | background-color: #ffe3b4;
558 | }
559 |
560 | .gitment-markdown .pl-mi2 {
561 | color: #d8d8d8;
562 | background-color: #808080;
563 | }
564 |
565 | .gitment-markdown .pl-mdr {
566 | font-weight: bold;
567 | color: #795da3;
568 | }
569 |
570 | .gitment-markdown .pl-mo {
571 | color: #1d3e81;
572 | }
573 |
574 | .gitment-markdown .pl-ba {
575 | color: #595e62;
576 | }
577 |
578 | .gitment-markdown .pl-sg {
579 | color: #c0c0c0;
580 | }
581 |
582 | .gitment-markdown .pl-corl {
583 | text-decoration: underline;
584 | color: #183691;
585 | }
586 |
587 | .gitment-markdown .octicon {
588 | display: inline-block;
589 | vertical-align: text-top;
590 | fill: currentColor;
591 | }
592 |
593 | .gitment-markdown a {
594 | background-color: transparent;
595 | -webkit-text-decoration-skip: objects;
596 | }
597 |
598 | .gitment-markdown a:active,
599 | .gitment-markdown a:hover {
600 | outline-width: 0;
601 | }
602 |
603 | .gitment-markdown strong {
604 | font-weight: inherit;
605 | }
606 |
607 | .gitment-markdown strong {
608 | font-weight: bolder;
609 | }
610 |
611 | .gitment-markdown h1 {
612 | font-size: 2em;
613 | margin: 0.67em 0;
614 | }
615 |
616 | .gitment-markdown img {
617 | border-style: none;
618 | }
619 |
620 | .gitment-markdown svg:not(:root) {
621 | overflow: hidden;
622 | }
623 |
624 | .gitment-markdown code,
625 | .gitment-markdown kbd,
626 | .gitment-markdown pre {
627 | font-family: monospace, monospace;
628 | font-size: 1em;
629 | }
630 |
631 | .gitment-markdown hr {
632 | box-sizing: content-box;
633 | height: 0;
634 | overflow: visible;
635 | }
636 |
637 | .gitment-markdown input {
638 | font: inherit;
639 | margin: 0;
640 | }
641 |
642 | .gitment-markdown input {
643 | overflow: visible;
644 | }
645 |
646 | .gitment-markdown [type="checkbox"] {
647 | box-sizing: border-box;
648 | padding: 0;
649 | }
650 |
651 | .gitment-markdown * {
652 | box-sizing: border-box;
653 | }
654 |
655 | .gitment-markdown input {
656 | font-family: inherit;
657 | font-size: inherit;
658 | line-height: inherit;
659 | }
660 |
661 | .gitment-markdown a {
662 | color: #0366d6;
663 | text-decoration: none;
664 | }
665 |
666 | .gitment-markdown a:hover {
667 | text-decoration: underline;
668 | }
669 |
670 | .gitment-markdown strong {
671 | font-weight: 600;
672 | }
673 |
674 | .gitment-markdown hr {
675 | height: 0;
676 | margin: 15px 0;
677 | overflow: hidden;
678 | background: transparent;
679 | border: 0;
680 | border-bottom: 1px solid #dfe2e5;
681 | }
682 |
683 | .gitment-markdown hr::before {
684 | display: table;
685 | content: "";
686 | }
687 |
688 | .gitment-markdown hr::after {
689 | display: table;
690 | clear: both;
691 | content: "";
692 | }
693 |
694 | .gitment-markdown table {
695 | border-spacing: 0;
696 | border-collapse: collapse;
697 | }
698 |
699 | .gitment-markdown td,
700 | .gitment-markdown th {
701 | padding: 0;
702 | }
703 |
704 | .gitment-markdown h1,
705 | .gitment-markdown h2,
706 | .gitment-markdown h3,
707 | .gitment-markdown h4,
708 | .gitment-markdown h5,
709 | .gitment-markdown h6 {
710 | margin-top: 0;
711 | margin-bottom: 0;
712 | }
713 |
714 | .gitment-markdown h1 {
715 | font-size: 32px;
716 | font-weight: 600;
717 | }
718 |
719 | .gitment-markdown h2 {
720 | font-size: 24px;
721 | font-weight: 600;
722 | }
723 |
724 | .gitment-markdown h3 {
725 | font-size: 20px;
726 | font-weight: 600;
727 | }
728 |
729 | .gitment-markdown h4 {
730 | font-size: 16px;
731 | font-weight: 600;
732 | }
733 |
734 | .gitment-markdown h5 {
735 | font-size: 14px;
736 | font-weight: 600;
737 | }
738 |
739 | .gitment-markdown h6 {
740 | font-size: 12px;
741 | font-weight: 600;
742 | }
743 |
744 | .gitment-markdown p {
745 | margin-top: 0;
746 | margin-bottom: 10px;
747 | }
748 |
749 | .gitment-markdown blockquote {
750 | margin: 0;
751 | }
752 |
753 | .gitment-markdown ul,
754 | .gitment-markdown ol {
755 | padding-left: 0;
756 | margin-top: 0;
757 | margin-bottom: 0;
758 | }
759 |
760 | .gitment-markdown ol ol,
761 | .gitment-markdown ul ol {
762 | list-style-type: lower-roman;
763 | }
764 |
765 | .gitment-markdown ul ul ol,
766 | .gitment-markdown ul ol ol,
767 | .gitment-markdown ol ul ol,
768 | .gitment-markdown ol ol ol {
769 | list-style-type: lower-alpha;
770 | }
771 |
772 | .gitment-markdown dd {
773 | margin-left: 0;
774 | }
775 |
776 | .gitment-markdown code {
777 | font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
778 | font-size: 12px;
779 | }
780 |
781 | .gitment-markdown pre {
782 | margin-top: 0;
783 | margin-bottom: 0;
784 | font: 12px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
785 | }
786 |
787 | .gitment-markdown .octicon {
788 | vertical-align: text-bottom;
789 | }
790 |
791 | .gitment-markdown .pl-0 {
792 | padding-left: 0 !important;
793 | }
794 |
795 | .gitment-markdown .pl-1 {
796 | padding-left: 4px !important;
797 | }
798 |
799 | .gitment-markdown .pl-2 {
800 | padding-left: 8px !important;
801 | }
802 |
803 | .gitment-markdown .pl-3 {
804 | padding-left: 16px !important;
805 | }
806 |
807 | .gitment-markdown .pl-4 {
808 | padding-left: 24px !important;
809 | }
810 |
811 | .gitment-markdown .pl-5 {
812 | padding-left: 32px !important;
813 | }
814 |
815 | .gitment-markdown .pl-6 {
816 | padding-left: 40px !important;
817 | }
818 |
819 | .gitment-markdown::before {
820 | display: table;
821 | content: "";
822 | }
823 |
824 | .gitment-markdown::after {
825 | display: table;
826 | clear: both;
827 | content: "";
828 | }
829 |
830 | .gitment-markdown>*:first-child {
831 | margin-top: 0 !important;
832 | }
833 |
834 | .gitment-markdown>*:last-child {
835 | margin-bottom: 0 !important;
836 | }
837 |
838 | .gitment-markdown a:not([href]) {
839 | color: inherit;
840 | text-decoration: none;
841 | }
842 |
843 | .gitment-markdown .anchor {
844 | float: left;
845 | padding-right: 4px;
846 | margin-left: -20px;
847 | line-height: 1;
848 | }
849 |
850 | .gitment-markdown .anchor:focus {
851 | outline: none;
852 | }
853 |
854 | .gitment-markdown p,
855 | .gitment-markdown blockquote,
856 | .gitment-markdown ul,
857 | .gitment-markdown ol,
858 | .gitment-markdown dl,
859 | .gitment-markdown table,
860 | .gitment-markdown pre {
861 | margin-top: 0;
862 | margin-bottom: 16px;
863 | }
864 |
865 | .gitment-markdown hr {
866 | height: 0.25em;
867 | padding: 0;
868 | margin: 24px 0;
869 | background-color: #e1e4e8;
870 | border: 0;
871 | }
872 |
873 | .gitment-markdown blockquote {
874 | padding: 0 1em;
875 | color: #6a737d;
876 | border-left: 0.25em solid #dfe2e5;
877 | }
878 |
879 | .gitment-markdown blockquote>:first-child {
880 | margin-top: 0;
881 | }
882 |
883 | .gitment-markdown blockquote>:last-child {
884 | margin-bottom: 0;
885 | }
886 |
887 | .gitment-markdown kbd {
888 | display: inline-block;
889 | padding: 3px 5px;
890 | font-size: 11px;
891 | line-height: 10px;
892 | color: #444d56;
893 | vertical-align: middle;
894 | background-color: #fafbfc;
895 | border: solid 1px #c6cbd1;
896 | border-bottom-color: #959da5;
897 | border-radius: 0;
898 | box-shadow: inset 0 -1px 0 #959da5;
899 | }
900 |
901 | .gitment-markdown h1,
902 | .gitment-markdown h2,
903 | .gitment-markdown h3,
904 | .gitment-markdown h4,
905 | .gitment-markdown h5,
906 | .gitment-markdown h6 {
907 | margin-top: 24px;
908 | margin-bottom: 16px;
909 | font-weight: 600;
910 | line-height: 1.25;
911 | }
912 |
913 | .gitment-markdown h1 .octicon-link,
914 | .gitment-markdown h2 .octicon-link,
915 | .gitment-markdown h3 .octicon-link,
916 | .gitment-markdown h4 .octicon-link,
917 | .gitment-markdown h5 .octicon-link,
918 | .gitment-markdown h6 .octicon-link {
919 | color: #1b1f23;
920 | vertical-align: middle;
921 | visibility: hidden;
922 | }
923 |
924 | .gitment-markdown h1:hover .anchor,
925 | .gitment-markdown h2:hover .anchor,
926 | .gitment-markdown h3:hover .anchor,
927 | .gitment-markdown h4:hover .anchor,
928 | .gitment-markdown h5:hover .anchor,
929 | .gitment-markdown h6:hover .anchor {
930 | text-decoration: none;
931 | }
932 |
933 | .gitment-markdown h1:hover .anchor .octicon-link,
934 | .gitment-markdown h2:hover .anchor .octicon-link,
935 | .gitment-markdown h3:hover .anchor .octicon-link,
936 | .gitment-markdown h4:hover .anchor .octicon-link,
937 | .gitment-markdown h5:hover .anchor .octicon-link,
938 | .gitment-markdown h6:hover .anchor .octicon-link {
939 | visibility: visible;
940 | }
941 |
942 | .gitment-markdown h1 {
943 | padding-bottom: 0.3em;
944 | font-size: 2em;
945 | border-bottom: 1px solid #eaecef;
946 | }
947 |
948 | .gitment-markdown h2 {
949 | padding-bottom: 0.3em;
950 | font-size: 1.5em;
951 | border-bottom: 1px solid #eaecef;
952 | }
953 |
954 | .gitment-markdown h3 {
955 | font-size: 1.25em;
956 | }
957 |
958 | .gitment-markdown h4 {
959 | font-size: 1em;
960 | }
961 |
962 | .gitment-markdown h5 {
963 | font-size: 0.875em;
964 | }
965 |
966 | .gitment-markdown h6 {
967 | font-size: 0.85em;
968 | color: #6a737d;
969 | }
970 |
971 | .gitment-markdown ul,
972 | .gitment-markdown ol {
973 | padding-left: 2em;
974 | }
975 |
976 | .gitment-markdown ul ul,
977 | .gitment-markdown ul ol,
978 | .gitment-markdown ol ol,
979 | .gitment-markdown ol ul {
980 | margin-top: 0;
981 | margin-bottom: 0;
982 | }
983 |
984 | .gitment-markdown li>p {
985 | margin-top: 16px;
986 | }
987 |
988 | .gitment-markdown li+li {
989 | margin-top: 0.25em;
990 | }
991 |
992 | .gitment-markdown dl {
993 | padding: 0;
994 | }
995 |
996 | .gitment-markdown dl dt {
997 | padding: 0;
998 | margin-top: 16px;
999 | font-size: 1em;
1000 | font-style: italic;
1001 | font-weight: 600;
1002 | }
1003 |
1004 | .gitment-markdown dl dd {
1005 | padding: 0 16px;
1006 | margin-bottom: 16px;
1007 | }
1008 |
1009 | .gitment-markdown table {
1010 | display: block;
1011 | width: 100%;
1012 | overflow: auto;
1013 | }
1014 |
1015 | .gitment-markdown table th {
1016 | font-weight: 600;
1017 | }
1018 |
1019 | .gitment-markdown table th,
1020 | .gitment-markdown table td {
1021 | padding: 6px 13px;
1022 | border: 1px solid #dfe2e5;
1023 | }
1024 |
1025 | .gitment-markdown table tr {
1026 | background-color: #fff;
1027 | border-top: 1px solid #c6cbd1;
1028 | }
1029 |
1030 | .gitment-markdown table tr:nth-child(2n) {
1031 | background-color: #f5f5f5;
1032 | }
1033 |
1034 | .gitment-markdown img {
1035 | max-width: 100%;
1036 | box-sizing: content-box;
1037 | background-color: #fff;
1038 | }
1039 |
1040 | .gitment-markdown code {
1041 | padding: 0;
1042 | padding-top: 0.2em;
1043 | padding-bottom: 0.2em;
1044 | margin: 0;
1045 | font-size: 85%;
1046 | background-color: rgba(27,31,35,0.05);
1047 | border-radius: 0;
1048 | }
1049 |
1050 | .gitment-markdown code::before,
1051 | .gitment-markdown code::after {
1052 | letter-spacing: -0.2em;
1053 | content: "\00a0";
1054 | }
1055 |
1056 | .gitment-markdown pre {
1057 | word-wrap: normal;
1058 | }
1059 |
1060 | .gitment-markdown pre>code {
1061 | padding: 0;
1062 | margin: 0;
1063 | font-size: 100%;
1064 | word-break: normal;
1065 | white-space: pre;
1066 | background: transparent;
1067 | border: 0;
1068 | }
1069 |
1070 | .gitment-markdown .highlight {
1071 | margin-bottom: 16px;
1072 | }
1073 |
1074 | .gitment-markdown .highlight pre {
1075 | margin-bottom: 0;
1076 | word-break: normal;
1077 | }
1078 |
1079 | .gitment-markdown .highlight pre,
1080 | .gitment-markdown pre {
1081 | padding: 16px;
1082 | overflow: auto;
1083 | font-size: 85%;
1084 | line-height: 1.45;
1085 | background-color: #f5f5f5;
1086 | border-radius: 0;
1087 | }
1088 |
1089 | .gitment-markdown pre code {
1090 | display: inline;
1091 | max-width: auto;
1092 | padding: 0;
1093 | margin: 0;
1094 | overflow: visible;
1095 | line-height: inherit;
1096 | word-wrap: normal;
1097 | background-color: transparent;
1098 | border: 0;
1099 | }
1100 |
1101 | .gitment-markdown pre code::before,
1102 | .gitment-markdown pre code::after {
1103 | content: normal;
1104 | }
1105 |
1106 | .gitment-markdown .full-commit .btn-outline:not(:disabled):hover {
1107 | color: #005cc5;
1108 | border-color: #005cc5;
1109 | }
1110 |
1111 | .gitment-markdown kbd {
1112 | display: inline-block;
1113 | padding: 3px 5px;
1114 | font: 11px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
1115 | line-height: 10px;
1116 | color: #444d56;
1117 | vertical-align: middle;
1118 | background-color: #fcfcfc;
1119 | border: solid 1px #c6cbd1;
1120 | border-bottom-color: #959da5;
1121 | border-radius: 0;
1122 | box-shadow: inset 0 -1px 0 #959da5;
1123 | }
1124 |
1125 | .gitment-markdown :checked+.radio-label {
1126 | position: relative;
1127 | z-index: 1;
1128 | border-color: #0366d6;
1129 | }
1130 |
1131 | .gitment-markdown .task-list-item {
1132 | list-style-type: none;
1133 | }
1134 |
1135 | .gitment-markdown .task-list-item+.task-list-item {
1136 | margin-top: 3px;
1137 | }
1138 |
1139 | .gitment-markdown .task-list-item input {
1140 | margin: 0 0.2em 0.25em -1.6em;
1141 | vertical-align: middle;
1142 | }
1143 |
1144 | .gitment-markdown hr {
1145 | border-bottom-color: #eee;
1146 | }
1147 |
--------------------------------------------------------------------------------
/assets/gitment/gitment.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4 |
5 | var _mobx = require('mobx');
6 |
7 | var _constants = require('./constants');
8 |
9 | var _utils = require('./utils');
10 |
11 | var _default = require('./theme/default');
12 |
13 | var _default2 = _interopRequireDefault(_default);
14 |
15 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16 |
17 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18 |
19 | var scope = 'public_repo';
20 |
21 | function extendRenderer(instance, renderer) {
22 | instance[renderer] = function (container) {
23 | var targetContainer = (0, _utils.getTargetContainer)(container);
24 | var render = instance.theme[renderer] || instance.defaultTheme[renderer];
25 |
26 | (0, _mobx.autorun)(function () {
27 | var e = render(instance.state, instance);
28 | if (targetContainer.firstChild) {
29 | targetContainer.replaceChild(e, targetContainer.firstChild);
30 | } else {
31 | targetContainer.appendChild(e);
32 | }
33 | });
34 |
35 | return targetContainer;
36 | };
37 | }
38 |
39 | var Gitment = function () {
40 | _createClass(Gitment, [{
41 | key: 'accessToken',
42 | get: function get() {
43 | return localStorage.getItem(_constants.LS_ACCESS_TOKEN_KEY);
44 | },
45 | set: function set(token) {
46 | localStorage.setItem(_constants.LS_ACCESS_TOKEN_KEY, token);
47 | }
48 | }, {
49 | key: 'loginLink',
50 | get: function get() {
51 | var oauthUri = 'https://github.com/login/oauth/authorize';
52 | var redirect_uri = this.oauth.redirect_uri || window.location.href;
53 |
54 | var oauthParams = Object.assign({
55 | scope: scope,
56 | redirect_uri: redirect_uri
57 | }, this.oauth);
58 |
59 | return '' + oauthUri + _utils.Query.stringify(oauthParams);
60 | }
61 | }]);
62 |
63 | function Gitment() {
64 | var _this = this;
65 |
66 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
67 |
68 | _classCallCheck(this, Gitment);
69 |
70 | this.defaultTheme = _default2.default;
71 | this.useTheme(_default2.default);
72 |
73 | Object.assign(this, {
74 | id: window.location.href,
75 | title: window.document.title,
76 | link: window.location.href,
77 | desc: '',
78 | labels: [],
79 | theme: _default2.default,
80 | oauth: {},
81 | perPage: 20,
82 | maxCommentHeight: 250
83 | }, options);
84 |
85 | this.useTheme(this.theme);
86 |
87 | var user = {};
88 | try {
89 | var userInfo = localStorage.getItem(_constants.LS_USER_KEY);
90 | if (this.accessToken && userInfo) {
91 | Object.assign(user, JSON.parse(userInfo), {
92 | fromCache: true
93 | });
94 | }
95 | } catch (e) {
96 | localStorage.removeItem(_constants.LS_USER_KEY);
97 | }
98 |
99 | this.state = (0, _mobx.observable)({
100 | user: user,
101 | error: null,
102 | meta: {},
103 | comments: undefined,
104 | reactions: [],
105 | commentReactions: {},
106 | currentPage: 1
107 | });
108 |
109 | var query = _utils.Query.parse();
110 | if (query.code) {
111 | var _oauth = this.oauth,
112 | client_id = _oauth.client_id,
113 | client_secret = _oauth.client_secret;
114 |
115 | var code = query.code;
116 | delete query.code;
117 | var search = _utils.Query.stringify(query);
118 | var replacedUrl = '' + window.location.origin + window.location.pathname + search + window.location.hash;
119 | history.replaceState({}, '', replacedUrl);
120 |
121 | Object.assign(this, {
122 | id: replacedUrl,
123 | link: replacedUrl
124 | }, options);
125 |
126 | this.state.user.isLoggingIn = true;
127 | _utils.http.post('https://gh-oauth.imsun.net', {
128 | code: code,
129 | client_id: client_id,
130 | client_secret: client_secret
131 | }, '').then(function (data) {
132 | _this.accessToken = data.access_token;
133 | _this.update();
134 | }).catch(function (e) {
135 | _this.state.user.isLoggingIn = false;
136 | alert(e);
137 | });
138 | } else {
139 | this.update();
140 | }
141 | }
142 |
143 | _createClass(Gitment, [{
144 | key: 'init',
145 | value: function init() {
146 | var _this2 = this;
147 |
148 | return this.createIssue().then(function () {
149 | return _this2.loadComments();
150 | }).then(function (comments) {
151 | _this2.state.error = null;
152 | return comments;
153 | });
154 | }
155 | }, {
156 | key: 'useTheme',
157 | value: function useTheme() {
158 | var _this3 = this;
159 |
160 | var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
161 |
162 | this.theme = theme;
163 |
164 | var renderers = Object.keys(this.theme);
165 | renderers.forEach(function (renderer) {
166 | return extendRenderer(_this3, renderer);
167 | });
168 | }
169 | }, {
170 | key: 'update',
171 | value: function update() {
172 | var _this4 = this;
173 |
174 | return Promise.all([this.loadMeta(), this.loadUserInfo()]).then(function () {
175 | return Promise.all([_this4.loadComments().then(function () {
176 | return _this4.loadCommentReactions();
177 | }), _this4.loadReactions()]);
178 | }).catch(function (e) {
179 | return _this4.state.error = e;
180 | });
181 | }
182 | }, {
183 | key: 'markdown',
184 | value: function markdown(text) {
185 | return _utils.http.post('/markdown', {
186 | text: text,
187 | mode: 'gfm'
188 | });
189 | }
190 | }, {
191 | key: 'createIssue',
192 | value: function createIssue() {
193 | var _this5 = this;
194 |
195 | var id = this.id,
196 | owner = this.owner,
197 | repo = this.repo,
198 | title = this.title,
199 | link = this.link,
200 | desc = this.desc,
201 | labels = this.labels;
202 |
203 |
204 | return _utils.http.post('/repos/' + owner + '/' + repo + '/issues', {
205 | title: title,
206 | labels: labels.concat(['gitment', id]),
207 | body: link + '\n\n' + desc
208 | }).then(function (meta) {
209 | _this5.state.meta = meta;
210 | return meta;
211 | });
212 | }
213 | }, {
214 | key: 'getIssue',
215 | value: function getIssue() {
216 | if (this.state.meta.id) return Promise.resolve(this.state.meta);
217 |
218 | return this.loadMeta();
219 | }
220 | }, {
221 | key: 'post',
222 | value: function post(body) {
223 | var _this6 = this;
224 |
225 | return this.getIssue().then(function (issue) {
226 | return _utils.http.post(issue.comments_url, { body: body }, '');
227 | }).then(function (data) {
228 | _this6.state.meta.comments++;
229 | var pageCount = Math.ceil(_this6.state.meta.comments / _this6.perPage);
230 | if (_this6.state.currentPage === pageCount) {
231 | _this6.state.comments.push(data);
232 | }
233 | return data;
234 | });
235 | }
236 | }, {
237 | key: 'loadMeta',
238 | value: function loadMeta() {
239 | var _this7 = this;
240 |
241 | var id = this.id,
242 | owner = this.owner,
243 | repo = this.repo;
244 |
245 | return _utils.http.get('/repos/' + owner + '/' + repo + '/issues', {
246 | creator: owner,
247 | labels: id
248 | }).then(function (issues) {
249 | if (!issues.length) return Promise.reject(_constants.NOT_INITIALIZED_ERROR);
250 | _this7.state.meta = issues[0];
251 | return issues[0];
252 | });
253 | }
254 | }, {
255 | key: 'loadComments',
256 | value: function loadComments() {
257 | var _this8 = this;
258 |
259 | var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.currentPage;
260 |
261 | return this.getIssue().then(function (issue) {
262 | return _utils.http.get(issue.comments_url, { page: page, per_page: _this8.perPage }, '');
263 | }).then(function (comments) {
264 | _this8.state.comments = comments;
265 | return comments;
266 | });
267 | }
268 | }, {
269 | key: 'loadUserInfo',
270 | value: function loadUserInfo() {
271 | var _this9 = this;
272 |
273 | if (!this.accessToken) {
274 | this.logout();
275 | return Promise.resolve({});
276 | }
277 |
278 | return _utils.http.get('/user').then(function (user) {
279 | _this9.state.user = user;
280 | localStorage.setItem(_constants.LS_USER_KEY, JSON.stringify(user));
281 | return user;
282 | });
283 | }
284 | }, {
285 | key: 'loadReactions',
286 | value: function loadReactions() {
287 | var _this10 = this;
288 |
289 | if (!this.accessToken) {
290 | this.state.reactions = [];
291 | return Promise.resolve([]);
292 | }
293 |
294 | return this.getIssue().then(function (issue) {
295 | if (!issue.reactions.total_count) return [];
296 | return _utils.http.get(issue.reactions.url, {}, '');
297 | }).then(function (reactions) {
298 | _this10.state.reactions = reactions;
299 | return reactions;
300 | });
301 | }
302 | }, {
303 | key: 'loadCommentReactions',
304 | value: function loadCommentReactions() {
305 | var _this11 = this;
306 |
307 | if (!this.accessToken) {
308 | this.state.commentReactions = {};
309 | return Promise.resolve([]);
310 | }
311 |
312 | var comments = this.state.comments;
313 | var comentReactions = {};
314 |
315 | return Promise.all(comments.map(function (comment) {
316 | if (!comment.reactions.total_count) return [];
317 |
318 | var owner = _this11.owner,
319 | repo = _this11.repo;
320 |
321 | return _utils.http.get('/repos/' + owner + '/' + repo + '/issues/comments/' + comment.id + '/reactions', {});
322 | })).then(function (reactionsArray) {
323 | comments.forEach(function (comment, index) {
324 | comentReactions[comment.id] = reactionsArray[index];
325 | });
326 | _this11.state.commentReactions = comentReactions;
327 |
328 | return comentReactions;
329 | });
330 | }
331 | }, {
332 | key: 'login',
333 | value: function login() {
334 | window.location.href = this.loginLink;
335 | }
336 | }, {
337 | key: 'logout',
338 | value: function logout() {
339 | localStorage.removeItem(_constants.LS_ACCESS_TOKEN_KEY);
340 | localStorage.removeItem(_constants.LS_USER_KEY);
341 | this.state.user = {};
342 | }
343 | }, {
344 | key: 'goto',
345 | value: function goto(page) {
346 | this.state.currentPage = page;
347 | this.state.comments = undefined;
348 | return this.loadComments(page);
349 | }
350 | }, {
351 | key: 'like',
352 | value: function like() {
353 | var _this12 = this;
354 |
355 | if (!this.accessToken) {
356 | alert('Login to Like');
357 | return Promise.reject();
358 | }
359 |
360 | var owner = this.owner,
361 | repo = this.repo;
362 |
363 |
364 | return _utils.http.post('/repos/' + owner + '/' + repo + '/issues/' + this.state.meta.number + '/reactions', {
365 | content: 'heart'
366 | }).then(function (reaction) {
367 | _this12.state.reactions.push(reaction);
368 | _this12.state.meta.reactions.heart++;
369 | });
370 | }
371 | }, {
372 | key: 'unlike',
373 | value: function unlike() {
374 | var _this13 = this;
375 |
376 | if (!this.accessToken) return Promise.reject();
377 |
378 | var _state = this.state,
379 | user = _state.user,
380 | reactions = _state.reactions;
381 |
382 | var index = reactions.findIndex(function (reaction) {
383 | return reaction.user.login === user.login;
384 | });
385 | return _utils.http.delete('/reactions/' + reactions[index].id).then(function () {
386 | reactions.splice(index, 1);
387 | _this13.state.meta.reactions.heart--;
388 | });
389 | }
390 | }, {
391 | key: 'likeAComment',
392 | value: function likeAComment(commentId) {
393 | var _this14 = this;
394 |
395 | if (!this.accessToken) {
396 | alert('Login to Like');
397 | return Promise.reject();
398 | }
399 |
400 | var owner = this.owner,
401 | repo = this.repo;
402 |
403 | var comment = this.state.comments.find(function (comment) {
404 | return comment.id === commentId;
405 | });
406 |
407 | return _utils.http.post('/repos/' + owner + '/' + repo + '/issues/comments/' + commentId + '/reactions', {
408 | content: 'heart'
409 | }).then(function (reaction) {
410 | _this14.state.commentReactions[commentId].push(reaction);
411 | comment.reactions.heart++;
412 | });
413 | }
414 | }, {
415 | key: 'unlikeAComment',
416 | value: function unlikeAComment(commentId) {
417 | if (!this.accessToken) return Promise.reject();
418 |
419 | var reactions = this.state.commentReactions[commentId];
420 | var comment = this.state.comments.find(function (comment) {
421 | return comment.id === commentId;
422 | });
423 | var user = this.state.user;
424 |
425 | var index = reactions.findIndex(function (reaction) {
426 | return reaction.user.login === user.login;
427 | });
428 |
429 | return _utils.http.delete('/reactions/' + reactions[index].id).then(function () {
430 | reactions.splice(index, 1);
431 | comment.reactions.heart--;
432 | });
433 | }
434 | }]);
435 |
436 | return Gitment;
437 | }();
438 |
439 | module.exports = Gitment;
440 | //# sourceMappingURL=gitment.js.map
--------------------------------------------------------------------------------
/assets/gitment/gitment.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":["../src/gitment.js"],"names":["scope","extendRenderer","instance","renderer","container","targetContainer","render","theme","defaultTheme","e","state","firstChild","replaceChild","appendChild","Gitment","localStorage","getItem","token","setItem","oauthUri","redirect_uri","oauth","window","location","href","oauthParams","Object","assign","stringify","options","useTheme","id","title","document","link","desc","labels","perPage","maxCommentHeight","user","userInfo","accessToken","JSON","parse","fromCache","removeItem","error","meta","comments","undefined","reactions","commentReactions","currentPage","query","code","client_id","client_secret","search","replacedUrl","origin","pathname","hash","history","replaceState","isLoggingIn","post","then","data","access_token","update","catch","alert","createIssue","loadComments","renderers","keys","forEach","Promise","all","loadMeta","loadUserInfo","loadCommentReactions","loadReactions","text","mode","owner","repo","concat","body","resolve","getIssue","issue","comments_url","pageCount","Math","ceil","push","get","creator","issues","length","reject","page","per_page","logout","total_count","url","comentReactions","map","comment","index","reactionsArray","loginLink","number","content","reaction","heart","findIndex","login","delete","splice","commentId","find","module","exports"],"mappings":";;;;AAAA;;AAEA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,QAAQ,aAAd;;AAEA,SAASC,cAAT,CAAwBC,QAAxB,EAAkCC,QAAlC,EAA4C;AAC1CD,WAASC,QAAT,IAAqB,UAACC,SAAD,EAAe;AAClC,QAAMC,kBAAkB,+BAAmBD,SAAnB,CAAxB;AACA,QAAME,SAASJ,SAASK,KAAT,CAAeJ,QAAf,KAA4BD,SAASM,YAAT,CAAsBL,QAAtB,CAA3C;;AAEA,uBAAQ,YAAM;AACZ,UAAMM,IAAIH,OAAOJ,SAASQ,KAAhB,EAAuBR,QAAvB,CAAV;AACA,UAAIG,gBAAgBM,UAApB,EAAgC;AAC9BN,wBAAgBO,YAAhB,CAA6BH,CAA7B,EAAgCJ,gBAAgBM,UAAhD;AACD,OAFD,MAEO;AACLN,wBAAgBQ,WAAhB,CAA4BJ,CAA5B;AACD;AACF,KAPD;;AASA,WAAOJ,eAAP;AACD,GAdD;AAeD;;IAEKS,O;;;wBACc;AAChB,aAAOC,aAAaC,OAAb,gCAAP;AACD,K;sBACeC,K,EAAO;AACrBF,mBAAaG,OAAb,iCAA0CD,KAA1C;AACD;;;wBAEe;AACd,UAAME,WAAW,0CAAjB;AACA,UAAMC,eAAe,KAAKC,KAAL,CAAWD,YAAX,IAA2BE,OAAOC,QAAP,CAAgBC,IAAhE;;AAEA,UAAMC,cAAcC,OAAOC,MAAP,CAAc;AAChC3B,oBADgC;AAEhCoB;AAFgC,OAAd,EAGjB,KAAKC,KAHY,CAApB;;AAKA,kBAAUF,QAAV,GAAqB,aAAMS,SAAN,CA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LS_USER_KEY, NOT_INITIALIZED_ERROR } from './constants'\nimport { getTargetContainer, http, Query } from './utils'\nimport defaultTheme from './theme/default'\n\nconst scope = 'public_repo'\n\nfunction extendRenderer(instance, renderer) {\n instance[renderer] = (container) => {\n const targetContainer = getTargetContainer(container)\n const render = instance.theme[renderer] || instance.defaultTheme[renderer]\n\n autorun(() => {\n const e = render(instance.state, instance)\n if (targetContainer.firstChild) {\n targetContainer.replaceChild(e, targetContainer.firstChild)\n } else {\n targetContainer.appendChild(e)\n }\n })\n\n return targetContainer\n }\n}\n\nclass Gitment {\n get accessToken() {\n return localStorage.getItem(LS_ACCESS_TOKEN_KEY)\n }\n set accessToken(token) {\n localStorage.setItem(LS_ACCESS_TOKEN_KEY, token)\n }\n\n get loginLink() {\n const oauthUri = 'https://github.com/login/oauth/authorize'\n const redirect_uri = this.oauth.redirect_uri || window.location.href\n\n const oauthParams = Object.assign({\n scope,\n redirect_uri,\n }, this.oauth)\n\n return `${oauthUri}${Query.stringify(oauthParams)}`\n }\n\n constructor(options = {}) {\n this.defaultTheme = defaultTheme\n this.useTheme(defaultTheme)\n\n Object.assign(this, {\n id: window.location.href,\n title: window.document.title,\n link: window.location.href,\n desc: '',\n labels: [],\n theme: defaultTheme,\n oauth: {},\n perPage: 20,\n maxCommentHeight: 250,\n }, options)\n\n this.useTheme(this.theme)\n\n const user = {}\n try {\n const userInfo = localStorage.getItem(LS_USER_KEY)\n if (this.accessToken && userInfo) {\n Object.assign(user, JSON.parse(userInfo), {\n fromCache: true,\n })\n }\n } catch (e) {\n localStorage.removeItem(LS_USER_KEY)\n }\n\n this.state = observable({\n user,\n error: null,\n meta: {},\n comments: undefined,\n reactions: [],\n commentReactions: {},\n currentPage: 1,\n })\n\n const query = Query.parse()\n if (query.code) {\n const { client_id, client_secret } = this.oauth\n const code = query.code\n delete query.code\n const search = Query.stringify(query)\n const replacedUrl = `${window.location.origin}${window.location.pathname}${search}${window.location.hash}`\n history.replaceState({}, '', replacedUrl)\n\n Object.assign(this, {\n id: replacedUrl,\n link: replacedUrl,\n }, options)\n\n this.state.user.isLoggingIn = true\n http.post('https://gh-oauth.imsun.net', {\n code,\n client_id,\n client_secret,\n }, '')\n .then(data => {\n this.accessToken = data.access_token\n this.update()\n })\n .catch(e => {\n this.state.user.isLoggingIn = false\n alert(e)\n })\n } else {\n this.update()\n }\n }\n\n init() {\n return this.createIssue()\n .then(() => this.loadComments())\n .then(comments => {\n this.state.error = null\n return comments\n })\n }\n\n useTheme(theme = {}) {\n this.theme = theme\n\n const renderers = Object.keys(this.theme)\n renderers.forEach(renderer => extendRenderer(this, renderer))\n }\n\n update() {\n return Promise.all([this.loadMeta(), this.loadUserInfo()])\n .then(() => Promise.all([\n this.loadComments().then(() => this.loadCommentReactions()),\n this.loadReactions(),\n ]))\n .catch(e => this.state.error = e)\n }\n\n markdown(text) {\n return http.post('/markdown', {\n text,\n mode: 'gfm',\n })\n }\n\n createIssue() {\n const { id, owner, repo, title, link, desc, labels } = this\n\n return http.post(`/repos/${owner}/${repo}/issues`, {\n title,\n labels: labels.concat(['gitment', id]),\n body: `${link}\\n\\n${desc}`,\n })\n .then((meta) => {\n this.state.meta = meta\n return meta\n })\n }\n\n getIssue() {\n if (this.state.meta.id) return Promise.resolve(this.state.meta)\n\n return this.loadMeta()\n }\n\n post(body) {\n return this.getIssue()\n .then(issue => http.post(issue.comments_url, { body }, ''))\n .then(data => {\n this.state.meta.comments++\n const pageCount = Math.ceil(this.state.meta.comments / this.perPage)\n if (this.state.currentPage === pageCount) {\n this.state.comments.push(data)\n }\n return data\n })\n }\n\n loadMeta() {\n const { id, owner, repo } = this\n return http.get(`/repos/${owner}/${repo}/issues`, {\n creator: owner,\n labels: id,\n })\n .then(issues => {\n if (!issues.length) return Promise.reject(NOT_INITIALIZED_ERROR)\n this.state.meta = issues[0]\n return issues[0]\n })\n }\n\n loadComments(page = this.state.currentPage) {\n return this.getIssue()\n .then(issue => http.get(issue.comments_url, { page, per_page: this.perPage }, ''))\n .then((comments) => {\n this.state.comments = comments\n return comments\n })\n }\n\n loadUserInfo() {\n if (!this.accessToken) {\n this.logout()\n return Promise.resolve({})\n }\n\n return http.get('/user')\n .then((user) => {\n this.state.user = user\n localStorage.setItem(LS_USER_KEY, JSON.stringify(user))\n return user\n })\n }\n\n loadReactions() {\n if (!this.accessToken) {\n this.state.reactions = []\n return Promise.resolve([])\n }\n\n return this.getIssue()\n .then((issue) => {\n if (!issue.reactions.total_count) return []\n return http.get(issue.reactions.url, {}, '')\n })\n .then((reactions) => {\n this.state.reactions = reactions\n return reactions\n })\n }\n\n loadCommentReactions() {\n if (!this.accessToken) {\n this.state.commentReactions = {}\n return Promise.resolve([])\n }\n\n const comments = this.state.comments\n const comentReactions = {}\n\n return Promise.all(comments.map((comment) => {\n if (!comment.reactions.total_count) return []\n\n const { owner, repo } = this\n return http.get(`/repos/${owner}/${repo}/issues/comments/${comment.id}/reactions`, {})\n }))\n .then(reactionsArray => {\n comments.forEach((comment, index) => {\n comentReactions[comment.id] = reactionsArray[index]\n })\n this.state.commentReactions = comentReactions\n\n return comentReactions\n })\n }\n\n login() {\n window.location.href = this.loginLink\n }\n\n logout() {\n localStorage.removeItem(LS_ACCESS_TOKEN_KEY)\n localStorage.removeItem(LS_USER_KEY)\n this.state.user = {}\n }\n\n goto(page) {\n this.state.currentPage = page\n this.state.comments = undefined\n return this.loadComments(page)\n }\n\n like() {\n if (!this.accessToken) {\n alert('Login to Like')\n return Promise.reject()\n }\n\n const { owner, repo } = this\n\n return http.post(`/repos/${owner}/${repo}/issues/${this.state.meta.number}/reactions`, {\n content: 'heart',\n })\n .then(reaction => {\n this.state.reactions.push(reaction)\n this.state.meta.reactions.heart++\n })\n }\n\n unlike() {\n if (!this.accessToken) return Promise.reject()\n\n\n const { user, reactions } = this.state\n const index = reactions.findIndex(reaction => reaction.user.login === user.login)\n return http.delete(`/reactions/${reactions[index].id}`)\n .then(() => {\n reactions.splice(index, 1)\n this.state.meta.reactions.heart--\n })\n }\n\n likeAComment(commentId) {\n if (!this.accessToken) {\n alert('Login to Like')\n return Promise.reject()\n }\n\n const { owner, repo } = this\n const comment = this.state.comments.find(comment => comment.id === commentId)\n\n return http.post(`/repos/${owner}/${repo}/issues/comments/${commentId}/reactions`, {\n content: 'heart',\n })\n .then(reaction => {\n this.state.commentReactions[commentId].push(reaction)\n comment.reactions.heart++\n })\n }\n\n unlikeAComment(commentId) {\n if (!this.accessToken) return Promise.reject()\n\n const reactions = this.state.commentReactions[commentId]\n const comment = this.state.comments.find(comment => comment.id === commentId)\n const { user } = this.state\n const index = reactions.findIndex(reaction => reaction.user.login === user.login)\n\n return http.delete(`/reactions/${reactions[index].id}`)\n .then(() => {\n reactions.splice(index, 1)\n comment.reactions.heart--\n })\n }\n}\n\nmodule.exports = Gitment\n"]}
--------------------------------------------------------------------------------
/assets/gitment/icons.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 | /**
7 | * Modified from https://github.com/evil-icons/evil-icons
8 | */
9 |
10 | var close = exports.close = '';
11 | var github = exports.github = '';
12 | var heart = exports.heart = '';
13 | var spinner = exports.spinner = '';
14 | //# sourceMappingURL=icons.js.map
--------------------------------------------------------------------------------
/assets/gitment/icons.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":["../src/icons.js"],"names":["close","github","heart","spinner"],"mappings":";;;;;AAAA;;;;AAIO,IAAMA,wBAAQ,gOAAd;AACA,IAAMC,0BAAS,0jBAAf;AACA,IAAMC,wBAAQ,iYAAd;AACA,IAAMC,4BAAU,48CAAhB","file":"icons.js","sourcesContent":["/**\n * Modified from https://github.com/evil-icons/evil-icons\n */\n\nexport const close = ''\nexport const github = ''\nexport const heart = ''\nexport const spinner = ''\n"]}
--------------------------------------------------------------------------------
/assets/gitment/theme/default.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 |
7 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
8 |
9 | var _icons = require('../icons');
10 |
11 | var _constants = require('../constants');
12 |
13 | var _mobx = require('mobx');
14 |
15 | Date.prototype.format = function (format) {
16 | var o = {
17 | "M+": this.getMonth() + 1, //month
18 | "d+": this.getDate(), //day
19 | "h+": this.getHours(), //hour
20 | "m+": this.getMinutes(), //minute
21 | "s+": this.getSeconds(), //second
22 | "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
23 | "S": this.getMilliseconds() //millisecond
24 | };
25 | if (/(y+)/.test(format)) {
26 | format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
27 | }
28 | for (var k in o) {
29 | if (new RegExp("(" + k + ")").test(format)) {
30 | format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
31 | }
32 | }
33 | return format;
34 | };
35 |
36 | function renderHeader(_ref, instance) {
37 | var meta = _ref.meta,
38 | user = _ref.user,
39 | reactions = _ref.reactions;
40 |
41 | var container = document.createElement('div');
42 | container.lang = "en-US";
43 | container.className = 'gitment-container gitment-header-container';
44 |
45 | var likeButton = document.createElement('span');
46 | var likedReaction = reactions.find(function (reaction) {
47 | return reaction.content === 'heart' && reaction.user.login === user.login;
48 | });
49 | likeButton.className = 'gitment-header-like-btn';
50 | likeButton.innerHTML = '\n ' + _icons.heart + '\n ' + (likedReaction ? 'Unlike' : 'Like') + '\n ' + (meta.reactions && meta.reactions.heart ? ' \u2022 ' + meta.reactions.heart + ' Liked' : '') + '\n ';
51 |
52 | if (likedReaction) {
53 | likeButton.classList.add('liked');
54 | likeButton.onclick = function () {
55 | return instance.unlike();
56 | };
57 | } else {
58 | likeButton.classList.remove('liked');
59 | likeButton.onclick = function () {
60 | return instance.like();
61 | };
62 | }
63 | container.appendChild(likeButton);
64 |
65 | var commentsCount = document.createElement('span');
66 | commentsCount.innerHTML = '\n ' + (meta.comments ? ' \u2022 ' + meta.comments + ' Comments' : '') + '\n ';
67 | container.appendChild(commentsCount);
68 |
69 | var issueLink = document.createElement('a');
70 | issueLink.className = 'gitment-header-issue-link';
71 | issueLink.href = meta.html_url;
72 | issueLink.target = '_blank';
73 | issueLink.innerText = 'Issue Page';
74 | container.appendChild(issueLink);
75 |
76 | return container;
77 | }
78 |
79 | function renderComments(_ref2, instance) {
80 | var meta = _ref2.meta,
81 | comments = _ref2.comments,
82 | commentReactions = _ref2.commentReactions,
83 | currentPage = _ref2.currentPage,
84 | user = _ref2.user,
85 | error = _ref2.error;
86 |
87 | var container = document.createElement('div');
88 | container.lang = "en-US";
89 | container.className = 'gitment-container gitment-comments-container';
90 |
91 | if (error) {
92 | var errorBlock = document.createElement('div');
93 | errorBlock.className = 'gitment-comments-error';
94 |
95 | if (error === _constants.NOT_INITIALIZED_ERROR && user.login && user.login.toLowerCase() === instance.owner.toLowerCase()) {
96 | var initHint = document.createElement('div');
97 | var initButton = document.createElement('button');
98 | initButton.className = 'gitment-comments-init-btn';
99 | initButton.onclick = function () {
100 | initButton.setAttribute('disabled', true);
101 | instance.init().catch(function (e) {
102 | initButton.removeAttribute('disabled');
103 | alert(e);
104 | });
105 | };
106 | initButton.innerText = '初始化评论';
107 | initHint.appendChild(initButton);
108 | errorBlock.appendChild(initHint);
109 | } else {
110 | errorBlock.innerText = error;
111 | }
112 | container.appendChild(errorBlock);
113 | return container;
114 | } else if (comments === undefined) {
115 | var loading = document.createElement('div');
116 | loading.innerText = '加载评论中...';
117 | loading.className = 'gitment-comments-loading';
118 | container.appendChild(loading);
119 | return container;
120 | } else if (!comments.length) {
121 | var emptyBlock = document.createElement('div');
122 | emptyBlock.className = 'gitment-comments-empty';
123 | emptyBlock.innerText = '暂无评论';
124 | container.appendChild(emptyBlock);
125 | return container;
126 | }
127 |
128 | var commentsList = document.createElement('ul');
129 | commentsList.className = 'gitment-comments-list';
130 |
131 | comments.forEach(function (comment) {
132 | var createDate = new Date(comment.created_at);
133 | var updateDate = new Date(comment.updated_at);
134 | var commentItem = document.createElement('li');
135 | commentItem.className = 'gitment-comment';
136 | commentItem.innerHTML = '\n \n \n \n
{{tagtitle}}
5 |数据加载中
15 | 16 |没有更多数据了...
19 |最新
6 |数据加载中
12 | 13 |我也是有底线的...
16 |搜索有关于"{{search}}" 6 |
7 |
{{item.name}}
9 | {{new Date(item.created).format('yyyy-MM-dd hh:mm')}} 10 |{{item.comment}}
12 |{{li.name}}
34 | {{new Date(li.created).format('yyyy-MM-dd hh:mm')}} 35 |{{li.comment}}
37 |