├── .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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AiB9G,OAAjB","file":"gitment.js","sourcesContent":["import { autorun, observable } from 'mobx'\n\nimport { LS_ACCESS_TOKEN_KEY, 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
\n
\n \n ' + comment.user.login + '\n \n \u521B\u5EFA\u4E8E\n ' + new Date(createDate).format('yyyy-MM-dd hh:mm:ss') + '\n ' + (createDate.toString() !== updateDate.toString() ? ' \u2022 edited' : '') + '\n
' + _icons.heart + ' ' + (comment.reactions.heart || '') + '
\n
\n
' + comment.body_html + '
\n
\n '; 137 | var likeButton = commentItem.querySelector('.gitment-comment-like-btn'); 138 | var likedReaction = commentReactions[comment.id] && commentReactions[comment.id].find(function (reaction) { 139 | return reaction.content === 'heart' && reaction.user.login === user.login; 140 | }); 141 | if (likedReaction) { 142 | likeButton.classList.add('liked'); 143 | likeButton.onclick = function () { 144 | return instance.unlikeAComment(comment.id); 145 | }; 146 | } else { 147 | likeButton.classList.remove('liked'); 148 | likeButton.onclick = function () { 149 | return instance.likeAComment(comment.id); 150 | }; 151 | } 152 | 153 | // dirty 154 | // use a blank image to trigger height calculating when element rendered 155 | var imgTrigger = document.createElement('img'); 156 | var markdownBody = commentItem.querySelector('.gitment-comment-body'); 157 | imgTrigger.className = 'gitment-hidden'; 158 | imgTrigger.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="; 159 | imgTrigger.onload = function () { 160 | if (markdownBody.clientHeight > instance.maxCommentHeight) { 161 | markdownBody.classList.add('gitment-comment-body-folded'); 162 | markdownBody.style.maxHeight = instance.maxCommentHeight + 'px'; 163 | markdownBody.title = 'Click to Expand'; 164 | markdownBody.onclick = function () { 165 | markdownBody.classList.remove('gitment-comment-body-folded'); 166 | markdownBody.style.maxHeight = ''; 167 | markdownBody.title = ''; 168 | markdownBody.onclick = null; 169 | }; 170 | } 171 | }; 172 | commentItem.appendChild(imgTrigger); 173 | 174 | commentsList.appendChild(commentItem); 175 | }); 176 | 177 | container.appendChild(commentsList); 178 | 179 | if (meta) { 180 | var pageCount = Math.ceil(meta.comments / instance.perPage); 181 | if (pageCount > 1) { 182 | var pagination = document.createElement('ul'); 183 | pagination.className = 'gitment-comments-pagination'; 184 | 185 | if (currentPage > 1) { 186 | var previousButton = document.createElement('li'); 187 | previousButton.className = 'gitment-comments-page-item'; 188 | previousButton.innerText = 'Previous'; 189 | previousButton.onclick = function () { 190 | return instance.goto(currentPage - 1); 191 | }; 192 | pagination.appendChild(previousButton); 193 | } 194 | 195 | var _loop = function _loop(i) { 196 | var pageItem = document.createElement('li'); 197 | pageItem.className = 'gitment-comments-page-item'; 198 | pageItem.innerText = i; 199 | pageItem.onclick = function () { 200 | return instance.goto(i); 201 | }; 202 | if (currentPage === i) pageItem.classList.add('gitment-selected'); 203 | pagination.appendChild(pageItem); 204 | }; 205 | 206 | for (var i = 1; i <= pageCount; i++) { 207 | _loop(i); 208 | } 209 | 210 | if (currentPage < pageCount) { 211 | var nextButton = document.createElement('li'); 212 | nextButton.className = 'gitment-comments-page-item'; 213 | nextButton.innerText = 'Next'; 214 | nextButton.onclick = function () { 215 | return instance.goto(currentPage + 1); 216 | }; 217 | pagination.appendChild(nextButton); 218 | } 219 | 220 | container.appendChild(pagination); 221 | } 222 | } 223 | 224 | return container; 225 | } 226 | 227 | function renderEditor(_ref3, instance) { 228 | var user = _ref3.user, 229 | error = _ref3.error; 230 | 231 | var container = document.createElement('div'); 232 | container.lang = "en-US"; 233 | container.className = 'gitment-container gitment-editor-container'; 234 | 235 | var shouldDisable = user.login && !error ? '' : 'disabled'; 236 | var disabledTip = user.login ? '' : 'Login to Comment'; 237 | container.innerHTML = '\n ' + (user.login ? '\n \n ' : user.isLoggingIn ? '
' + _icons.spinner + '
' : '\n ' + _icons.github + '\n ') + '\n \n
\n
\n \n \n
\n
\n
\n \n
\n
\n
\n
\n
\n
\n \n '; 238 | if (user.login) { 239 | container.querySelector('.gitment-editor-logout-link').onclick = function () { 240 | return instance.logout(); 241 | }; 242 | } 243 | 244 | var writeField = container.querySelector('.gitment-editor-write-field'); 245 | var previewField = container.querySelector('.gitment-editor-preview-field'); 246 | 247 | var textarea = writeField.querySelector('textarea'); 248 | textarea.oninput = function () { 249 | textarea.style.height = 'auto'; 250 | var style = window.getComputedStyle(textarea, null); 251 | var height = parseInt(style.height, 10); 252 | var clientHeight = textarea.clientHeight; 253 | var scrollHeight = textarea.scrollHeight; 254 | if (clientHeight < scrollHeight) { 255 | textarea.style.height = height + scrollHeight - clientHeight + 'px'; 256 | } 257 | }; 258 | 259 | var _container$querySelec = container.querySelectorAll('.gitment-editor-tab'), 260 | _container$querySelec2 = _slicedToArray(_container$querySelec, 2), 261 | writeTab = _container$querySelec2[0], 262 | previewTab = _container$querySelec2[1]; 263 | 264 | writeTab.onclick = function () { 265 | writeTab.classList.add('gitment-selected'); 266 | previewTab.classList.remove('gitment-selected'); 267 | writeField.classList.remove('gitment-hidden'); 268 | previewField.classList.add('gitment-hidden'); 269 | 270 | textarea.focus(); 271 | }; 272 | previewTab.onclick = function () { 273 | previewTab.classList.add('gitment-selected'); 274 | writeTab.classList.remove('gitment-selected'); 275 | previewField.classList.remove('gitment-hidden'); 276 | writeField.classList.add('gitment-hidden'); 277 | 278 | var preview = previewField.querySelector('.gitment-editor-preview'); 279 | var content = textarea.value.trim(); 280 | if (!content) { 281 | preview.innerText = '暂无内容可预览'; 282 | return; 283 | } 284 | 285 | preview.innerText = 'Loading preview...'; 286 | instance.markdown(content).then(function (html) { 287 | return preview.innerHTML = html; 288 | }); 289 | }; 290 | 291 | var submitButton = container.querySelector('.gitment-editor-submit'); 292 | submitButton.onclick = function () { 293 | submitButton.innerText = 'Submitting...'; 294 | submitButton.setAttribute('disabled', true); 295 | instance.post(textarea.value.trim()).then(function (data) { 296 | textarea.value = ''; 297 | textarea.style.height = 'auto'; 298 | submitButton.removeAttribute('disabled'); 299 | submitButton.innerText = 'Comment'; 300 | }).catch(function (e) { 301 | alert(e); 302 | submitButton.removeAttribute('disabled'); 303 | submitButton.innerText = 'Comment'; 304 | }); 305 | }; 306 | 307 | return container; 308 | } 309 | 310 | function renderFooter() { 311 | var container = document.createElement('div'); 312 | container.lang = "en-US"; 313 | container.className = 'gitment-container gitment-footer-container'; 314 | container.innerHTML = '\n Powered by\n \n Gitment\n \n '; 315 | return container; 316 | } 317 | 318 | function render(state, instance) { 319 | var container = document.createElement('div'); 320 | container.lang = "en-US"; 321 | container.className = 'gitment-container gitment-root-container'; 322 | container.appendChild(instance.renderHeader(state, instance)); 323 | container.appendChild(instance.renderComments(state, instance)); 324 | container.appendChild(instance.renderEditor(state, instance)); 325 | container.appendChild(instance.renderFooter(state, instance)); 326 | return container; 327 | } 328 | 329 | exports.default = { render: render, renderHeader: renderHeader, renderComments: renderComments, renderEditor: renderEditor, renderFooter: renderFooter }; 330 | //# sourceMappingURL=default.js.map -------------------------------------------------------------------------------- /assets/gitment/theme/default.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../../src/theme/default.js"],"names":["Date","prototype","format","o","getMonth","getDate","getHours","getMinutes","getSeconds","Math","floor","getMilliseconds","test","replace","RegExp","$1","getFullYear","substr","length","k","renderHeader","instance","meta","user","reactions","container","document","createElement","lang","className","likeButton","likedReaction","find","reaction","content","login","innerHTML","heart","classList","add","onclick","unlike","remove","like","appendChild","commentsCount","comments","issueLink","href","html_url","target","innerText","renderComments","commentReactions","currentPage","error","errorBlock","toLowerCase","owner","initHint","initButton","setAttribute","init","catch","removeAttribute","alert","e","undefined","loading","emptyBlock","commentsList","forEach","createDate","comment","created_at","updateDate","updated_at","commentItem","avatar_url","toString","body_html","querySelector","id","unlikeAComment","likeAComment","imgTrigger","markdownBody","src","onload","clientHeight","maxCommentHeight","style","maxHeight","title","pageCount","ceil","perPage","pagination","previousButton","goto","i","pageItem","nextButton","renderEditor","shouldDisable","disabledTip","isLoggingIn","loginLink","logout","writeField","previewField","textarea","oninput","height","window","getComputedStyle","parseInt","scrollHeight","querySelectorAll","writeTab","previewTab","focus","preview","value","trim","markdown","then","html","submitButton","post","renderFooter","render","state"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;AAEAA,KAAKC,SAAL,CAAeC,MAAf,GAAwB,UAASA,MAAT,EAAiB;AACvC,MAAIC,IAAI;AACJ,UAAM,KAAKC,QAAL,KAAkB,CADpB,EACuB;AAC3B,UAAM,KAAKC,OAAL,EAFF,EAEkB;AACtB,UAAM,KAAKC,QAAL,EAHF,EAGmB;AACvB,UAAM,KAAKC,UAAL,EAJF,EAIqB;AACzB,UAAM,KAAKC,UAAL,EALF,EAKqB;AACzB,UAAMC,KAAKC,KAAL,CAAW,CAAC,KAAKN,QAAL,KAAkB,CAAnB,IAAwB,CAAnC,CANF,EAMyC;AAC7C,SAAK,KAAKO,eAAL,EAPD,CAOwB;AAPxB,GAAR;AASA,MAAI,OAAOC,IAAP,CAAYV,MAAZ,CAAJ,EAAyB;AACrBA,aAASA,OAAOW,OAAP,CAAeC,OAAOC,EAAtB,EAAyB,CAAC,KAAKC,WAAL,KAAqB,EAAtB,EAA0BC,MAA1B,CAAiC,IAAIH,OAAOC,EAAP,CAAUG,MAA/C,CAAzB,CAAT;AACH;AACD,OAAK,IAAIC,CAAT,IAAchB,CAAd,EAAgB;AACZ,QAAI,IAAIW,MAAJ,CAAW,MAAMK,CAAN,GAAU,GAArB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as heartIcon, spinner as spinnerIcon } from '../icons'\nimport { NOT_INITIALIZED_ERROR } from '../constants'\nimport {toJS} from 'mobx';\n\nDate.prototype.format = function(format) {\n var o = {\n \"M+\": this.getMonth() + 1, //month\n \"d+\": this.getDate(), //day\n \"h+\": this.getHours(), //hour\n \"m+\": this.getMinutes(), //minute\n \"s+\": this.getSeconds(), //second\n \"q+\": Math.floor((this.getMonth() + 3) / 3), //quarter\n \"S\": this.getMilliseconds() //millisecond\n }\n if (/(y+)/.test(format)) {\n format = format.replace(RegExp.$1,(this.getFullYear() + \"\").substr(4 - RegExp.$1.length));\n }\n for (var k in o){\n if (new RegExp(\"(\" + k + \")\").test(format)){\n format = format.replace(RegExp.$1,RegExp.$1.length == 1 ? o[k] :(\"00\" + o[k]).substr((\"\" + o[k]).length));\n }\n }\n return format;\n}\n\nfunction renderHeader({ meta, user, reactions }, instance) {\n const container = document.createElement('div')\n container.lang = \"en-US\"\n container.className = 'gitment-container gitment-header-container'\n\n const likeButton = document.createElement('span')\n const likedReaction = reactions.find(reaction => (\n reaction.content === 'heart' && reaction.user.login === user.login\n ))\n likeButton.className = 'gitment-header-like-btn'\n likeButton.innerHTML = `\n ${heartIcon}\n ${ likedReaction\n ? 'Unlike'\n : 'Like'\n }\n ${ meta.reactions && meta.reactions.heart\n ? ` • ${meta.reactions.heart} Liked`\n : ''\n }\n `\n\n if (likedReaction) {\n likeButton.classList.add('liked')\n likeButton.onclick = () => instance.unlike()\n } else {\n likeButton.classList.remove('liked')\n likeButton.onclick = () => instance.like()\n }\n container.appendChild(likeButton)\n\n const commentsCount = document.createElement('span')\n commentsCount.innerHTML = `\n ${ meta.comments\n ? ` • ${meta.comments} Comments`\n : ''\n }\n `\n container.appendChild(commentsCount)\n\n const issueLink = document.createElement('a')\n issueLink.className = 'gitment-header-issue-link'\n issueLink.href = meta.html_url\n issueLink.target = '_blank'\n issueLink.innerText = 'Issue Page'\n container.appendChild(issueLink)\n\n return container\n}\n\nfunction renderComments({ meta, comments, commentReactions, currentPage, user, error }, instance) {\n const container = document.createElement('div')\n container.lang = \"en-US\"\n container.className = 'gitment-container gitment-comments-container'\n\n if (error) {\n const errorBlock = document.createElement('div')\n errorBlock.className = 'gitment-comments-error'\n\n if (error === NOT_INITIALIZED_ERROR\n && user.login\n && user.login.toLowerCase() === instance.owner.toLowerCase()) {\n const initHint = document.createElement('div')\n const initButton = document.createElement('button')\n initButton.className = 'gitment-comments-init-btn'\n initButton.onclick = () => {\n initButton.setAttribute('disabled', true)\n instance.init()\n .catch(e => {\n initButton.removeAttribute('disabled')\n alert(e)\n })\n }\n initButton.innerText = '初始化评论'\n initHint.appendChild(initButton)\n errorBlock.appendChild(initHint)\n } else {\n errorBlock.innerText = error\n }\n container.appendChild(errorBlock)\n return container\n } else if (comments === undefined) {\n const loading = document.createElement('div')\n loading.innerText = '加载评论中...'\n loading.className = 'gitment-comments-loading'\n container.appendChild(loading)\n return container\n } else if (!comments.length) {\n const emptyBlock = document.createElement('div')\n emptyBlock.className = 'gitment-comments-empty'\n emptyBlock.innerText = '暂无评论'\n container.appendChild(emptyBlock)\n return container\n }\n\n const commentsList = document.createElement('ul')\n commentsList.className = 'gitment-comments-list'\n\n comments.forEach(comment => {\n const createDate = new Date(comment.created_at)\n const updateDate = new Date(comment.updated_at)\n const commentItem = document.createElement('li')\n commentItem.className = 'gitment-comment'\n commentItem.innerHTML = `\n \n \n \n
\n
\n \n ${comment.user.login}\n \n 创建于\n ${new Date(createDate).format('yyyy-MM-dd hh:mm:ss')}\n ${ createDate.toString() !== updateDate.toString()\n ? ` • edited`\n : ''\n }\n
${heartIcon} ${comment.reactions.heart || ''}
\n
\n
${comment.body_html}
\n
\n `\n const likeButton = commentItem.querySelector('.gitment-comment-like-btn')\n const likedReaction = commentReactions[comment.id]\n && commentReactions[comment.id].find(reaction => (\n reaction.content === 'heart' && reaction.user.login === user.login\n ))\n if (likedReaction) {\n likeButton.classList.add('liked')\n likeButton.onclick = () => instance.unlikeAComment(comment.id)\n } else {\n likeButton.classList.remove('liked')\n likeButton.onclick = () => instance.likeAComment(comment.id)\n }\n\n // dirty\n // use a blank image to trigger height calculating when element rendered\n const imgTrigger = document.createElement('img')\n const markdownBody = commentItem.querySelector('.gitment-comment-body')\n imgTrigger.className = 'gitment-hidden'\n imgTrigger.src = \"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\"\n imgTrigger.onload = () => {\n if (markdownBody.clientHeight > instance.maxCommentHeight) {\n markdownBody.classList.add('gitment-comment-body-folded')\n markdownBody.style.maxHeight = instance.maxCommentHeight + 'px'\n markdownBody.title = 'Click to Expand'\n markdownBody.onclick = () => {\n markdownBody.classList.remove('gitment-comment-body-folded')\n markdownBody.style.maxHeight = ''\n markdownBody.title = ''\n markdownBody.onclick = null\n }\n }\n }\n commentItem.appendChild(imgTrigger)\n\n commentsList.appendChild(commentItem)\n })\n\n container.appendChild(commentsList)\n\n if (meta) {\n const pageCount = Math.ceil(meta.comments / instance.perPage)\n if (pageCount > 1) {\n const pagination = document.createElement('ul')\n pagination.className = 'gitment-comments-pagination'\n\n if (currentPage > 1) {\n const previousButton = document.createElement('li')\n previousButton.className = 'gitment-comments-page-item'\n previousButton.innerText = 'Previous'\n previousButton.onclick = () => instance.goto(currentPage - 1)\n pagination.appendChild(previousButton)\n }\n\n for (let i = 1; i <= pageCount; i++) {\n const pageItem = document.createElement('li')\n pageItem.className = 'gitment-comments-page-item'\n pageItem.innerText = i\n pageItem.onclick = () => instance.goto(i)\n if (currentPage === i) pageItem.classList.add('gitment-selected')\n pagination.appendChild(pageItem)\n }\n\n if (currentPage < pageCount) {\n const nextButton = document.createElement('li')\n nextButton.className = 'gitment-comments-page-item'\n nextButton.innerText = 'Next'\n nextButton.onclick = () => instance.goto(currentPage + 1)\n pagination.appendChild(nextButton)\n }\n\n container.appendChild(pagination)\n }\n }\n\n return container\n}\n\nfunction renderEditor({ user, error }, instance) {\n const container = document.createElement('div')\n container.lang = \"en-US\"\n container.className = 'gitment-container gitment-editor-container'\n\n const shouldDisable = user.login && !error ? '' : 'disabled'\n const disabledTip = user.login ? '' : 'Login to Comment'\n container.innerHTML = `\n ${ user.login\n ? `\n \n `\n : user.isLoggingIn\n ? `
${spinnerIcon}
`\n : `\n ${githubIcon}\n `\n }\n \n
\n
\n \n
\n ${ user.login\n ? '退出登录'\n : user.isLoggingIn\n ? 'Logging in...'\n : ``\n }\n
\n
\n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n \n 支持 Markdown\n \n \n
\n `\n if (user.login) {\n container.querySelector('.gitment-editor-logout-link').onclick = () => instance.logout()\n }\n\n const writeField = container.querySelector('.gitment-editor-write-field')\n const previewField = container.querySelector('.gitment-editor-preview-field')\n\n const textarea = writeField.querySelector('textarea')\n textarea.oninput = () => {\n textarea.style.height = 'auto'\n const style = window.getComputedStyle(textarea, null)\n const height = parseInt(style.height, 10)\n const clientHeight = textarea.clientHeight\n const scrollHeight = textarea.scrollHeight\n if (clientHeight < scrollHeight) {\n textarea.style.height = (height + scrollHeight - clientHeight) + 'px'\n }\n }\n\n const [writeTab, previewTab] = container.querySelectorAll('.gitment-editor-tab')\n writeTab.onclick = () => {\n writeTab.classList.add('gitment-selected')\n previewTab.classList.remove('gitment-selected')\n writeField.classList.remove('gitment-hidden')\n previewField.classList.add('gitment-hidden')\n\n textarea.focus()\n }\n previewTab.onclick = () => {\n previewTab.classList.add('gitment-selected')\n writeTab.classList.remove('gitment-selected')\n previewField.classList.remove('gitment-hidden')\n writeField.classList.add('gitment-hidden')\n\n const preview = previewField.querySelector('.gitment-editor-preview')\n const content = textarea.value.trim()\n if (!content) {\n preview.innerText = '暂无内容可预览'\n return\n }\n\n preview.innerText = 'Loading preview...'\n instance.markdown(content)\n .then(html => preview.innerHTML = html)\n }\n\n const submitButton = container.querySelector('.gitment-editor-submit')\n submitButton.onclick = () => {\n submitButton.innerText = 'Submitting...'\n submitButton.setAttribute('disabled', true)\n instance.post(textarea.value.trim())\n .then(data => {\n textarea.value = ''\n textarea.style.height = 'auto'\n submitButton.removeAttribute('disabled')\n submitButton.innerText = 'Comment'\n })\n .catch(e => {\n alert(e)\n submitButton.removeAttribute('disabled')\n submitButton.innerText = 'Comment'\n })\n }\n\n return container\n}\n\nfunction renderFooter() {\n const container = document.createElement('div')\n container.lang = \"en-US\"\n container.className = 'gitment-container gitment-footer-container'\n container.innerHTML = `\n Powered by\n \n Gitment\n \n `\n return container\n}\n\nfunction render(state, instance) {\n const container = document.createElement('div')\n container.lang = \"en-US\"\n container.className = 'gitment-container gitment-root-container'\n container.appendChild(instance.renderHeader(state, instance))\n container.appendChild(instance.renderComments(state, instance))\n container.appendChild(instance.renderEditor(state, instance))\n container.appendChild(instance.renderFooter(state, instance))\n return container\n}\n\nexport default { render, renderHeader, renderComments, renderEditor, renderFooter }\n"]} -------------------------------------------------------------------------------- /assets/gitment/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.http = exports.Query = exports.isString = undefined; 7 | 8 | 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"); } }; }(); 9 | 10 | exports.getTargetContainer = getTargetContainer; 11 | 12 | var _constants = require('./constants'); 13 | 14 | var isString = exports.isString = function isString(s) { 15 | return toString.call(s) === '[object String]'; 16 | }; 17 | 18 | function getTargetContainer(container) { 19 | var targetContainer = void 0; 20 | if (container instanceof Element) { 21 | targetContainer = container; 22 | } else if (isString(container)) { 23 | targetContainer = document.getElementById(container); 24 | } else { 25 | targetContainer = document.createElement('div'); 26 | } 27 | 28 | return targetContainer; 29 | } 30 | 31 | var Query = exports.Query = { 32 | parse: function parse() { 33 | var search = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location.search; 34 | 35 | if (!search) return {}; 36 | var queryString = search[0] === '?' ? search.substring(1) : search; 37 | var query = {}; 38 | queryString.split('&').forEach(function (queryStr) { 39 | var _queryStr$split = queryStr.split('='), 40 | _queryStr$split2 = _slicedToArray(_queryStr$split, 2), 41 | key = _queryStr$split2[0], 42 | value = _queryStr$split2[1]; 43 | 44 | if (key) query[key] = value; 45 | }); 46 | 47 | return query; 48 | }, 49 | stringify: function stringify(query) { 50 | var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '?'; 51 | 52 | var queryString = Object.keys(query).map(function (key) { 53 | return key + '=' + encodeURIComponent(query[key] || ''); 54 | }).join('&'); 55 | return queryString ? prefix + queryString : ''; 56 | } 57 | }; 58 | 59 | function ajaxFactory(method) { 60 | return function (apiPath) { 61 | var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 62 | var base = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'https://api.github.com'; 63 | 64 | var req = new XMLHttpRequest(); 65 | var token = localStorage.getItem(_constants.LS_ACCESS_TOKEN_KEY); 66 | 67 | var url = '' + base + apiPath; 68 | var body = null; 69 | if (method === 'GET' || method === 'DELETE') { 70 | url += Query.stringify(data); 71 | } 72 | 73 | var p = new Promise(function (resolve, reject) { 74 | req.addEventListener('load', function () { 75 | var contentType = req.getResponseHeader('content-type'); 76 | var res = req.responseText; 77 | if (!/json/.test(contentType)) { 78 | resolve(res); 79 | return; 80 | } 81 | var data = req.responseText ? JSON.parse(res) : {}; 82 | if (data.message) { 83 | reject(new Error(data.message)); 84 | } else { 85 | resolve(data); 86 | } 87 | }); 88 | req.addEventListener('error', function (error) { 89 | return reject(error); 90 | }); 91 | }); 92 | req.open(method, url, true); 93 | 94 | req.setRequestHeader('Accept', 'application/vnd.github.squirrel-girl-preview, application/vnd.github.html+json'); 95 | if (token) { 96 | req.setRequestHeader('Authorization', 'token ' + token); 97 | } 98 | if (method !== 'GET' && method !== 'DELETE') { 99 | body = JSON.stringify(data); 100 | req.setRequestHeader('Content-Type', 'application/json'); 101 | } 102 | 103 | req.send(body); 104 | return p; 105 | }; 106 | } 107 | 108 | var http = exports.http = { 109 | get: ajaxFactory('GET'), 110 | post: ajaxFactory('POST'), 111 | delete: ajaxFactory('DELETE'), 112 | put: ajaxFactory('PUT') 113 | }; 114 | //# sourceMappingURL=utils.js.map -------------------------------------------------------------------------------- /assets/gitment/utils.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../src/utils.js"],"names":["getTargetContainer","isString","toString","call","s","container","targetContainer","Element","document","getElementById","createElement","Query","parse","search","window","location","queryString","substring","query","split","forEach","queryStr","key","value","stringify","prefix","Object","keys","map","encodeURIComponent","join","ajaxFactory","method","apiPath","data","base","req","XMLHttpRequest","token","localStorage","getItem","url","body","p","Promise","resolve","reject","addEventListener","contentType","getResponseHeader","res","responseText","test","JSON","message","Error","error","open","setRequestHeader","send","http","get","post","delete","put"],"mappings":";;;;;;;;;QAIgBA,kB,GAAAA,kB;;AAJhB;;AAEO,IAAMC,8BAAW,SAAXA,QAAW;AAAA,SAAKC,SAASC,IAAT,CAAcC,CAAd,MAAqB,iBAA1B;AAAA,CAAjB;;AAEA,SAASJ,kBAAT,CAA4BK,SAA5B,EAAuC;AAC5C,MAAIC,wBAAJ;AACA,MAAID,qBAAqBE,OAAzB,EAAkC;AAChCD,sBAAkBD,SAAlB;AACD,GAFD,MAEO,IAAIJ,SAASI,SAAT,CAAJ,EAAyB;AAC9BC,sBAAkBE,SAASC,cAAT,CAAwBJ,SAAxB,CAAlB;AACD,GAFM,MAEA;AACLC,sBAAkBE,SAASE,aAAT,CAAuB,KAAvB,CAAlB;AACD;;AAED,SAAOJ,eAAP;AACD;;AA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,OAAKjC,YAAY,KAAZ;AAJa,CAAb","file":"utils.js","sourcesContent":["import { LS_ACCESS_TOKEN_KEY } from './constants'\n\nexport const isString = s => toString.call(s) === '[object String]'\n\nexport function getTargetContainer(container) {\n let targetContainer\n if (container instanceof Element) {\n targetContainer = container\n } else if (isString(container)) {\n targetContainer = document.getElementById(container)\n } else {\n targetContainer = document.createElement('div')\n }\n\n return targetContainer\n}\n\nexport const Query = {\n parse(search = window.location.search) {\n if (!search) return {}\n const queryString = search[0] === '?' ? search.substring(1) : search\n const query = {}\n queryString.split('&')\n .forEach(queryStr => {\n const [key, value] = queryStr.split('=')\n if (key) query[key] = value\n })\n\n return query\n },\n stringify(query, prefix = '?') {\n const queryString = Object.keys(query)\n .map(key => `${key}=${encodeURIComponent(query[key] || '')}`)\n .join('&')\n return queryString ? prefix + queryString : ''\n },\n}\n\nfunction ajaxFactory(method) {\n return function(apiPath, data = {}, base = 'https://api.github.com') {\n const req = new XMLHttpRequest()\n const token = localStorage.getItem(LS_ACCESS_TOKEN_KEY)\n\n let url = `${base}${apiPath}`\n let body = null\n if (method === 'GET' || method === 'DELETE') {\n url += Query.stringify(data)\n }\n\n const p = new Promise((resolve, reject) => {\n req.addEventListener('load', () => {\n const contentType = req.getResponseHeader('content-type')\n const res = req.responseText\n if (!/json/.test(contentType)) {\n resolve(res)\n return\n }\n const data = req.responseText ? JSON.parse(res) : {}\n if (data.message) {\n reject(new Error(data.message))\n } else {\n resolve(data)\n }\n })\n req.addEventListener('error', error => reject(error))\n })\n req.open(method, url, true)\n\n req.setRequestHeader('Accept', 'application/vnd.github.squirrel-girl-preview, application/vnd.github.html+json')\n if (token) {\n req.setRequestHeader('Authorization', `token ${token}`)\n }\n if (method !== 'GET' && method !== 'DELETE') {\n body = JSON.stringify(data)\n req.setRequestHeader('Content-Type', 'application/json')\n }\n\n req.send(body)\n return p\n }\n}\n\nexport const http = {\n get: ajaxFactory('GET'),\n post: ajaxFactory('POST'),\n delete: ajaxFactory('DELETE'),\n put: ajaxFactory('PUT'),\n}\n"]} -------------------------------------------------------------------------------- /assets/hybrid.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Monokai Sublime style. Derived from Monokai by noformnocontent http://nn.mit-license.org/ 4 | 5 | */ 6 | 7 | .hljs { 8 | display: block; 9 | overflow-x: auto; 10 | padding: 0.5em; 11 | background: #23241f; 12 | } 13 | 14 | .hljs, 15 | .hljs-tag, 16 | .hljs-subst { 17 | color: #f8f8f2; 18 | } 19 | 20 | .hljs-strong, 21 | .hljs-emphasis { 22 | color: #a8a8a2; 23 | } 24 | 25 | .hljs-bullet, 26 | .hljs-quote, 27 | .hljs-number, 28 | .hljs-regexp, 29 | .hljs-link { 30 | color: #ae81ff; 31 | } 32 | .hljs-literal{color:#f92672} 33 | .hljs-code, 34 | .hljs-title, 35 | .hljs-section, 36 | .hljs-selector-class { 37 | color: #a6e22e; 38 | } 39 | 40 | .hljs-strong { 41 | font-weight: bold; 42 | } 43 | 44 | .hljs-emphasis { 45 | font-style: italic; 46 | } 47 | 48 | .hljs-keyword{color:#66d9ef} 49 | .hljs-selector-tag, 50 | .hljs-name{ 51 | color: #f92672; 52 | } 53 | .hljs-attr { 54 | color: #a6e22e; 55 | } 56 | 57 | .hljs-symbol, 58 | .hljs-attribute { 59 | color: #66d9ef; 60 | } 61 | 62 | .hljs-params{color:#fd971f} 63 | .hljs-class .hljs-title { 64 | color: #f8f8f2; 65 | } 66 | 67 | .hljs-string, 68 | .hljs-type, 69 | 70 | .hljs-builtin-name, 71 | .hljs-selector-id, 72 | .hljs-selector-attr, 73 | .hljs-selector-pseudo, 74 | .hljs-addition, 75 | .hljs-variable, 76 | .hljs-template-variable { 77 | color: #e6db74; 78 | } 79 | .hljs-built_in{color:#66d9ef} 80 | .hljs-comment, 81 | .hljs-deletion, 82 | .hljs-meta { 83 | color: #75715e; 84 | } 85 | .hljs-comment{font-style:inherit} -------------------------------------------------------------------------------- /assets/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hzy0913/my-blog/0c9e4841d8bdfcbf87e3c75eaa5609dade53aef0/assets/logo.jpg -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hzy0913/my-blog/0c9e4841d8bdfcbf87e3c75eaa5609dade53aef0/assets/logo.png -------------------------------------------------------------------------------- /assets/radiocolor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hzy0913/my-blog/0c9e4841d8bdfcbf87e3c75eaa5609dade53aef0/assets/radiocolor.png -------------------------------------------------------------------------------- /components/ArticleList.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 65 | 66 | 82 | -------------------------------------------------------------------------------- /components/Comment.vue: -------------------------------------------------------------------------------- 1 | 63 | 64 | 209 | 385 | -------------------------------------------------------------------------------- /components/README.md: -------------------------------------------------------------------------------- 1 | # COMPONENTS 2 | 3 | The components directory contains your Vue.js Components. 4 | Nuxt.js doesn't supercharge these components. 5 | 6 | **This directory is not required, you can delete it if you don't want to use it.** 7 | -------------------------------------------------------------------------------- /layouts/README.md: -------------------------------------------------------------------------------- 1 | # LAYOUTS 2 | 3 | This directory contains your Application Layouts. 4 | 5 | More information about the usage of this directory in the documentation: 6 | https://nuxtjs.org/guide/views#layouts 7 | 8 | **This directory is not required, you can delete it if you don't want to use it.** 9 | -------------------------------------------------------------------------------- /layouts/default.vue: -------------------------------------------------------------------------------- 1 | 43 | 109 | -------------------------------------------------------------------------------- /layouts/error.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 22 | 23 | 26 | -------------------------------------------------------------------------------- /middleware/README.md: -------------------------------------------------------------------------------- 1 | # MIDDLEWARE 2 | 3 | This directory contains your Application Middleware. 4 | The middleware lets you define custom function to be ran before rendering a page or a group of pages (layouts). 5 | 6 | More information about the usage of this directory in the documentation: 7 | https://nuxtjs.org/guide/routing#middleware 8 | 9 | **This directory is not required, you can delete it if you don't want to use it.** 10 | -------------------------------------------------------------------------------- /nuxt.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack') 2 | 3 | module.exports = { 4 | /* 5 | ** Headers of the page 6 | */ 7 | head: { 8 | title: 'binlive', 9 | meta: [ 10 | { charset: 'utf-8' }, 11 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 12 | { name: 'keywords', content: 'binlive博客 vue ssr blog,前端开发,前端,web开发,node,vue,react,webpack,git' }, 13 | { hid: 'description', name: 'description', content: 'binlive博客 vue ssr blog,前端开发,前端,web开发,node,vue,react,webpack,git' } 14 | ], 15 | link: [ 16 | { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } 17 | ] 18 | }, 19 | /* 20 | ** Customize the progress bar color 21 | */ 22 | loading: { color: '#44C1B8', height: '4px' }, 23 | vender:[ 24 | 'element-ui', 'axios', '~untils/index.js' 25 | ], 26 | css: [ 27 | 'element-ui/lib/theme-chalk/index.css', 28 | {src: '@/style/style.css', lang: 'css'} 29 | ], 30 | plugins: [ 31 | { src: '~plugins/element-ui', ssr: true } 32 | ], 33 | /* 34 | ** Build configuration 35 | */ 36 | build: { 37 | build: { 38 | vendor: ['element-ui', 'axios', 'Button', 'Input', 'Tabs', 'Message', 'TabPane', 'Row', 'Col', 'Loading', 'Notification', 'Icon'] 39 | }, 40 | analyze: false, 41 | plugins: [ 42 | new webpack.ContextReplacementPlugin( 43 | /highlight\.js\/lib\/languages$/, 44 | new RegExp(`^./(${['javascript', 'css', 'php', 'sql', 'python', 'bash'].join('|')})$`), 45 | ) 46 | ], 47 | babel: { 48 | plugins: [['component', [{ 49 | libraryName: 'element-ui', 50 | styleLibraryName: 'theme-chalk' 51 | }]]], 52 | comments: true 53 | }, 54 | /* 55 | ** Run ESLint on save 56 | */ 57 | extend (config, { isDev, isClient }) { 58 | if (isDev && isClient) { 59 | config.module.rules.push({ 60 | enforce: 'pre', 61 | test: /\.(js|vue)$/, 62 | loader: 'eslint-loader', 63 | exclude: /(node_modules)/ 64 | }) 65 | } 66 | } 67 | }, 68 | modules: [ 69 | '@nuxtjs/axios', 70 | '@nuxtjs/proxy' 71 | ], 72 | proxy: [ 73 | ['/api', { target: 'http://localhost:3080' }] 74 | ] 75 | } 76 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blog", 3 | "version": "1.0.1", 4 | "description": "blog vue ssr", 5 | "author": "hzy", 6 | "private": true, 7 | "scripts": { 8 | "dev": "nuxt", 9 | "build": "nuxt build", 10 | "start": "nuxt start", 11 | "server": "npm run build && pm2 delete blog && pm2 start npm --name 'blog' -- start", 12 | "generate": "nuxt generate", 13 | "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", 14 | "precommit": "npm run lint", 15 | "firstserver": "npm run build && pm2 start npm --name 'blog' -- start", 16 | "list": "pm2 list", 17 | "stop": "pm2 stop 'blog'" 18 | }, 19 | "dependencies": { 20 | "axios": "^0.18.0", 21 | "element-ui": "^2.3.6", 22 | "highlight.js": "^9.12.0", 23 | "marked": "^0.3.19", 24 | "mobx": "^4.2.0", 25 | "nuxt": "^1.0.0" 26 | }, 27 | "devDependencies": { 28 | "@nuxtjs/axios": "^5.3.1", 29 | "@nuxtjs/proxy": "^1.2.4", 30 | "babel-eslint": "^8.2.1", 31 | "babel-plugin-component": "^1.1.0", 32 | "eslint": "^4.15.0", 33 | "eslint-friendly-formatter": "^3.0.0", 34 | "eslint-loader": "^1.7.1", 35 | "eslint-plugin-vue": "^4.0.0", 36 | "pm2": "^2.10.3" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pages/README.md: -------------------------------------------------------------------------------- 1 | # PAGES 2 | 3 | This directory contains your Application Views and Routes. 4 | The framework reads all the .vue files inside this directory and creates the router of your application. 5 | 6 | More information about the usage of this directory in the documentation: 7 | https://nuxtjs.org/guide/routing 8 | -------------------------------------------------------------------------------- /pages/_tag.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | 112 | 113 | 131 | -------------------------------------------------------------------------------- /pages/details/_id.vue: -------------------------------------------------------------------------------- 1 | 24 | 25 | 121 | 122 | 160 | -------------------------------------------------------------------------------- /pages/index.vue: -------------------------------------------------------------------------------- 1 | 19 | 107 | 108 | 113 | -------------------------------------------------------------------------------- /pages/search/_search.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 57 | 58 | 73 | -------------------------------------------------------------------------------- /plugins/README.md: -------------------------------------------------------------------------------- 1 | # PLUGINS 2 | 3 | This directory contains your Javascript plugins that you want to run before instantiating the root vue.js application. 4 | 5 | More information about the usage of this directory in the documentation: 6 | https://nuxtjs.org/guide/plugins 7 | 8 | **This directory is not required, you can delete it if you don't want to use it.** 9 | -------------------------------------------------------------------------------- /plugins/axios.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | let options = {} 4 | if (process.server) { 5 | options.baseURL = 'http://localhost:3080' 6 | } 7 | 8 | export default axios.create(options) 9 | -------------------------------------------------------------------------------- /plugins/element-ui.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import {Button, Input, Tabs, TabPane, Row, Col, Notification, Icon, Loading} from 'element-ui' 3 | 4 | Vue.use(Button); 5 | Vue.use(Input); 6 | Vue.use(Tabs); 7 | Vue.use(TabPane); 8 | Vue.use(Row); 9 | Vue.use(Col); 10 | Vue.use(Icon); 11 | Vue.use(Notification); 12 | Vue.use(Loading); 13 | -------------------------------------------------------------------------------- /pull.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const exec = require('exec'); 3 | const PORT = 3389 4 | 5 | var deployServer = http.createServer(function(request, response) { 6 | if (request.url.search(/pull\/?$/i) > 0) { 7 | var commands = ['git pull', 'npm run server'].join(' && '); 8 | exec(commands, function(err, out, code) { 9 | if (err instanceof Error) { 10 | response.writeHead(500) 11 | response.end('Server Internal Error.') 12 | throw err 13 | } 14 | process.stderr.write(err) 15 | process.stdout.write(out) 16 | response.writeHead(200) 17 | }) 18 | } else { 19 | response.writeHead(404) 20 | response.end('Not Found.') 21 | } 22 | }) 23 | 24 | deployServer.listen(PORT); 25 | -------------------------------------------------------------------------------- /static/README.md: -------------------------------------------------------------------------------- 1 | # STATIC 2 | 3 | This directory contains your static files. 4 | Each file inside this directory is mapped to /. 5 | 6 | Example: /static/robots.txt is mapped as /robots.txt. 7 | 8 | More information about the usage of this directory in the documentation: 9 | https://nuxtjs.org/guide/assets#static 10 | 11 | **This directory is not required, you can delete it if you don't want to use it.** 12 | -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hzy0913/my-blog/0c9e4841d8bdfcbf87e3c75eaa5609dade53aef0/static/favicon.ico -------------------------------------------------------------------------------- /store/README.md: -------------------------------------------------------------------------------- 1 | # STORE 2 | 3 | This directory contains your Vuex Store files. 4 | Vuex Store option is implemented in the Nuxt.js framework. 5 | Creating a index.js file in this directory activate the option in the framework automatically. 6 | 7 | More information about the usage of this directory in the documentation: 8 | https://nuxtjs.org/guide/vuex-store 9 | 10 | **This directory is not required, you can delete it if you don't want to use it.** 11 | -------------------------------------------------------------------------------- /store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | 4 | 5 | Vue.use(Vuex); 6 | 7 | const state = { 8 | 'newlistfirst':true, 9 | 'newArticlelist':[], 10 | 'taglistfirst':true, 11 | 'taglistcon':[], 12 | }; 13 | // 创建一个对象存储一系列 14 | const mutations = { 15 | updatenewlistcon (state, newArticlelist) { 16 | state.newArticlelist = newArticlelist 17 | }, 18 | newlistfirst (state,newlistfirst) { 19 | state.newlistfirst=newlistfirst 20 | }, 21 | updatetaglistcon (state,taglistcon) { 22 | state.taglistcon=taglistcon 23 | }, 24 | taglistfirst (state,taglistfirst) { 25 | state.taglistfirst=taglistfirst 26 | }, 27 | }; 28 | 29 | 30 | const store = () => new Vuex.Store({ 31 | state, 32 | mutations 33 | }) 34 | 35 | export default store; 36 | -------------------------------------------------------------------------------- /style/style.css: -------------------------------------------------------------------------------- 1 | body, h1, h2, h3, h4, h5, h6, dl, dt, dd, ul, ol, li, th, td, p, blockquote, pre, form, fieldset, legend, input, button, textarea, hr { 2 | margin: 0; 3 | padding: 0 4 | } 5 | 6 | h1, h2, h3, h4, h5, h6 { 7 | font-size: 100%; 8 | font-weight: normal; 9 | } 10 | 11 | * { 12 | /*font-family: "Fira Mono", "Andale Mono", "Consolas", monospace, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;*/ 13 | box-sizing: border-box; 14 | font-variant-ligatures: none; 15 | letter-spacing: 0px; 16 | } 17 | 18 | button, input, optgroup, select, textarea { 19 | font-family: 'Source Sans Pro', 'Lucida Grande', sans-serif; 20 | } 21 | 22 | li { 23 | list-style: none 24 | } 25 | 26 | fieldset, img { 27 | border: 0 28 | } 29 | 30 | table { 31 | border-collapse: collapse; 32 | border: 1px; 33 | margin-bottom: 10px 34 | } 35 | 36 | button, input, select, textarea { 37 | font-size: 100% 38 | } 39 | 40 | legend { 41 | color: #000 42 | } 43 | 44 | small { 45 | font-size: 12px 46 | } 47 | 48 | hr { 49 | border: none; 50 | height: 1px 51 | } 52 | 53 | a { 54 | text-decoration: none 55 | } 56 | 57 | a:hover { 58 | text-decoration: none 59 | } 60 | 61 | body { 62 | background-color: #fff 63 | } 64 | 65 | #app { 66 | width: 100%; 67 | overflow: hidden; 68 | font-family: 'Source Sans Pro', 'Lucida Grande', sans-serif; 69 | } 70 | 71 | /*路由动画*/ 72 | .fade-enter-active, .fade-leave-active { 73 | transition: all .4s linear; 74 | -webkit-transition: all .4s linear; 75 | -webkit-transform: translate3d(-20px, 0px, 0); 76 | transform: translate3d(-20px, 0px, 0) 77 | } 78 | html { 79 | overflow: auto; 80 | } 81 | .fade-enter, .fade-leave-to { 82 | opacity: 0; 83 | -webkit-transform: translate3d(0, 0px, 0); 84 | transform: translate3d(0, 0px, 0); 85 | } 86 | 87 | /*导航*/ 88 | .nav { 89 | width: 100%; 90 | height: 106px !important; 91 | position: fixed; 92 | top: 0px; 93 | left: 0px; 94 | z-index: 99; 95 | background-color: #fafafa; 96 | border-top: 4px solid #4267b2; 97 | box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1), 0 1px rgba(66, 66, 66, 0.1); 98 | z-index: 99999; 99 | } 100 | 101 | .nav-bar { 102 | height: 100%; 103 | display: block !important; 104 | margin: 0 auto; 105 | position: relative; 106 | float: none !important; 107 | } 108 | 109 | .container_article { 110 | margin: 0 auto; 111 | float: none !important; 112 | margin-top: 120px; 113 | overflow: hidden; 114 | box-sizing: border-box 115 | } 116 | 117 | .mobile-nav-bar { 118 | float: left; 119 | } 120 | 121 | .nav-bar-inner { 122 | height: 100%; 123 | width: 80px; 124 | float: left; 125 | text-align: center; 126 | color: #32D3C3; 127 | font-size: 18px; 128 | position: absolute; 129 | left: 0px; 130 | top: 0px; 131 | } 132 | 133 | .nav-bar-inner > span { 134 | width: 85%; 135 | float: left; 136 | } 137 | 138 | .nav-bar-body { 139 | float: left; 140 | width: 100%; 141 | height: 64px; 142 | padding-left: 100px; 143 | position: relative; 144 | 145 | } 146 | 147 | .nav-bar-body > ul > li { 148 | height: 100%; 149 | text-align: center; 150 | color: #666; 151 | font-size: 18px; 152 | padding-right: 20px; 153 | float: left; 154 | } 155 | 156 | .nav-bar-body .borderRightActive { 157 | border-right: 4px solid #32D3C3; 158 | color: #32D3C3; 159 | } 160 | 161 | .navmenu { 162 | width: 100%; 163 | height: 42px; 164 | position: absolute; 165 | bottom: 0px; 166 | border-top: 1px solid #eee; 167 | padding-right: 190px 168 | } 169 | 170 | .navmenu ul { 171 | overflow: hidden; 172 | height: 100% 173 | } 174 | 175 | .navmenu ul a { 176 | float: left; 177 | padding-left: 12px; 178 | padding-right: 12px; 179 | line-height: 42px; 180 | } 181 | 182 | .nav-bar-body > ul > li:hover { 183 | height: 8vh; 184 | line-height: 8vh; 185 | text-align: center; 186 | color: #32D3C3; 187 | cursor: pointer; 188 | background-color: #26252f; 189 | } 190 | 191 | .nav-bar-footer { 192 | height: 8vh; 193 | line-height: 8vh; 194 | text-align: center; 195 | color: #666; 196 | font-size: 13px; 197 | } 198 | 199 | /*页面主体*/ 200 | .main { 201 | background-color: #fff; 202 | padding-bottom: 20px; 203 | } 204 | 205 | .navmenu ul a:hover { 206 | background-color: #eee; 207 | border-radius: 5px; 208 | } 209 | 210 | .footer { 211 | text-align: center; 212 | padding: 6px 0px; 213 | color: #b3b3b3; 214 | margin-top: 40px; 215 | font-size: 12px; 216 | letter-spacing: 2px 217 | } 218 | 219 | /*code*/ 220 | .detail-body pre { 221 | background-color: #272822 !important; 222 | margin-top: 10px; 223 | overflow-x: auto !important; 224 | font-size: 16px; 225 | position: relative; 226 | padding: 10px; 227 | padding-left: 42px !important; 228 | border-radius: 4px; 229 | } 230 | 231 | .detail-body pre:before { 232 | content: ''; 233 | height: 100%; 234 | width: 28px; 235 | background-color: #373737; 236 | display: block; 237 | position: absolute; 238 | left: 0px; 239 | top: 0px; 240 | border-radius: 0px 5px 5px 0px; 241 | overflow: hidden; 242 | box-shadow: 1px 0px 2px rgba(36, 36, 36, .2) 243 | } 244 | .detail-body p code, .detail-body li>code{ 245 | background-color: #eee; 246 | padding: 2px 8px; 247 | border: 1px solid #e0e0e0; 248 | border-radius: 3px; 249 | line-height: 18px; 250 | margin: 0px 3px; 251 | margin-bottom: 2px; 252 | display: inline-block; 253 | } 254 | .detail-body table tr { 255 | background-color: #fff; 256 | border-top: 1px solid #c6cbd1; 257 | } 258 | .detail-body table th, .detail-body table td { 259 | padding: 6px 13px; 260 | border: 1px solid #dfe2e5; 261 | color: #333; 262 | } 263 | .detail-body ol { 264 | padding-left: 20px; 265 | margin-bottom: 10px; 266 | } 267 | .detail-body table tr:nth-child(2n) { 268 | background-color: #f6f8fa; 269 | } 270 | 271 | #articlesDetails { 272 | overflow: inherit !important; 273 | height: auto !important; 274 | padding-bottom: 50px; 275 | } 276 | 277 | .detail-body pre code { 278 | color: #fff; 279 | /*font-family: "Fira Mono", "Andale Mono", "Consolas", monospace;*/ 280 | font-family: monospace,monospace; 281 | letter-spacing: 0px; 282 | line-height: 24px; 283 | } 284 | 285 | .detail-body hr { 286 | border: inherit !important; 287 | background-color: #D3DCE6; 288 | margin-top: 10px; 289 | margin-bottom: 10px; 290 | } 291 | 292 | .detail-body blockquote { 293 | background-color: #EFF2F7; 294 | padding: 10px; 295 | border-left: 10px solid #D3DCE6; 296 | color: #D3DCE6; 297 | margin-bottom: 10px; 298 | } 299 | 300 | .detail-body h1 { 301 | font-size: 22px; 302 | font-weight: 900; 303 | margin-bottom: 20px; 304 | margin-top: 8px; 305 | color: #333 306 | } 307 | 308 | .detail-body h2 { 309 | font-size: 20px; 310 | font-weight: 900; 311 | line-height: 28px; 312 | margin-bottom: 10px; 313 | color: #444 314 | } 315 | 316 | .detail-body h3 { 317 | font-size: 18px; 318 | font-weight: 900; 319 | line-height: 28px; 320 | margin-bottom: 10px; 321 | color: #444 322 | } 323 | 324 | .detail-body h4 { 325 | font-size: 17px; 326 | font-weight: 900; 327 | line-height: 28px; 328 | margin-bottom: 10px; 329 | color: #555 330 | } 331 | 332 | .detail-body blockquote { 333 | margin-top: 14px; 334 | margin-bottom: 14px; 335 | } 336 | 337 | .detail-body p { 338 | font-size: 16px; 339 | line-height: 24px; 340 | margin-bottom: 8px; 341 | color: rgb(36, 41, 46); 342 | } 343 | 344 | .detail-body strong { 345 | color: rgb(0, 123, 111); 346 | } 347 | 348 | .detail-body a { 349 | text-decoration: underline; 350 | color: rgb(13, 92, 119); 351 | } 352 | .detail-body em { 353 | color: #666 354 | } 355 | 356 | .detail-body pre { 357 | margin-bottom: 15px; 358 | box-shadow: 0px -1px rgba(0, 0, 0, 0.04) 359 | } 360 | 361 | .detail-body img { 362 | width: auto; 363 | max-width: 100%; 364 | display: block; 365 | margin: 6px 0px; 366 | cursor: pointer; 367 | } 368 | 369 | .detail-body blockquote * { 370 | margin-bottom: 0px 371 | } 372 | 373 | .detail-body a:hover { 374 | color: #005e55 !important 375 | } 376 | 377 | .detail-body ul { 378 | padding-left: 28px; 379 | margin-bottom: 14px 380 | } 381 | 382 | .detail-body li { 383 | list-style: initial !important; 384 | color: #24292e 385 | } 386 | 387 | /*style*/ 388 | #app { 389 | background-color: #f4f5f5 390 | } 391 | 392 | .el-tabs__header { 393 | border: none 394 | } 395 | 396 | .container { 397 | padding: 0px 30px; 398 | margin-bottom: 30px 399 | } 400 | 401 | #logo { 402 | width: 80px; 403 | height: 60px; 404 | overflow: hidden 405 | } 406 | 407 | #logo img { 408 | width: 70%; 409 | } 410 | 411 | .artitem > div { 412 | padding: 16px 20px 0; 413 | height: 210px; 414 | overflow: hidden; 415 | background: #fff; 416 | border-top: 1px solid rgba(151, 151, 151, .08); 417 | border-radius: 3px; 418 | box-shadow: 0 1px 2px rgba(151, 151, 151, .6); 419 | margin-bottom: 30px; 420 | min-height: 100px; 421 | position: relative; 422 | overflow: hidden 423 | } 424 | 425 | .post-time { 426 | margin-top: -14px; 427 | color: #727272; 428 | font-size: 14px; 429 | } 430 | 431 | .articles-box { 432 | width: 100%; 433 | margin-top: 10px; 434 | margin-bottom: 5px; 435 | text-align: center; 436 | height: 150px; 437 | } 438 | 439 | .scrollbottomtip { 440 | font-size: 18px; 441 | text-align: center; 442 | color: #666; 443 | height: 24px; 444 | } 445 | 446 | .post-time span { 447 | display: block; 448 | text-align: left 449 | } 450 | 451 | .post-title { 452 | margin-top: 20px; 453 | } 454 | 455 | .post-title h1 { 456 | color: #1F2D3D; 457 | font-weight: 400; 458 | font-size: 20px; 459 | text-align: left; 460 | min-height: 52px; 461 | overflow: hidden 462 | } 463 | 464 | .post-abstract { 465 | color: #666; 466 | text-align: left; 467 | line-height: 22px; 468 | margin-top: 10px; 469 | max-height: 42px; 470 | overflow: hidden; 471 | text-overflow: ellipsis; 472 | display: -webkit-box; 473 | -webkit-line-clamp: 2; 474 | -webkit-box-orient: vertical; 475 | } 476 | 477 | .artitem_bottom { 478 | width: 100%; 479 | height: 40px; 480 | overflow: hidden; 481 | position: relative; 482 | border-top: 1px solid #eee; 483 | padding-top: 5px; 484 | } 485 | 486 | .avatar { 487 | float: left; 488 | width: 30px; 489 | height: 30px; 490 | margin-top: 1px; 491 | } 492 | 493 | .avatar a { 494 | display: inline-block; 495 | width: 100% 496 | } 497 | 498 | .avatar a img { 499 | float: left; 500 | width: 100% 501 | } 502 | 503 | .avatar a p { 504 | float: left; 505 | height: 80%; 506 | display: none; 507 | font-size: 14px; 508 | line-height: 50px; 509 | margin-left: 10px; 510 | color: #666 511 | } 512 | 513 | .post-label-box { 514 | display: inline-block; 515 | position: absolute; 516 | right: 0px; 517 | margin-top: 2px; 518 | } 519 | 520 | .scrollbottomtip > div { 521 | width: 140px; 522 | margin: 0 auto; 523 | } 524 | 525 | .scrollbottomtip > div > p { 526 | float: left; 527 | margin-left: 14px; 528 | } 529 | 530 | .scrollbottomtip > div > i { 531 | margin-top: 4px; 532 | color: #999; 533 | } 534 | 535 | .scrollbottomtipno { 536 | display: none !important 537 | } 538 | 539 | .scrollload, .scrolltip { 540 | display: none 541 | } 542 | 543 | .scrollloadlast { 544 | display: none !important 545 | } 546 | 547 | .el-tab-pane .el-row { 548 | padding-bottom: 30px; 549 | } 550 | 551 | .el-tabs { 552 | margin-bottom: 30px; 553 | } 554 | 555 | .hide { 556 | display: none 557 | } 558 | 559 | .lastpagetip { 560 | width: 100%; 561 | margin: 0 auto; 562 | text-align: center; 563 | font-size: 16px; 564 | color: #999; 565 | border-bottom: 1px solid #eee; 566 | padding-bottom: 6px; 567 | margin-bottom: -1px; 568 | } 569 | 570 | .post-label-box .post-label { 571 | font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif; 572 | background: #44C1B8; 573 | padding: 5px 12px; 574 | color: #fff; 575 | font-size: 14px; 576 | line-height: 18px; 577 | border-radius: 4px; 578 | box-shadow: 3px 2px 2px rgba(36, 61, 107, .1) 579 | } 580 | 581 | .post-label:nth-child(2n) { 582 | background-color: #3DB89D 583 | } 584 | 585 | .post-label:nth-child(3n) { 586 | background-color: #47A1C2 587 | } 588 | 589 | #search { 590 | position: absolute; 591 | width: 300px; 592 | right: 100px; 593 | height: 40px; 594 | margin-top: 10px; 595 | } 596 | 597 | .main { 598 | box-shadow: 0px 1px 1px 1px rgba(110, 110, 110, .1); 599 | border-radius: 3px; 600 | min-height: 900px 601 | } 602 | 603 | .artitem > div:before { 604 | position: absolute; 605 | top: 0; 606 | left: 0; 607 | width: 100%; 608 | height: 100%; 609 | background: rgba(255, 255, 255, 0.5); 610 | content: ''; 611 | -webkit-transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, 45deg) translate3d(0, -120%, 0); 612 | transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, 45deg) translate3d(0, -120%, 0); 613 | cursor: pointer 614 | } 615 | 616 | .artitem > div:hover:before { 617 | -moz-transition: all 0.6s ease-in-out; 618 | -o-transition: all 0.6s ease-in-out; 619 | -webkit-transition: all 0.6s ease-in-out; 620 | transition: all 0.6s ease-in-out; 621 | -webkit-transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, 45deg) translate3d(0, 20%, 0); 622 | transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, 45deg) translate3d(0, 20%, 0); 623 | background-color: rgba(255, 255, 255, .1) 624 | } 625 | 626 | .artitem > div:hover { 627 | background-color: #fafafa; 628 | -moz-transition: all 0.3s ease-in-out; 629 | -o-transition: all 0.3s ease-in-out; 630 | -webkit-transition: all 0.3s ease-in-out; 631 | transition: all 0.3s ease-in-out; 632 | box-shadow: 0px 1px 1px 1px rgba(0, 0, 0, .1); 633 | border-top: 1px solid #fff; 634 | border-radius: 3px; 635 | } 636 | 637 | .artitem { 638 | padding-top: 4px; 639 | } 640 | 641 | .articles-box { 642 | cursor: pointer 643 | } 644 | 645 | .artitem:hover .post-title > h1 { 646 | color: #1D8CE0 !important; 647 | -moz-transition: all 0.3s ease-in-out; 648 | -o-transition: all 0.3s ease-in-out; 649 | -webkit-transition: all 0.3s ease-in-out; 650 | transition: all 0.3s ease-in-out; 651 | } 652 | 653 | .artitem:hover { 654 | -moz-transition: all 0.3s ease-in-out; 655 | -o-transition: all 0.3s ease-in-out; 656 | -webkit-transition: all 0.3s ease-in-out; 657 | transition: all 0.3s ease-in-out; 658 | -webkit-transform: translate3d(0, -3px, 0); 659 | } 660 | 661 | #addacticlebtn { 662 | position: absolute; 663 | right: 0px; 664 | top: 4px; 665 | height: 33px; 666 | background-color: #4cbcfe; 667 | border-color: #4cbcfe 668 | } 669 | 670 | #gomobilebtn { 671 | position: absolute; 672 | right: 90px; 673 | top: 4px; 674 | height: 33px; 675 | background-color: #4cbcfe; 676 | border-color: #4cbcfe 677 | } 678 | 679 | #avatar { 680 | margin-top: 10px; 681 | width: 36px; 682 | height: 36px; 683 | overflow: hidden; 684 | float: right; 685 | margin-right: 15px; 686 | } 687 | 688 | #avatar img { 689 | width: 100%; 690 | } 691 | 692 | /*点击效果*/ 693 | .el-tabs__item { 694 | position: relative; 695 | overflow: hidden 696 | } 697 | 698 | .el-tabs__item:after { 699 | content: ""; 700 | background: rgba(76, 188, 254, 0.44); 701 | display: block; 702 | position: absolute; 703 | border-radius: 50%; 704 | padding-top: 240%; 705 | padding-left: 240%; 706 | margin-top: -120%; 707 | margin-left: -120%; 708 | opacity: 0; 709 | transition: all .8s 710 | } 711 | 712 | .el-tabs__item:active:after { 713 | padding-top: 0; 714 | padding-left: 0; 715 | margin-top: 0; 716 | margin-left: 0; 717 | opacity: 1; 718 | transition: 0s 719 | } 720 | 721 | .el-tabs__active-bar { 722 | background-color: #4cbcfe !important; 723 | } 724 | 725 | .el-tabs__item.is-active { 726 | color: #4cbcfe !important 727 | } 728 | 729 | .navmenu button span { 730 | position: relative; 731 | top: -2px 732 | } 733 | 734 | .navmenu button { 735 | padding-left: 28px 736 | } 737 | 738 | .navmenu button i { 739 | position: absolute; 740 | top: -2px; 741 | font-size: 18px; 742 | left: 8px; 743 | top: 6px 744 | } 745 | 746 | #gomobilebtn i { 747 | top: 7px 748 | } 749 | 750 | .tagtitle { 751 | width: 120%; 752 | margin-left: -10%; 753 | padding-left: 12%; 754 | height: 100px; 755 | background-color: #1c96e0; 756 | box-sizing: border-box 757 | } 758 | 759 | @keyframes fadeInDown { 760 | from { 761 | opacity: 0; 762 | transform: translate3d(0, -10px, 0); 763 | } 764 | 765 | to { 766 | opacity: 1; 767 | transform: none; 768 | } 769 | } 770 | 771 | .fadetitle { 772 | animation-name: fadeInDown; 773 | animation-duration: 1s; 774 | animation-fill-mode: both; 775 | } 776 | 777 | .tagtitle { 778 | margin-bottom: 40px; 779 | } 780 | 781 | .el-tabs__item { 782 | font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif; 783 | } 784 | 785 | .tagtitle > p { 786 | font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif; 787 | color: #fff; 788 | font-size: 26px; 789 | font-weight: 900; 790 | padding-top: 30px; 791 | opacity: 0; 792 | -webkit-transform: translate3d(0, -6px, 0); 793 | transform: translate3d(0, -6px, 0); 794 | } 795 | 796 | .el-tabs__active-bar { 797 | background-color: #32D3C3; 798 | } 799 | 800 | .el-tabs__item { 801 | color: #666 !important; 802 | } 803 | 804 | .el-tabs__nav-wrap { 805 | position: relative; 806 | top: -2px 807 | } 808 | 809 | .el-tabs__nav-wrap::after { 810 | display: none !important 811 | } 812 | 813 | .post-label { 814 | background-color: rgba(1, 126, 102, 0.08); 815 | color: #017E66; 816 | padding: 0.1rem 0.5rem; 817 | font-size: 12px; 818 | float: left; 819 | margin-left: 10px; 820 | } 821 | 822 | .post-label { 823 | margin-bottom: 4px; 824 | } 825 | 826 | .el-card__body { 827 | border-bottom: 1px dotted #eee 828 | } 829 | 830 | #addacticlebtn:hover { 831 | background-color: #1ca0ee; 832 | border-color: #1ca0ee; 833 | -moz-transition: all 0.3s ease-in-out; 834 | -o-transition: all 0.3s ease-in-out; 835 | -webkit-transition: all 0.3s ease-in-out; 836 | transition: all 0.3s ease-in-out; 837 | } 838 | 839 | #gomobilebtn:hover { 840 | background-color: #1ca0ee; 841 | border-color: #1ca0ee; 842 | -moz-transition: all 0.3s ease-in-out; 843 | -o-transition: all 0.3s ease-in-out; 844 | -webkit-transition: all 0.3s ease-in-out; 845 | transition: all 0.3s ease-in-out; 846 | } 847 | 848 | ::selection { 849 | background: #32acb4; 850 | color: #fff; 851 | } 852 | 853 | ::-moz-selection { 854 | background: #32acb4; 855 | color: #fff; 856 | } 857 | 858 | /*gitcont*/ 859 | .gitment-comments-empty { 860 | display: none 861 | } 862 | 863 | .gitment-editor-submit { 864 | border-radius: 3px 865 | } 866 | 867 | .gitment-comments-list { 868 | padding-bottom: 25px 869 | } 870 | 871 | #container { 872 | padding: 0px 10px 873 | } 874 | 875 | @-webkit-keyframes zoomInDown { 876 | 0% { 877 | opacity: 0; 878 | -webkit-transform: scale3d(.1, .1, .1) translate3d(0, -1000px, 0); 879 | transform: scale3d(.1, .1, .1) translate3d(0, -1000px, 0); 880 | -webkit-animation-timing-function: cubic-bezier(0.55, .055, .675, .19); 881 | animation-timing-function: cubic-bezier(0.55, .055, .675, .19) 882 | } 883 | 60% { 884 | opacity: 1; 885 | -webkit-transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0); 886 | transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0); 887 | -webkit-animation-timing-function: cubic-bezier(0.175, .885, .32, 1); 888 | animation-timing-function: cubic-bezier(0.175, .885, .32, 1) 889 | } 890 | } 891 | 892 | @keyframes artitemanimate { 893 | 0% { 894 | opacity: 0; 895 | -webkit-transform: translate3d(0, 10px, 0); 896 | -ms-transform: translate3d(0, 10px, 0); 897 | transform: translate3d(0, 10px, 0); 898 | } 899 | 80% { 900 | opacity: 1; 901 | -webkit-transform: translate3d(0, 0px, 0); 902 | -ms-transform: translate3d(0, 0px, 0); 903 | transform: translate3d(0, 0px, 0); 904 | } 905 | } 906 | 907 | .artitem > div { 908 | -webkit-animation-name: artitemanimate; 909 | animation-name: artitemanimate; 910 | -webkit-animation-duration: 1s; 911 | animation-duration: 1s; 912 | -webkit-animation-fill-mode: both; 913 | animation-fill-mode: both 914 | } 915 | 916 | @media (min-width: 1200px) { 917 | .el-col-lg-16 { 918 | width: 1200px !important; 919 | } 920 | } 921 | 922 | .el-col-md-22 { 923 | -moz-transition: all 0.6s ease-in-out; 924 | -o-transition: all 0.6s ease-in-out; 925 | -webkit-transition: all 0.6s ease-in-out; 926 | transition: all 0.6s ease-in-out; 927 | } 928 | 929 | @media screen and (max-width: 768px) { 930 | .main { 931 | padding-bottom: 0px; 932 | } 933 | #search { 934 | right: 80px; 935 | width: 164px; 936 | } 937 | 938 | .tagtitle { 939 | height: 60px; 940 | margin-bottom: 15px; 941 | } 942 | 943 | .tagtitle > p { 944 | padding-top: 14px; 945 | font-size: 24px; 946 | } 947 | 948 | .el-tabs__content { 949 | padding: 0px 20px; 950 | } 951 | 952 | .main { 953 | background-color: #fafafa 954 | } 955 | 956 | .post-title { 957 | margin-top: 15px; 958 | } 959 | 960 | #articlesDetails { 961 | width: 100% !important; 962 | padding: 0px !important 963 | } 964 | 965 | .detail-header { 966 | min-height: 100px !important; 967 | padding-bottom: 40px; 968 | padding-right: 15px; 969 | box-sizing: border-box; 970 | width: 100% !important; 971 | margin: 0px !important; 972 | padding-left: 20px !important 973 | } 974 | 975 | .detail-body-tag { 976 | padding-top: 1px 977 | } 978 | 979 | .detail-header h1 { 980 | font-size: 18px !important; 981 | padding-bottom: 20px; 982 | padding-top: 18px !important; 983 | word-wrap: break-word; 984 | font-size: 18px; 985 | padding-left: 0px !important; 986 | width: 100% !important; 987 | } 988 | 989 | .time { 990 | float: left; 991 | margin-right: 20px 992 | } 993 | 994 | .detail-body h1 { 995 | font-size: 18px; 996 | } 997 | 998 | .detail-body { 999 | background-color: #fafafa; 1000 | padding: 15px !important; 1001 | padding-top: 15px !important 1002 | } 1003 | .detail-body pre code { 1004 | word-wrap: break-word !important; 1005 | width: 100% !important; 1006 | display: block; 1007 | overflow: scroll; 1008 | font-family: monospace,monospace; 1009 | } 1010 | 1011 | #addacticlebtn { 1012 | display: none !important 1013 | } 1014 | 1015 | #gomobilebtn { 1016 | display: none !important 1017 | } 1018 | 1019 | .navmenu { 1020 | padding: 0px 10px 1021 | } 1022 | 1023 | .footer { 1024 | display: none 1025 | } 1026 | .comment-text { 1027 | padding-bottom: 40px !important; 1028 | } 1029 | .post-title h1 { 1030 | height: 54px !important; 1031 | overflow: hidden; 1032 | text-overflow: ellipsis; 1033 | display: -webkit-box; 1034 | -webkit-line-clamp: 2; 1035 | -webkit-box-orient: vertical; 1036 | } 1037 | 1038 | .detail-header .time { 1039 | padding-left: 0px !important 1040 | } 1041 | 1042 | } 1043 | -------------------------------------------------------------------------------- /utils/index.js: -------------------------------------------------------------------------------- 1 | export function dateFormat(){ 2 | Date.prototype.format = function(format) { 3 | var o = { 4 | "M+": this.getMonth() + 1, //month 5 | "d+": this.getDate(), //day 6 | "h+": this.getHours(), //hour 7 | "m+": this.getMinutes(), //minute 8 | "s+": this.getSeconds(), //second 9 | "q+": Math.floor((this.getMonth() + 3) / 3), //quarter 10 | "S": this.getMilliseconds() //millisecond 11 | } 12 | if (/(y+)/.test(format)) { 13 | format = format.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length)); 14 | } 15 | for (var k in o){ 16 | if (new RegExp("(" + k + ")").test(format)){ 17 | format = format.replace(RegExp.$1,RegExp.$1.length == 1 ? o[k] :("00" + o[k]).substr(("" + o[k]).length)); 18 | } 19 | } 20 | return format; 21 | } 22 | } 23 | 24 | --------------------------------------------------------------------------------