Compare commits
215 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6662fa4c5 | ||
|
|
a570c783f3 | ||
|
|
e2046d0d39 | ||
|
|
cdbe082764 | ||
|
|
3a86c6a65c | ||
|
|
c1c9e6025a | ||
|
|
a15791a792 | ||
|
|
ea87f4b2e6 | ||
|
|
a0653cf67f | ||
|
|
397d47bc00 | ||
|
|
00d9df4406 | ||
|
|
2b277bd901 | ||
|
|
c18f3b7da9 | ||
|
|
79ac024312 | ||
|
|
1e4c0afc19 | ||
|
|
055d7d2164 | ||
|
|
ed7c510744 | ||
|
|
488c0f04fe | ||
|
|
a99ed9504b | ||
|
|
6cde9323b1 | ||
|
|
2b226977ab | ||
|
|
aa076e5e3c | ||
|
|
26635790e1 | ||
|
|
569a1fe2a1 | ||
|
|
182eaff085 | ||
|
|
90e7082322 | ||
|
|
e71e42571f | ||
|
|
3527e11b04 | ||
|
|
a407bdfe72 | ||
|
|
05aa254e70 | ||
|
|
4ec3065f9d | ||
|
|
7bec238f9c | ||
|
|
605787958d | ||
|
|
c06f02622a | ||
|
|
f431bf5adc | ||
|
|
7922043bc6 | ||
|
|
2fbc5fa024 | ||
|
|
9c341f88d2 | ||
|
|
0ae5e6c9fc | ||
|
|
3e2b746319 | ||
|
|
2cd72e190e | ||
|
|
1c955769f4 | ||
|
|
a2769f0913 | ||
|
|
bf3d45a404 | ||
|
|
4b92636079 | ||
|
|
753aaa4ace | ||
|
|
43d7a26e19 | ||
|
|
872d0b1987 | ||
|
|
897b05d071 | ||
|
|
c5a3bd6eab | ||
|
|
beea4f1746 | ||
|
|
9f563f0ae9 | ||
|
|
4749b1e681 | ||
|
|
a39e3aac3b | ||
|
|
63b55b2df8 | ||
|
|
cb091532d5 | ||
|
|
6b74e1d208 | ||
|
|
1815cea2cd | ||
|
|
c3fdbfcb78 | ||
|
|
990e6abbd8 | ||
|
|
bb40570053 | ||
|
|
e2df642a46 | ||
|
|
68e01cdf1f | ||
|
|
bd69c62254 | ||
|
|
970c6068d5 | ||
|
|
27a1f600de | ||
|
|
edf0fbac51 | ||
|
|
98ca570a36 | ||
|
|
9a526f97f8 | ||
|
|
33a29f5e57 | ||
|
|
30ebf76eda | ||
|
|
f5c0bcdb99 | ||
|
|
4b53da3801 | ||
|
|
1bdfb6abea | ||
|
|
33f47d8f3a | ||
|
|
cbd0cfaaf5 | ||
|
|
080c992a92 | ||
|
|
371b2326ea | ||
|
|
2720d11b23 | ||
|
|
b7751d7b9e | ||
|
|
24d81db8be | ||
|
|
010137ebf5 | ||
|
|
c6a2439c54 | ||
|
|
1d54ff3ac5 | ||
|
|
63a4d69209 | ||
|
|
b35d7de58a | ||
|
|
77ea01b7c1 | ||
|
|
5f608b638d | ||
|
|
52da8abceb | ||
|
|
f016b28cb6 | ||
|
|
01b7643ca5 | ||
|
|
375d43761b | ||
|
|
f3e9727947 | ||
|
|
911aa963c7 | ||
|
|
fb66b6871e | ||
|
|
5ae76f243e | ||
|
|
051b034e51 | ||
|
|
27439ecc71 | ||
|
|
d02c838447 | ||
|
|
d17acf5325 | ||
|
|
b278ca377f | ||
|
|
93131441e4 | ||
|
|
ddcc6c2d2e | ||
|
|
ef63ae9598 | ||
|
|
2ed9db5c7b | ||
|
|
06a12bc6f9 | ||
|
|
6524b45751 | ||
|
|
ceb9e2690b | ||
|
|
405fbaf24f | ||
|
|
3245c0e0d3 | ||
|
|
badc62e3f0 | ||
|
|
a5561f257b | ||
|
|
eb37b83ebd | ||
|
|
b2fab703fc | ||
|
|
37deb390d9 | ||
|
|
6fa5088352 | ||
|
|
e023a33786 | ||
|
|
6f818c4b5d | ||
|
|
9ad22fb2d9 | ||
|
|
fc37d5e093 | ||
|
|
61024bfebd | ||
|
|
f20c4a6063 | ||
|
|
c24e6bf7bd | ||
|
|
ade94168d3 | ||
|
|
552d010650 | ||
|
|
1c3106cbb0 | ||
|
|
168937f1b2 | ||
|
|
730cffcb5b | ||
|
|
8c3f1c2aba | ||
|
|
ea375ea76c | ||
|
|
275a6c0c31 | ||
|
|
360204995d | ||
|
|
c9fc0cc75a | ||
|
|
41daaa322e | ||
|
|
894535fbe5 | ||
|
|
6fc5af1b0f | ||
|
|
5ce806a7d7 | ||
|
|
25cb23fdb3 | ||
|
|
a89a1a2bc9 | ||
|
|
93e170f9ac | ||
|
|
59d9a616aa | ||
|
|
2ff0934206 | ||
|
|
cde7cba2f0 | ||
|
|
2be7501afe | ||
|
|
487d35dae2 | ||
|
|
19af9376cb | ||
|
|
3ddd2a0b33 | ||
|
|
ee7523b124 | ||
|
|
cc1dbac1f0 | ||
|
|
04532ba8a6 | ||
|
|
0a2a132b11 | ||
|
|
3ff712d407 | ||
|
|
27162d2205 | ||
|
|
f150974566 | ||
|
|
b94fc825b3 | ||
|
|
d8f0e30285 | ||
|
|
e0a5f0ebca | ||
|
|
c18d9c0bef | ||
|
|
e1ec5cd08a | ||
|
|
5efdd72e58 | ||
|
|
b9470fa14c | ||
|
|
a932d2906d | ||
|
|
3ff5977941 | ||
|
|
da7b726e8d | ||
|
|
3923bc70f1 | ||
|
|
8dc73fd67c | ||
|
|
2825bbfeae | ||
|
|
66811830b0 | ||
|
|
c4bf59ce5d | ||
|
|
6cea283f86 | ||
|
|
3992db49ba | ||
|
|
055c2307cb | ||
|
|
11b0f486cd | ||
|
|
ed0a50b626 | ||
|
|
cf2b2d6d34 | ||
|
|
00456806bb | ||
|
|
54f5289d6b | ||
|
|
1634418a13 | ||
|
|
a84a474504 | ||
|
|
b64cf5985a | ||
|
|
4f9965b6bd | ||
|
|
daffa6c294 | ||
|
|
0bd738438e | ||
|
|
309339492c | ||
|
|
694036c65f | ||
|
|
cafdaac9f4 | ||
|
|
f6956f592f | ||
|
|
2382f76cf6 | ||
|
|
a66a3c0198 | ||
|
|
31c398700e | ||
|
|
9296147a0f | ||
|
|
6932799cba | ||
|
|
b1ff8b59af | ||
|
|
5f047c2c27 | ||
|
|
5d24af11e5 | ||
|
|
d03f327fb4 | ||
|
|
ef9e64469b | ||
|
|
86e7374997 | ||
|
|
4f24b80107 | ||
|
|
2c49a1ec8d | ||
|
|
3eaab0fb1f | ||
|
|
8e6404a90a | ||
|
|
7775ea35a2 | ||
|
|
931d7b0683 | ||
|
|
562f4d86c6 | ||
|
|
4ebbc38cc0 | ||
|
|
9509cd66e6 | ||
|
|
48756a2810 | ||
|
|
ec8297c3f6 | ||
|
|
d622a8397f | ||
|
|
c75619785d | ||
|
|
c014c6450b | ||
|
|
d8879f8d32 | ||
|
|
9bb0905aab | ||
|
|
c39844ca63 |
@@ -1,17 +1,12 @@
|
||||
.git
|
||||
vendor
|
||||
setting
|
||||
conf
|
||||
static
|
||||
views
|
||||
!static/tzdata
|
||||
Dockerfile
|
||||
glide.yaml
|
||||
glide.lock
|
||||
*.yml
|
||||
*.md
|
||||
*.go
|
||||
*.sh
|
||||
*.DS_Store
|
||||
.gitignore
|
||||
.dockerignore
|
||||
# Ignore all files and dirs
|
||||
*
|
||||
|
||||
# Unignore files or dirs
|
||||
!build
|
||||
!bin
|
||||
!conf
|
||||
!assets
|
||||
!website
|
||||
!CHANGELOG.md
|
||||
!LICENSE
|
||||
!README.md
|
||||
|
||||
49
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
name: release image & asset
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
package:
|
||||
runs-on: ubuntu-16.04
|
||||
steps:
|
||||
- name: Golang env
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ^1.15
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Cache mod
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
- name: Docker tag
|
||||
id: vars
|
||||
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Docker login
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
- name: Build image
|
||||
run: scripts/run_build.sh deepzz0 ${{ steps.vars.outputs.tag }}
|
||||
|
||||
- name: Package tar
|
||||
run: scripts/dist_tar.sh ${{ steps.vars.outputs.tag }}
|
||||
- name: Release push
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
files: |
|
||||
*.tar.gz
|
||||
27
.gitignore
vendored
@@ -1,10 +1,21 @@
|
||||
*.DS_Store
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
vendor
|
||||
vendor/**
|
||||
conf/ssl/domain.*
|
||||
eiblog
|
||||
static/feed.xml
|
||||
static/opensearch.xml
|
||||
static/sitemap.xml
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
*.DS_Store
|
||||
*.tar.gz
|
||||
*.db
|
||||
backend
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
bin
|
||||
assets/*.*
|
||||
|
||||
44
.travis.yml
@@ -1,44 +0,0 @@
|
||||
sudo: required # 超级权限
|
||||
|
||||
dist: trusty # 在ubuntu:trusty
|
||||
|
||||
language: go # 声明构建语言环境
|
||||
|
||||
go: # 只构建最新版本
|
||||
- tip
|
||||
|
||||
services: # docker环境
|
||||
- docker
|
||||
|
||||
# branches: # 限定项目分支
|
||||
# only:
|
||||
# - master
|
||||
|
||||
before_install:
|
||||
- curl https://glide.sh/get | sh # 安装glide包管理
|
||||
|
||||
script:
|
||||
- glide up
|
||||
- GOOS=linux GOARCH=amd64 go build # 编译版本
|
||||
- docker build -t registry.cn-hangzhou.aliyuncs.com/deepzz/eiblog . # 构建镜像
|
||||
|
||||
after_success:
|
||||
- if [ "$TRAVIS_BRANCH" =~ ^v[0-9](\.[0-9])+.*$ ]; then
|
||||
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" registry.cn-hangzhou.aliyuncs.com;
|
||||
docker push registry.cn-hangzhou.aliyuncs.com/deepzz/eiblog;
|
||||
fi
|
||||
|
||||
before_deploy:
|
||||
- ./dist.sh
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: AGW05sQuQfjy77+JprSV+ohti/VVgFuh7UOTV0+hwxqsOVXSoIQz/ZPOlHWPP1iiSiGGEalspm+UtKRvADcDfllUaEwo7kebfFeMx4X//qxFxQSQ5LJYx7qxsTDpuQ4CF8zifCtND3ynnUAdx0P6FFkxE/67kN2n4CrhIxYCUb8gNPzDDRuS0ZNBC4zzNldJo/vtatbvc2btuFfwKoClYf+xPLy5luLqDvKF+hdjJ8NuZl8BWkWxXE+kk8fW4iUn2IV0qtLRZ3FQUyAF2CumzxqZfViX+rYTXsfbabYY5nYG6opT4mUEF58T4X3uRV0e3Q6Fe73nmLh9cyAoQl1BTSJ1XiyV4eJJWcKEMY7DqJ646lzoUT449YwvTK57klcfBbShpcjFf2alVdEbr9jbEXrCkuWKnssO9VfufhYF6t9h22c79evpexpIbsoncPD+b+n712MzufREtUF4kpUdkIir5n9CgQl/l7S+fV+n+gME+mcA44K7iPXkC80UfxJiw83QizT39OQhExq6SPIwrbt2vlAkBpSLMUS9iAHtTJYUsmH1SsmrxGK3WromKysWeTRJbcAJls2k6V313sn4TuYBWiHTUfsUBhv+objDFA2TsfO+g0g1JsdfZb5EsKrqNvs/2ta1xlzdE0+/TLG/YNKIOPkHnXswAM3DZm3zEss=
|
||||
skip_cleanup: true
|
||||
file: "*.tar.gz"
|
||||
file_glob: true
|
||||
on:
|
||||
tags: true
|
||||
repo: eiblog/eiblog
|
||||
all_branches: true
|
||||
40
CHANGELOG.md
@@ -1,12 +1,32 @@
|
||||
# Eiblog Changelog
|
||||
# Changelog
|
||||
|
||||
## v1.0.0 (2016-01-09)
|
||||
首次发布版本
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
* 全站`HTTPS`设计,安全、极速。
|
||||
* `Elasticsearch`博客搜索系统。
|
||||
* 开源`Typecho`完整博客后台。
|
||||
* 全功能`Markdown`编辑器。
|
||||
* 异步`Google analysts`分析统计。
|
||||
* `Disqus`评论系统。
|
||||
* 后台直接对接七牛`CDN`。
|
||||
### [2.1.1](https://github.com/eiblog/eiblog/compare/v2.1.0...v2.1.1) (2021-07-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* sqlite error ([e2046d0](https://github.com/eiblog/eiblog/commit/e2046d0d39d9914473fe7b8fae3b18246ed133ce))
|
||||
|
||||
### [2.0.6](https://github.com/eiblog/eiblog/compare/v2.0.5...v2.0.6) (2021-05-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* workdir loop ([2b277bd](https://github.com/eiblog/eiblog/commit/2b277bd90188d53b90fddd0f6a8edad00f888f53))
|
||||
* workdir path error ([c18f3b7](https://github.com/eiblog/eiblog/commit/c18f3b7da96e3181b40867a88f9c8cad042d2f44))
|
||||
|
||||
## [1.1.0](https://github.com/deepzz0/appdemo/compare/v1.0.0...v1.1.0) (2020-12-18)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **docker:** make build, build docker image ([3ac2b8b](https://github.com/deepzz0/appdemo/commit/3ac2b8b2efadf024dfcf58e7ef8341b1a89cf1b1))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* config path fixed [#1](https://github.com/deepzz0/appdemo/issues/1) ([4343eb4](https://github.com/deepzz0/appdemo/commit/4343eb44e8fffc6825be57393e024c75c4f68b7b))
|
||||
|
||||
## 1.0.0 (2020-10-31)
|
||||
|
||||
11
Dockerfile
@@ -1,11 +0,0 @@
|
||||
FROM alpine
|
||||
MAINTAINER deepzz <deepzz.qi@gmail.com>
|
||||
|
||||
RUN apk update
|
||||
RUN apk add ca-certificates
|
||||
ADD static/tzdata/Shanghai /etc/localtime
|
||||
|
||||
COPY . /eiblog
|
||||
EXPOSE 9000
|
||||
WORKDIR /eiblog
|
||||
ENTRYPOINT ["./eiblog"]
|
||||
3
LICENSE
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Manuel Martínez-Almeida
|
||||
Copyright (c) 2020-NOW deepzz0 <deepzz.qi@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
31
Makefile
Normal file
@@ -0,0 +1,31 @@
|
||||
.PHONY: demo build swag
|
||||
|
||||
tag=`git describe --abbrev=0 --tags`
|
||||
|
||||
swag:
|
||||
@scripts/swag_init.sh
|
||||
|
||||
_app:
|
||||
@scripts/new_app.sh
|
||||
|
||||
# below you should write
|
||||
|
||||
# run eiblog app
|
||||
eiblog:
|
||||
@scripts/run_app.sh eiblog
|
||||
|
||||
# run backup app
|
||||
backup:
|
||||
@scripts/run_app.sh backup
|
||||
|
||||
# dist tar
|
||||
dist:
|
||||
@scripts/dist_tar.sh $(tag)
|
||||
|
||||
# clean
|
||||
clean:
|
||||
@rm -rf bin && rm -f *.tar.gz && rm -f backend
|
||||
|
||||
# protoc
|
||||
protoc:
|
||||
@cd pkg/proto && make protoc
|
||||
335
README.md
@@ -1,308 +1,109 @@
|
||||
# EiBlog [](https://travis-ci.org/eiblog/eiblog)
|
||||
# EiBlog [](https://travis-ci.org/eiblog/eiblog) [](LICENSE.md) [](https://github.com/eiblog/eiblog/releases)
|
||||
|
||||
> 系统根据[https://imququ.com](https://imququ.com)一系列文章和方向进行搭建,期间获得了QuQu的很大帮助,在此表示感谢。
|
||||
> 博客项目结构参考模版:https://github.com/deepzz0/appdemo
|
||||
|
||||
用过其它博客系统,不喜欢,不够轻,不够快!自己做过共两款博客系统,完美主义的我(毕竟处女座)也实在是不想再在这件事情上过多纠结了。`Eiblog`应该是一个比较稳定的博客系统,且是博主以后使用的博客系统,稳定性和维护你是不用担心的,唯独该系统部署过程太过复杂,并且不推荐没有计算机知识的朋友搭建,欢迎咨询。该博客的个中优点(明显快,安全),等你体验。
|
||||
用过其它博客系统,不喜欢,不够轻,不够快!这是我开发的第二款博客系统,也实在不想再在这件事情上过多纠结了。`EiBlog` 是一个比较稳定的博客系统,现已迭代至 `2.0` 版本,稳定性和维护你是不用担心的。
|
||||
|
||||
<!--more-->
|
||||
但它有着部署简单(上线复杂!)的特点,不推荐没有计算机知识的朋友搭建,欢迎咨询。该博客的个中优点(简洁、轻快,安全),等你体验。
|
||||
|
||||
### 介绍
|
||||
整个博客系统涉及到模块如下:
|
||||
### 快速体验
|
||||
|
||||
* `MongoDB`,博客采用 mongodb 作为存储数据库。
|
||||
* `Elasticsearch`,采用`elasticsearch`作为博客的站内搜索,尽管占用内存稍高。
|
||||
* `Disqus`,作为博客评论系统,国内大部分被墙,故实现两种评论方式。
|
||||
* `Nginx`,作为反向代理服务器,并做相关`http header`和证书的设置。
|
||||
* `Google Analytics`,作为博客系统的数据分析统计工具。
|
||||
* `七牛 CDN`,作为博客系统的静态文件存储,博文的图片附件什么上传至这里。
|
||||
这里以 mongodb 为例,更多支持的后端存储服务如下:
|
||||
|
||||
相关技术有:
|
||||
| 类型(driver) | 地址(source)示例 |
|
||||
| -------------- | ------------------------------------------------------------ |
|
||||
| mongodb | mongodb://localhost:27017 |
|
||||
| mysql | user:password@tcp(localhost:3306)/eiblog?charset=utf8mb4&parseTime=True&loc=Local |
|
||||
| postgres | host=localhost port=5432 user=user password=password dbname=eiblog sslmode=disable |
|
||||
| sqlite | /path/eiblog.db |
|
||||
| sqlserver | sqlserver://user:password@localhost:9930?database=eiblog |
|
||||
| clickhouse | tcp://localhost:9000?database=eiblog&username=user&password=password&read_timeout=10&write_timeout=20 |
|
||||
|
||||
* `Golang`,博客系统后端采用golang编写,并开源至[Eiblog](https://github.com/eiblog/eiblog)。
|
||||
* `HTML Javascript CSS`,博客系统的前端采用`html`和`jquery`编写,样式采用`CSS`。
|
||||
* `Glide`, golang 编写。作为博客系统的包依赖管理器,其开源地址是[Glide](https://github.com/Masterminds/glide)。
|
||||
* `Docker`,博客系统可 docker 部署,方便,快捷。
|
||||
* `Docker Compose`,博客系统可完全 docker 运行,compose起到很好管理作用。
|
||||
* `SSL 证书`,`https`是未来的趋势,整个博客系统都将围绕着`证书`进行,请事先准备好一张有效的 ssl 证书。
|
||||
* `Travis`,作为博客系统的自动构建工具,自动构建docker镜像并推送到镜像仓库。
|
||||
* `Yaml`,博客系统的配置文件使用`yaml`,请悉知。
|
||||
|
||||
作为博主之心血之作,`Eiblog`实现了什么功能,有什么特点,做了什么优化呢?
|
||||
|
||||
1. 系统目前只有`首页`、`专题`、`归档`、`友链`、`关于`、`搜索`界面。相信已经可以满足大部分用户的需求。
|
||||
2. `.js`、`.css`等静态文件本地存储,小图片 base64 内置到 css 中,不会产生网络所带来的延迟,加速网页访问。版本控制方式,动态更新静态文件。
|
||||
3. 采用谷歌统计,并实现异步(将访问信息发给后端,后端提交给谷歌)统计,加速访问速度。
|
||||
4. 采用直接缓存 markdown 转过的 html 文档的方式,加速后端处理。响应速度均在 3ms 以内,真正极速。
|
||||
5. 通过 Nginx 的配置,开启压缩缩小传输量,服务器传输证书链、开启`Session Resumption`、`Session Ticket`、`OCSP Stapling`等加速证书握手,再次提高速度。
|
||||
6. 文章评论数量(不重要)后端跑定时脚本,定时更新,所以有时评论数是不对的。这样减少了 api 调用,又再次达到加速访问的目的。
|
||||
7. 针对`disqus`被墙原因,实现[Jerry Qu](https://imququ.com)的另类评论方式,保证评论的流畅。
|
||||
8. 开源`Typecho`完整后台系统,全功能`markdown`编辑器,让你体验什么是简洁清爽。
|
||||
9. 博客后台直接对接`七牛 SDK`,实现后台上传文件和删除文件的简单功能。
|
||||
10. 采用`elasticsearch`作为站内搜索,添加`google opensearch`功能,搜索更加自然。
|
||||
|
||||
当然,在信息安全方面也没少下功夫,虽然我们只是一个小小的博客系统。
|
||||
|
||||
1. `CDN`,使用七牛融合CDN,并`https`化,实现全站`https`。七牛可申请免费证书了。
|
||||
2. `CT`,证书透明度检测,提供一个开放的审计和监控系统。可以让任何域名所有者或者 CA 确定证书是否被错误签发或者被恶意使用,从而提高 HTTPS 网站的安全性。
|
||||
3. `OSCP`,在线证书状态协议。用来检验证书合法性的在线查询服务.
|
||||
4. `HSTS`,强制客户端(如浏览器)使用 HTTPS 与服务器创建连接。可以很好的解决 HTTPS 降级攻击。
|
||||
5. `HPKP`,HTTP公钥固定扩展,防范由「伪造或不正当手段获得网站证书」造成的中间人攻击。该功能让我们选择信任哪些`CA`。
|
||||
5. `SSL Protocols`,罗列支持的`TLS`协议,SSLv3被证实是不安全的。
|
||||
6. `SSL dhparam`,迪菲赫尔曼密钥交换。
|
||||
7. `Cipher suite`,罗列服务器支持加密套件。
|
||||
|
||||
可以容易的看到[httpsecurityreport](https://httpsecurityreport.com/?report=deepzz.com)评分`96`,[ssllabs](https://www.ssllabs.com/ssltest/analyze.html?d=deepzz.com&latest)评分`A+`,堪称完美。这些安全的相关配置会在后面的部署过程中接触到。
|
||||
|
||||
相关图片展示:
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
> `注`:图片1,图片2是博客界面,图片3是后台界面,图片4是性能展示。
|
||||
|
||||
好了,说了那么多,吹了那么多,我们实际来动手搭建一个`Eiblog`吧。
|
||||
|
||||
### 安装
|
||||
1、`Eiblog`提供多个平台的压缩包下载,可到[Eiblog release](https://github.com/eiblog/eiblog/releases)选择相应版本和平台下载。也可通过:
|
||||
``` sh
|
||||
$ curl -L https://github.com/eiblog/eiblog/releases/download/v1.0.0/eiblog-v1.0.0.`uname -s | tr '[A-Z]' '[a-z]'`-amd64.tar.gz > eiblog-v1.0.0.`uname -s | tr '[A-Z]' '[a-z]'`-amd64.tar.gz
|
||||
```
|
||||
|
||||
2、如果有幸你也是`Gopher`,相信你会亲自动手,你可以通过:
|
||||
``` sh
|
||||
$ go get https://github.com/eiblog/eiblog
|
||||
```
|
||||
进行源码编译二进制文件运行。
|
||||
|
||||
3、如果你对`docker`技术也有研究的话,你也可以通过`docker`来安装:
|
||||
``` sh
|
||||
$ docker pull registry.cn-hangzhou.aliyuncs.com/deepzz/eiblog
|
||||
1、启动依赖服务,mongodb、elasticsearch:
|
||||
|
||||
```
|
||||
镜像内部只提供了`eiblog`的二进制文件,因为其它内容定制化的需求过高。所以需要将`conf`、`static`、`views`目录映射出来,后面会具体说到。
|
||||
$ docker run --name mongodb \
|
||||
-p 27017:27017 \
|
||||
-v ${PWD}/mgodb:/data/db \
|
||||
mongo:3.2
|
||||
|
||||
### 本地测试
|
||||
在我们下载好可执行程序之后,我们可以开始本地测试的工作了。
|
||||
|
||||
本地测试需要搭建两个服务`mongodb`和`elasticsearch2.4.1`(可选,搜索服务不可用)。
|
||||
|
||||
`Eiblog`默认会连接`hostname`为`eidb`和`eisearch`,因此你需要将信息填入`/etc/hosts`下。假如你搭建的`mongodb`地址为`127.0.0.1:27017`,`elasticsearch`地址为`192.168.99.100:9200`,如:
|
||||
``` sh
|
||||
$ sudo vi /etc/hosts
|
||||
|
||||
# 在末尾加上两行
|
||||
127.0.0.1 eidb
|
||||
192.168.99.100 eisearch
|
||||
```
|
||||
|
||||
#### MongoDB 搭建
|
||||
1、`MongoDB`搭建,Mac 可通过`brew install mongo`进行安装,其它平台请查询资料。
|
||||
#### Elasticsearch 搭建
|
||||
2、`Elasticsearch`搭建,它的搭建要些许复杂。博主尚未接触如何直接安装,因此建议通过`docker`搭建。需要注意的是 es 自带的分析器对中文分词是不友好的,这里采用了`elasticsearch-analysis-ik`分词器。如果你想了解更多[Github](https://github.com/medcl/elasticsearch-analysis-ik)或则如何实现[博客站内搜索](https://imququ.com/post/elasticsearch.html)。
|
||||
|
||||
* pull 镜像`docker pull elasticsearch:2.4.1`,必需使用该版本。
|
||||
* 添加环境变量`ES_JAVA_OPTS: "-Xms512m -Xmx512m"`,除非你想让你的服务器爆掉。
|
||||
* 映射相关目录:
|
||||
|
||||
```
|
||||
conf/es/config:/usr/share/elasticsearch/config
|
||||
conf/es/plugins:/usr/share/elasticsearch/plugins
|
||||
conf/es/data:/usr/share/elasticsearch/data
|
||||
conf/es/logs:/usr/share/elasticsearch/logs
|
||||
```
|
||||
请将这四个目录映射至`eiblog`下的`conf`目录。如果你想查看更多,请查看`docker-compose.yml`文件。
|
||||
|
||||
总结一下,`docker`运行 es 的命令为:
|
||||
``` sh
|
||||
$ docker run -d --name eisearch \
|
||||
$ docker run --name elasticsearch \
|
||||
-p 9200:9200 \
|
||||
-e ES_JAVA_OPTS: "-Xms512m -Xmx512m" \
|
||||
-v conf/es/config:/usr/share/elasticsearch/config \
|
||||
-v conf/es/plugins:/usr/share/elasticsearch/plugins \
|
||||
-v conf/es/data:/usr/share/elasticsearch/data \
|
||||
-v conf/es/logs:/usr/share/elasticsearch/logs \
|
||||
elasticsearch:2.4.1
|
||||
-p ${PWD}/esdata:/usr/share/elasticsearch/data \
|
||||
deepzz0/elasticsearch:2.4.1
|
||||
```
|
||||
|
||||
之后执行`./eiblog`,咱们的`eiblog`就可以运行起来了。
|
||||
2、下载压缩包,到 [这里](https://github.com/eiblog/eiblog/releases) 下载 eiblog(非backup) 相应系统压缩包,然后解压缩。
|
||||
|
||||
通过`127.0.0.1:9000`可以进入博客首页,`127.0.0.1:9000/admin/login`进入后台登陆,账号密码为`eiblog/conf/app.yml`下的`username`和`password`。也就是初始账号密码`deepz`、`deepzz`。
|
||||
|
||||
> `注意`,因为配置`conf/app.yml`均是博主自用配置。有些操作可能(如评论)会评论到我的博客,还请尽量避免,谢谢。
|
||||
|
||||
### 准备部署
|
||||
如果你在感受了该博客的魅力了之后,仍然坚持想要搭建它。那么,恭喜你,获得的一款不想再更换的博客系统。下面,我们跟随步骤对部署流程进一步说明。
|
||||
|
||||
这里只提供`Docker`的相关部署说明。你如果需要其它方式部署,请参考该方式。
|
||||
|
||||
#### 前提准备
|
||||
这里需要准备一些必要的东西,如果你已准备好。请跳过。
|
||||
|
||||
* `一台服务器`。
|
||||
* `一个域名`,国内服务器需备案。
|
||||
* `有效的证书`。一般使用免费的就可以。如:`Let‘s Encrypt`,另外`qcloud`、`七牛`也提供了免费证书的申请,均是全球可信。
|
||||
* `七牛CDN`。博客只设计接入了七牛cdn,相信该CDN服务商不会让你失望。
|
||||
* `Disqus`。作为博客评论系统,你得有翻墙的能力注册到该账号,具体配置我想又可以写一片博客了。简单说需要`shorname`和`public key`。
|
||||
* `Google Analystic`。数据统计分析工具。
|
||||
* `Superfeedr`。加速 RSS 订阅。
|
||||
* `Twitter`。希望你能够有一个twitter账号。
|
||||
|
||||
是不是这么多要求,很费解。其实当初该博客系统只是为个人而设计的,是自己心中想要的那一款。博主些这篇文章不是想要多少人来用该博客,而是希望对那些追求至极的朋友说:你需要这款博客系统。
|
||||
#### 文件准备
|
||||
尽管大多数文件已经准备好。但有些默认的文件需要特别指出来,需要你在 CDN 上写特殊的路径。
|
||||
|
||||
假如你的 CDN 域名为`st.example.com`,那么:
|
||||
|
||||
* `favicon.ico`,其 URL 应该是`st.example.com/static/img/favicon.ico`。故你在 CDN 中的文件名为`static/img/favicon.ico`,以下如是。
|
||||
* `左侧背景图片`,`500*1200`左右,CDN 中文件名:`static/img/bg04.jpg`。如需更改,请在`eiblog/view/st_blog.css`中替换该名称。
|
||||
* `头像`,`160*160~256*256`之间,CDN 文件名:`static/img/avatar.jpg`。另外你需要将该图片 `Base64` 编码后替换掉`eiblog/views/st_blog.css`中合适位置的图片。
|
||||
* `blank.gif`,CDN 文件名:`static/img/blank.gif`。该图片请从[这里](https://st.deepzz.com/static/img/blank.gif)下载并上传至你的 CDN。
|
||||
* `default_avatar.png`,CDN 文件名:`static/img/default_avatar.png`,请从[这里](https://st.deepzz.com/static/img/default_avatar.png)下载并上传至你的 CDN。
|
||||
* `disqus.js`,该文件名是会变的,每次更新如果没有提及就没有改变,更新说明在[这里](https://github.com/eiblog/eiblog/blob/master/CHANGELOG.md)。CDN 文件名格式是:`static/js/name.js`。在我写这篇文章是使用的是:`static/js/disqus_a9d3fd.js`,请从[这里](https://st.deepzz.com/static/js/disqus_a9d3fd.js)下载并上传至你的 CDN。
|
||||
|
||||
> `注意`:本人 CDN 做了防盗链处理,故请将这些资源上传至您的 CDN ,以免静态资源不能访问,请悉知。
|
||||
|
||||
#### 配置说明
|
||||
走到这里,我相信只走到`60%`的路程。放弃还来得及。
|
||||
|
||||
这里会对`eiblog/conf`下的所有文件做说明,希望你做好准备。
|
||||
```
|
||||
├── app.yml # 博客配置文件
|
||||
├── blackip.yml # 博客ip黑名单
|
||||
├── es # elasticsearch配置
|
||||
│ ├── config # 配置文件
|
||||
│ │ ├── analysis # 同义词
|
||||
│ │ ├── elasticsearch.yml # 具体配置
|
||||
│ │ ├── logging.yml # 日志配置
|
||||
│ │ └── scripts # 脚本文件夹
|
||||
│ └── plugins # 插件文件夹
|
||||
│ └── ik1.10.1 # ik分词器
|
||||
├── nginx # nginx配置
|
||||
│ ├── domain # 域名配置,nginx会读区改文件夹下的.conf文件
|
||||
│ │ └── deepzz.conf
|
||||
│ ├── ip.blacklist # nginx ip黑名单
|
||||
│ └── nginx.conf # nginx配置,请替换原有配置
|
||||
├── scts # ct文件
|
||||
│ ├── aviator.sct
|
||||
│ └── digicert.sct
|
||||
├── ssl # 证书文件,具体请看deepzz.conf
|
||||
│ ├── dhparams.pem
|
||||
│ ├── domain.key
|
||||
│ ├── domain.pem
|
||||
│ ├── full_chained.pem
|
||||
│ └── session_ticket.key
|
||||
└── tpl # 模版文件
|
||||
├── feedTpl.xml
|
||||
├── opensearchTpl.xml
|
||||
└── sitemapTpl.xml
|
||||
3、修改配置,将数据库与ES地址修改为相应地址:
|
||||
|
||||
```
|
||||
1、app.yml,整个程序的配置文件,里面已经列出了所有配置项的说明,这里不再阐述。
|
||||
2、blackip.yml,如果没有使用`Nginx`,博客内置`ip`过滤系统。
|
||||
3、`es`全名`elasticsearch`,非常强大的分布式搜索引擎,`github`用的就是它。里面的配置基本不用修改,但`es/analysis/synonym.txt`是同义词,你可以照着已有的随意增加。
|
||||
```
|
||||
├── es
|
||||
│ ├── config
|
||||
│ │ ├── analysis
|
||||
│ │ │ └── synonym.txt #同义词配置
|
||||
│ │ ├── elasticsearch.yml #分词器配置
|
||||
│ │ ├── logging.yml #日志配置
|
||||
│ │ └── scripts #脚本
|
||||
│ └── plugins #中文分词插件
|
||||
│ └── ik1.10.0
|
||||
│
|
||||
# 修改 conf/app.yml 数据库连接配置
|
||||
database:
|
||||
driver: mongodb
|
||||
source: mongodb://localhost:27017
|
||||
|
||||
# 修改 conf/app.yml ES连接配置,如果不启用搜索功能可以置空
|
||||
eshost: http://localhost:9200
|
||||
```
|
||||
|
||||
> `注意`,scripts文件夹虽然是空的,但必需存在,不然elasticsearch报错。
|
||||
4、启动服务:
|
||||
|
||||
4、`nginx`,系统采用`nginx`作为代理(相信博客系统也不会独占一台服务器~)。请使用`nginx.conf`替换原`nginx`的配置。博客系统的配置文件是`domain/deepzz.conf`,或则重命名(只要是满足`*.conf`)。`deepzz.conf`文件里面学问是最多的。或许你想一一弄懂,或许…。
|
||||
|
||||
> 注意本配置需要更新nginx到最新版,openssl更新到1.0.2j,具体请到 Jerry Qu 的[本博客 Nginx 配置之完整篇](https://imququ.com/post/my-nginx-conf.html)查看,了解详情。
|
||||
|
||||
5、`scts`,存放 ct 文件。
|
||||
|
||||
6、`ssl`,这里存放了所有证书相关的内容。
|
||||
```
|
||||
├── dhparams.pem #参见eiblog/conf/nginx/domain/deepzz.conf
|
||||
├── domain.key #证书私钥,一般颁发者处下载
|
||||
├── domain.pem #证书链,一般从证书颁发者那可以直接下载到
|
||||
├── full_chained.pem #参见eiblog/conf/nginx/domain/deepzz.conf
|
||||
└── session_ticket.key #参见eiblog/conf/nginx/domain/deepzz.conf
|
||||
./backend
|
||||
```
|
||||
|
||||
7、`tpl`模版相关,不用修改。
|
||||
然后访问 `localhost:9000` 就可以了,后台地址 `localhost:9000/admin/login`,默认账户密码 `deepzz/deepzz`。
|
||||
|
||||
### 开始部署
|
||||
### 功能特性
|
||||
|
||||
#### docker
|
||||
请确定你已经完成了上面所说的所有步骤,在本地已经测试成功。服务器上`MognoDB`和`Elasticsearch`已经安装并已经运行成功。
|
||||
本着博客本质用来分享知识的特点,`EiBlog` 不会有较强的定制功能(包括主题,CDN支持等),仅保持常用简单页面与功能:
|
||||
|
||||
首先,请将本地测试好的`conf`,`static`,`views`文件夹上传至服务器,建议存储到服务器`/data/eiblog`下。
|
||||
``` sh
|
||||
$ tree /data/eiblog -L 1
|
||||
|
||||
├── conf
|
||||
├── static
|
||||
├── views
|
||||
```
|
||||
首页、专题、归档、友链、关于、搜索
|
||||
```
|
||||
|
||||
然后,将镜像 PULL 到服务器本地。
|
||||
``` sh
|
||||
# PULL下Eiblog镜像
|
||||
$ docker pull registry.cn-hangzhou.aliyuncs.com/deepzz/eiblog
|
||||
```
|
||||
功能说明:
|
||||
|
||||
最后,执行`docker run`命令,希望你能成功。
|
||||
``` sh
|
||||
$ docker run -d --name eiblog --restart=always \
|
||||
--add-host disqus.com:23.235.33.134 \
|
||||
--link eidb --link eisearch \
|
||||
-p 9000:9000 \
|
||||
-e GODEBUG=netdns=cgo \
|
||||
-v /data/eiblog/logdata:/eiblog/logdata \
|
||||
-v /data/eiblog/conf:/eiblog/conf \
|
||||
-v /data/eiblog/static:/eiblog/static \
|
||||
-v /data/eiblog/views:/eiblog/views \
|
||||
registry.cn-hangzhou.aliyuncs.com/deepzz/eiblog
|
||||
```
|
||||
这里默认`MongDB`和`Elasticsearch`均为`docker`部署,且名称为`eidb`,`eisearch`。
|
||||
* 博客归档,利用时间线帮助我们将归纳博文,内容少于一年按月归档,大于则按年归档。
|
||||
* 博客专题,有时候博文是同一系列,专题能够帮助我们很好归纳博文,对阅读者是非常友好的。
|
||||
* 标签系统,每篇博文都可以打上不同标签,使得在归档和专题不满足的情况下自定义归档,这块辅助搜索简直完美。
|
||||
* 搜索系统,依托ElasticSearch实现的站内搜索,速度与效率并存,再加上google opensearch,搜索只流畅。
|
||||
* 管理后台,内嵌全功能 `Typecho` 后台系统,全功能 `Markdown` 编辑器让你感觉什么是简洁清爽。
|
||||
* 谷歌统计,由于google api的速度问题,从而实现了后端API异步统计,使得博客页面加载飞速。
|
||||
* Disqus评论,国内评论系统不友好,因此选择disqus,又由于众所周知原因国内不能用,实现另类disqus评论方式。
|
||||
* 多存储后端,支持mongodb、mysql、postgres、sqlite等存储后端。
|
||||
* 七牛CDN,支持在 `Markdown` 编辑器直接上传附件,让你只考虑编辑内容,解放思想。
|
||||
* 自动备份,支持多存储后端的备份功能,备份数据保存到七牛CDN上。
|
||||
|
||||
#### nginx + docker
|
||||
通过`Nginx+docker`部署,是博主推荐的方式。这里采用`Docker Compose`管理我们整个博客系统。
|
||||
当然,为了让整个系统加载速度更快,还做了更多优化措施:
|
||||
|
||||
请确认你已经成功安装好`Nginx`、`docker`、`docker-compose`。Nginx 请一定参照 Jerry Qu 的[Nginx 配置完整篇](https://imququ.com/post/my-nginx-conf.html)。
|
||||
* 文章评论数量(不重要)通过后端跑定时任务获取,所以有时评论数量是不对的,这样减少了 API 调用。
|
||||
* 整站内容全部内存缓存,`mardown` 文档全部转换为 html 进行缓存,减少了转换过程。
|
||||
* `.js`、`.css` 等静态文件浏览器本地存储,小图片 base64 内置到 css 中,二次访问不会产生网络带来的延迟,加速访问。通过版本控制更新。
|
||||
* 最佳实践 nginx 配置,可以查看 `eiblog.conf`,开启压缩缩小传输量,服务器传输证书链、开启 `Session Resumption`、`Session Ticket`、`OCSP Stapling `等加速证书握手,再次提高速度。
|
||||
|
||||
首先,请将本地测试好的`conf`,`static`,`views`,`docker-compose.yml`文件夹和文件上传至服务器。前三个文件夹建议存储到服务器`/data/eiblog`下,`docker-compose.yml`存放在你使用方便的地方。
|
||||
### 博客页面
|
||||
|
||||
> 注意`conf/es/config/scripts`空文件夹是否存在
|
||||
可以容易的看到 [httpsecurityreport](https://httpsecurityreport.com/?report=deepzz.com) 评分`96`,[ssllabs](https://www.ssllabs.com/ssltest/analyze.html?d=deepzz.com&latest) 评分`A+`,[myssl](https://myssl.com/deepzz.com) 评分`A+`,堪称完美。这些安全的相关配置会在后面的部署过程中接触到。
|
||||
|
||||
``` sh
|
||||
$ tree /data/eiblog -L 1
|
||||

|
||||

|
||||
|
||||
├── conf
|
||||
├── static
|
||||
├── views
|
||||

|
||||
|
||||
$ ls ~/
|
||||
### 更多文档
|
||||
|
||||
docker-compose.yml
|
||||
```
|
||||
* [安装部署](https://eiblog.github.io/eiblog/install)
|
||||
* [写作须知](https://eiblog.github.io/eiblog/writing)
|
||||
* [好玩功能](https://eiblog.github.io/eiblog/amusing)
|
||||
* [如何备份](https://eiblog.github.io/eiblog/backup)
|
||||
|
||||
然后,执行:
|
||||
``` sh
|
||||
$ cd ~
|
||||
$ docker-compose up -d
|
||||
```
|
||||
### 贡献成员
|
||||
|
||||
等待些许时间,成功运行。
|
||||

|
||||
|
||||
### 授权许可
|
||||
|
||||
### 成功搭建者博客
|
||||
本项目采用 MIT 开源授权许可证,完整的授权说明已放置在 [LICENSE](https://github.com/eiblog/eiblog/blob/master/LICENSE) 文件中。
|
||||
|
||||
* [https://razeencheng.com/](https://razeencheng.com/) - Razeen's Blog
|
||||
|
||||
如果你的博客使用`Eiblog`搭建,你可以在[这里](https://github.com/eiblog/eiblog/issues/1)提交网址。
|
||||
|
||||
463
api.go
@@ -1,463 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/setting"
|
||||
"github.com/eiblog/utils/logd"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
const (
|
||||
NOTICE_SUCCESS = "success"
|
||||
NOTICE_NOTICE = "notice"
|
||||
NOTICE_ERROR = "error"
|
||||
)
|
||||
|
||||
var APIs = make(map[string]func(c *gin.Context))
|
||||
|
||||
func init() {
|
||||
// 更新账号信息
|
||||
APIs["account"] = apiAccount
|
||||
// 更新博客信息
|
||||
APIs["blog"] = apiBlog
|
||||
// 更新密码
|
||||
APIs["password"] = apiPassword
|
||||
// 删除文章
|
||||
APIs["post-delete"] = apiPostDelete
|
||||
// 添加文章
|
||||
APIs["post-add"] = apiPostAdd
|
||||
// 删除专题
|
||||
APIs["serie-delete"] = apiSerieDelete
|
||||
// 添加专题
|
||||
APIs["serie-add"] = apiSerieAdd
|
||||
// 专题排序
|
||||
APIs["serie-sort"] = apiSerieSort
|
||||
// 删除草稿箱
|
||||
APIs["draft-delete"] = apiDraftDelete
|
||||
// 删除回收箱
|
||||
APIs["trash-delete"] = apiTrashDelete
|
||||
// 恢复回收箱
|
||||
APIs["trash-recover"] = apiTrashRecover
|
||||
// 上传文件
|
||||
APIs["file-upload"] = apiFileUpload
|
||||
// 删除文件
|
||||
APIs["file-delete"] = apiFileDelete
|
||||
}
|
||||
|
||||
func apiAccount(c *gin.Context) {
|
||||
e := c.PostForm("email")
|
||||
pn := c.PostForm("phoneNumber")
|
||||
ad := c.PostForm("address")
|
||||
logd.Debug(e, pn, ad)
|
||||
if (e != "" && !CheckEmail(e)) || (pn != "" && !CheckSMS(pn)) {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
err := UpdateAccountField(bson.M{"$set": bson.M{"email": e, "phonen": pn, "address": ad}})
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
Ei.Email = e
|
||||
Ei.PhoneN = pn
|
||||
Ei.Address = ad
|
||||
responseNotice(c, NOTICE_SUCCESS, "更新成功", "")
|
||||
}
|
||||
|
||||
func apiBlog(c *gin.Context) {
|
||||
bn := c.PostForm("blogName")
|
||||
bt := c.PostForm("bTitle")
|
||||
ba := c.PostForm("beiAn")
|
||||
st := c.PostForm("subTitle")
|
||||
ss := c.PostForm("seriessay")
|
||||
as := c.PostForm("archivessay")
|
||||
if bn == "" || bt == "" {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
err := UpdateAccountField(bson.M{"$set": bson.M{"blogger.blogname": bn, "blogger.btitle": bt, "blogger.beian": ba, "blogger.subtitle": st, "blogger.seriessay": ss, "blogger.archivessay": as}})
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
Ei.BlogName = bn
|
||||
Ei.BTitle = bt
|
||||
Ei.BeiAn = ba
|
||||
Ei.SubTitle = st
|
||||
Ei.SeriesSay = ss
|
||||
Ei.ArchivesSay = as
|
||||
Ei.CH <- SERIES_MD
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
responseNotice(c, NOTICE_SUCCESS, "更新成功", "")
|
||||
}
|
||||
|
||||
func apiPassword(c *gin.Context) {
|
||||
logd.Debug(c.Request.PostForm.Encode())
|
||||
od := c.PostForm("old")
|
||||
nw := c.PostForm("new")
|
||||
cf := c.PostForm("confirm")
|
||||
if nw != cf {
|
||||
responseNotice(c, NOTICE_NOTICE, "两次密码输入不一致", "")
|
||||
return
|
||||
}
|
||||
if !CheckPwd(nw) {
|
||||
responseNotice(c, NOTICE_NOTICE, "密码格式错误", "")
|
||||
return
|
||||
}
|
||||
if !VerifyPasswd(Ei.Password, Ei.Username, od) {
|
||||
responseNotice(c, NOTICE_NOTICE, "原始密码不正确", "")
|
||||
return
|
||||
}
|
||||
newPwd := EncryptPasswd(Ei.Username, nw)
|
||||
err := UpdateAccountField(bson.M{"$set": bson.M{"password": newPwd}})
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
Ei.Password = newPwd
|
||||
responseNotice(c, NOTICE_SUCCESS, "更新成功", "")
|
||||
}
|
||||
|
||||
func apiPostDelete(c *gin.Context) {
|
||||
var err error
|
||||
defer func() {
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "删除成功", "")
|
||||
}()
|
||||
err = c.Request.ParseForm()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var ids []int32
|
||||
var i int
|
||||
for _, v := range c.Request.PostForm["cid[]"] {
|
||||
i, err = strconv.Atoi(v)
|
||||
if err != nil || i < 1 {
|
||||
err = errors.New("参数错误")
|
||||
return
|
||||
}
|
||||
ids = append(ids, int32(i))
|
||||
}
|
||||
err = DelArticles(ids...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// elasticsearch 删除索引
|
||||
err = ElasticDelIndex(ids)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func apiPostAdd(c *gin.Context) {
|
||||
var err error
|
||||
var do string
|
||||
var cid int
|
||||
defer func() {
|
||||
switch do {
|
||||
case "auto": // 自动保存
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"fail": FAIL, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": SUCCESS, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
case "save": // 保存草稿
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
c.Redirect(http.StatusFound, "/admin/manage-draft")
|
||||
case "publish": // 发布
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
c.Redirect(http.StatusFound, "/admin/manage-posts")
|
||||
}
|
||||
}()
|
||||
do = c.PostForm("do") // auto or save or publish
|
||||
slug := c.PostForm("slug")
|
||||
title := c.PostForm("title")
|
||||
text := c.PostForm("text")
|
||||
date := c.PostForm("date")
|
||||
serie := c.PostForm("serie")
|
||||
tag := c.PostForm("tags")
|
||||
update := c.PostForm("update")
|
||||
if title == "" || text == "" || slug == "" {
|
||||
err = errors.New("参数错误")
|
||||
return
|
||||
}
|
||||
var tags []string
|
||||
if tag != "" {
|
||||
tags = strings.Split(tag, ",")
|
||||
}
|
||||
serieid := CheckSerieID(serie)
|
||||
artc := &Article{
|
||||
Title: title,
|
||||
Content: text,
|
||||
Slug: slug,
|
||||
CreateTime: CheckDate(date),
|
||||
IsDraft: do != "publish",
|
||||
Author: Ei.Username,
|
||||
SerieID: serieid,
|
||||
Tags: tags,
|
||||
}
|
||||
cid, err = strconv.Atoi(c.PostForm("cid"))
|
||||
if err != nil || cid < 1 {
|
||||
err = AddArticle(artc)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
}
|
||||
cid = int(artc.ID)
|
||||
if !artc.IsDraft {
|
||||
ElasticIndex(artc)
|
||||
DoPings(slug)
|
||||
}
|
||||
return
|
||||
}
|
||||
artc.ID = int32(cid)
|
||||
i, a := GetArticle(artc.ID)
|
||||
if a != nil {
|
||||
artc.IsDraft = false
|
||||
artc.Count = a.Count
|
||||
artc.UpdateTime = a.UpdateTime
|
||||
Ei.Articles = append(Ei.Articles[0:i], Ei.Articles[i+1:]...)
|
||||
DelFromLinkedList(a)
|
||||
ManageTagsArticle(a, false, DELETE)
|
||||
ManageSeriesArticle(a, false, DELETE)
|
||||
ManageArchivesArticle(a, false, DELETE)
|
||||
delete(Ei.MapArticles, a.Slug)
|
||||
a = nil
|
||||
}
|
||||
if CheckBool(update) {
|
||||
artc.UpdateTime = time.Now()
|
||||
}
|
||||
err = UpdateArticle(bson.M{"id": artc.ID}, artc)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
}
|
||||
if !artc.IsDraft {
|
||||
Ei.MapArticles[artc.Slug] = artc
|
||||
Ei.Articles = append(Ei.Articles, artc)
|
||||
sort.Sort(Ei.Articles)
|
||||
GenerateExcerptAndRender(artc)
|
||||
// elasticsearch 索引
|
||||
ElasticIndex(artc)
|
||||
DoPings(slug)
|
||||
if artc.ID >= setting.Conf.StartID {
|
||||
ManageTagsArticle(artc, true, ADD)
|
||||
ManageSeriesArticle(artc, true, ADD)
|
||||
ManageArchivesArticle(artc, true, ADD)
|
||||
AddToLinkedList(artc.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func apiSerieDelete(c *gin.Context) {
|
||||
err := c.Request.ParseForm()
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
// 只能逐一删除
|
||||
for _, v := range c.Request.PostForm["mid[]"] {
|
||||
id, err := strconv.Atoi(v)
|
||||
if err != nil || id < 1 {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
err = DelSerie(int32(id))
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "删除成功", "")
|
||||
}
|
||||
|
||||
func apiSerieAdd(c *gin.Context) {
|
||||
name := c.PostForm("name")
|
||||
slug := c.PostForm("slug")
|
||||
desc := c.PostForm("description")
|
||||
if name == "" || slug == "" || desc == "" {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
mid, err := strconv.Atoi(c.PostForm("mid"))
|
||||
if err == nil && mid > 0 {
|
||||
serie := QuerySerie(int32(mid))
|
||||
if serie == nil {
|
||||
responseNotice(c, NOTICE_NOTICE, "专题不存在", "")
|
||||
return
|
||||
}
|
||||
serie.Name = name
|
||||
serie.Slug = slug
|
||||
serie.Desc = desc
|
||||
serie.ID = int32(mid)
|
||||
err = UpdateSerie(serie)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
err = AddSerie(name, slug, desc)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "操作成功", "")
|
||||
}
|
||||
|
||||
// 暂未启用
|
||||
func apiSerieSort(c *gin.Context) {
|
||||
err := c.Request.ParseForm()
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
v := c.Request.PostForm["mid[]"]
|
||||
logd.Debug(v)
|
||||
}
|
||||
|
||||
func apiDraftDelete(c *gin.Context) {
|
||||
err := c.Request.ParseForm()
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
for _, v := range c.Request.PostForm["mid[]"] {
|
||||
i, err := strconv.Atoi(v)
|
||||
if err != nil || i < 1 {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
err = RemoveArticle(int32(i))
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "删除成功", "")
|
||||
}
|
||||
|
||||
func apiTrashDelete(c *gin.Context) {
|
||||
logd.Debug(c.PostForm("key"))
|
||||
logd.Debug(c.Request.PostForm)
|
||||
err := c.Request.ParseForm()
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
for _, v := range c.Request.PostForm["mid[]"] {
|
||||
i, err := strconv.Atoi(v)
|
||||
if err != nil || i < 1 {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
err = RemoveArticle(int32(i))
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "删除成功", "")
|
||||
}
|
||||
|
||||
func apiTrashRecover(c *gin.Context) {
|
||||
logd.Debug(c.PostForm("key"))
|
||||
logd.Debug(c.Request.PostForm)
|
||||
err := c.Request.ParseForm()
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
for _, v := range c.Request.PostForm["mid[]"] {
|
||||
i, err := strconv.Atoi(v)
|
||||
if err != nil || i < 1 {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
|
||||
}
|
||||
err = RecoverArticle(int32(i))
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "恢复成功", "")
|
||||
}
|
||||
|
||||
func apiFileUpload(c *gin.Context) {
|
||||
type Size interface {
|
||||
Size() int64
|
||||
}
|
||||
file, header, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
s, ok := file.(Size)
|
||||
if !ok {
|
||||
logd.Error("assert failed")
|
||||
c.String(http.StatusBadRequest, "false")
|
||||
return
|
||||
}
|
||||
filename := strings.ToLower(header.Filename)
|
||||
url, err := FileUpload(filename, s.Size(), file)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
typ := c.Request.Header.Get("Content-Type")
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"title": filename,
|
||||
"isImage": typ[:5] == "image",
|
||||
"url": url,
|
||||
"bytes": fmt.Sprintf("%dkb", s.Size()/1000),
|
||||
})
|
||||
}
|
||||
|
||||
func apiFileDelete(c *gin.Context) {
|
||||
var err error
|
||||
defer func() {
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
}
|
||||
c.String(http.StatusOK, "删掉了吗?鬼知道。。。")
|
||||
}()
|
||||
name := c.PostForm("title")
|
||||
if name == "" {
|
||||
err = errors.New("参数错误")
|
||||
return
|
||||
}
|
||||
err = FileDelete(name)
|
||||
}
|
||||
|
||||
func responseNotice(c *gin.Context, typ, content, hl string) {
|
||||
if hl != "" {
|
||||
c.SetCookie("notice_highlight", hl, 86400, "/", "", true, false)
|
||||
}
|
||||
c.SetCookie("notice_type", typ, 86400, "/", "", true, false)
|
||||
c.SetCookie("notice", fmt.Sprintf("[\"%s\"]", content), 86400, "/", "", true, false)
|
||||
c.Redirect(http.StatusFound, c.Request.Referer())
|
||||
}
|
||||
1
assets/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Other assets to go along with your repository (images, logos, etc).
|
||||
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 847 B After Width: | Height: | Size: 847 B |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
299
back.go
@@ -1,299 +0,0 @@
|
||||
// Package main provides ...
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/setting"
|
||||
"github.com/eiblog/utils/logd"
|
||||
"github.com/gin-gonic/contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
func isLogin(c *gin.Context) bool {
|
||||
session := sessions.Default(c)
|
||||
v := session.Get("username")
|
||||
if v == nil || v.(string) != Ei.Username {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func AuthFilter() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if !isLogin(c) {
|
||||
c.Abort()
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// 登录界面
|
||||
func HandleLogin(c *gin.Context) {
|
||||
logout := c.Query("logout")
|
||||
if logout == "true" {
|
||||
session := sessions.Default(c)
|
||||
session.Delete("username")
|
||||
session.Save()
|
||||
} else if isLogin(c) {
|
||||
c.Redirect(http.StatusFound, "/admin/profile")
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "login.html", gin.H{"BTitle": Ei.BTitle})
|
||||
}
|
||||
|
||||
func HandleLoginPost(c *gin.Context) {
|
||||
user := c.PostForm("user")
|
||||
pwd := c.PostForm("password")
|
||||
// code := c.PostForm("code") // 二次验证
|
||||
if user == "" || pwd == "" {
|
||||
logd.Print("参数错误", user, pwd)
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
if Ei.Username != user || !VerifyPasswd(Ei.Password, user, pwd) {
|
||||
logd.Printf("账号或密码错误 %s, %s", user, pwd)
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
session := sessions.Default(c)
|
||||
session.Set("username", user)
|
||||
session.Save()
|
||||
Ei.LoginIP = c.ClientIP()
|
||||
Ei.LoginTime = time.Now()
|
||||
UpdateAccountField(bson.M{"$set": bson.M{"loginip": Ei.LoginIP, "logintime": Ei.LoginTime}})
|
||||
c.Redirect(http.StatusFound, "/admin/profile")
|
||||
}
|
||||
|
||||
func GetBack() gin.H {
|
||||
return gin.H{"Author": Ei.Username, "Kodo": setting.Conf.Kodo}
|
||||
}
|
||||
|
||||
// 个人配置
|
||||
func HandleProfile(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Console"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "个人配置 | " + Ei.BTitle
|
||||
h["Account"] = Ei
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-profile", h)
|
||||
}
|
||||
|
||||
// 写文章==>Write
|
||||
type T struct {
|
||||
ID string `json:"id"`
|
||||
Tags string `json:"tags"`
|
||||
}
|
||||
|
||||
func HandlePost(c *gin.Context) {
|
||||
h := GetBack()
|
||||
id, err := strconv.Atoi(c.Query("cid"))
|
||||
if err == nil && id > 0 {
|
||||
artc := QueryArticle(int32(id))
|
||||
if artc != nil {
|
||||
h["Title"] = "编辑文章 | " + Ei.BTitle
|
||||
h["Edit"] = artc
|
||||
}
|
||||
}
|
||||
if h["Title"] == nil {
|
||||
h["Title"] = "撰写文章 | " + Ei.BTitle
|
||||
}
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Domain"] = setting.Conf.Mode.Domain
|
||||
h["Series"] = Ei.Series
|
||||
var tags []T
|
||||
for tag, _ := range Ei.Tags {
|
||||
tags = append(tags, T{tag, tag})
|
||||
}
|
||||
h["Tags"] = tags
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-post", h)
|
||||
}
|
||||
|
||||
func HandleDraftDelete(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Query("cid"))
|
||||
if err != nil || id < 1 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数错误"})
|
||||
return
|
||||
}
|
||||
if err = RemoveArticle(int32(id)); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "删除错误"})
|
||||
return
|
||||
}
|
||||
c.Redirect(http.StatusFound, "/admin/write-post")
|
||||
}
|
||||
|
||||
// 文章管理==>Manage
|
||||
func HandlePosts(c *gin.Context) {
|
||||
kw := c.Query("keywords")
|
||||
tmp := c.Query("serie")
|
||||
se, err := strconv.Atoi(tmp)
|
||||
if err != nil || se < 1 {
|
||||
se = 0
|
||||
}
|
||||
pg, err := strconv.Atoi(c.Query("page"))
|
||||
if err != nil || pg < 1 {
|
||||
pg = 1
|
||||
}
|
||||
vals := c.Request.URL.Query()
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "文章管理 | " + Ei.BTitle
|
||||
h["Series"] = Ei.Series
|
||||
h["Serie"] = se
|
||||
h["KW"] = kw
|
||||
var max int
|
||||
max, h["List"] = PageListBack(se, kw, false, false, pg, setting.Conf.PageSize)
|
||||
if pg < max {
|
||||
vals.Set("page", fmt.Sprint(pg+1))
|
||||
h["Next"] = vals.Encode()
|
||||
}
|
||||
if pg > 1 {
|
||||
vals.Set("page", fmt.Sprint(pg-1))
|
||||
h["Prev"] = vals.Encode()
|
||||
}
|
||||
h["PP"] = make(map[int]string, max)
|
||||
for i := 0; i < max; i++ {
|
||||
vals.Set("page", fmt.Sprint(i+1))
|
||||
h["PP"].(map[int]string)[i+1] = vals.Encode()
|
||||
}
|
||||
h["Cur"] = pg
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-posts", h)
|
||||
}
|
||||
|
||||
// 专题列表
|
||||
func HandleSeries(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "专题管理 | " + Ei.BTitle
|
||||
h["List"] = Ei.Series
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-series", h)
|
||||
}
|
||||
|
||||
func HandleSerie(c *gin.Context) {
|
||||
h := GetBack()
|
||||
id, err := strconv.Atoi(c.Query("mid"))
|
||||
if serie := QuerySerie(int32(id)); err == nil && id > 0 && serie != nil {
|
||||
h["Title"] = "编辑专题 | " + Ei.BTitle
|
||||
h["Edit"] = serie
|
||||
} else {
|
||||
h["Title"] = "新增专题 | " + Ei.BTitle
|
||||
}
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-serie", h)
|
||||
}
|
||||
|
||||
// 标签列表
|
||||
func HandleTags(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "标签管理 | " + Ei.BTitle
|
||||
h["List"] = Ei.Tags
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-tags", h)
|
||||
}
|
||||
|
||||
// 草稿箱
|
||||
func HandleDraft(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "草稿箱 | " + Ei.BTitle
|
||||
var err error
|
||||
h["List"], err = LoadDraft()
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
c.Status(http.StatusBadRequest)
|
||||
} else {
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
RenderHTMLBack(c, "admin-draft", h)
|
||||
}
|
||||
|
||||
// 回收箱
|
||||
func HandleTrash(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "回收箱 | " + Ei.BTitle
|
||||
var err error
|
||||
h["List"], err = LoadTrash()
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
c.HTML(http.StatusBadRequest, "backLayout.html", h)
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-trash", h)
|
||||
}
|
||||
|
||||
// 基本设置==>Setting
|
||||
func HandleGeneral(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Setting"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "基本设置 | " + Ei.BTitle
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-general", h)
|
||||
}
|
||||
|
||||
// 阅读设置
|
||||
func HandleDiscussion(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Setting"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "阅读设置 | " + Ei.BTitle
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-discussion", h)
|
||||
}
|
||||
|
||||
// api
|
||||
func HandleAPI(c *gin.Context) {
|
||||
action := c.Param("action")
|
||||
logd.Debug("action=======>", action)
|
||||
api := APIs[action]
|
||||
if api == nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Invalid API Request"})
|
||||
return
|
||||
}
|
||||
api(c)
|
||||
}
|
||||
|
||||
func RenderHTMLBack(c *gin.Context, name string, data gin.H) {
|
||||
if name == "login.html" {
|
||||
err := Tmpl.ExecuteTemplate(c.Writer, name, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
return
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
err := Tmpl.ExecuteTemplate(&buf, name, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data["LayoutContent"] = template.HTML(buf.String())
|
||||
err = Tmpl.ExecuteTemplate(c.Writer, "backLayout.html", data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
}
|
||||
5
build/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Packaging and Continuous Integration.
|
||||
|
||||
Put your cloud (AMI), container (Docker), OS (deb, rpm, pkg) package configurations and scripts in the `/build/package` directory.
|
||||
|
||||
Put your CI (travis, circle, drone) configurations and scripts in the `/build/ci` directory. Note that some of the CI tools (e.g., Travis CI) are very picky about the location of their config files. Try putting the config files in the `/build/ci` directory linking them to the location where the CI tools expect them (when possible).
|
||||
15
build/package/backup.Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM alpine:latest
|
||||
LABEL maintainer="deepzz.qi@gmail.com"
|
||||
|
||||
RUN apk add --update --no-cache tzdata
|
||||
COPY README.md /app/README.md
|
||||
COPY CHANGELOG.md /app/CHANGELOG.md
|
||||
COPY LICENSE /app/LICENSE
|
||||
|
||||
COPY bin/backend /app/backend
|
||||
COPY conf /app/conf
|
||||
|
||||
EXPOSE 9001
|
||||
|
||||
WORKDIR /app
|
||||
CMD ["./backend"]
|
||||
17
build/package/eiblog.Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM alpine:latest
|
||||
LABEL maintainer="deepzz.qi@gmail.com"
|
||||
|
||||
RUN apk add --update --no-cache tzdata
|
||||
COPY README.md /app/README.md
|
||||
COPY CHANGELOG.md /app/CHANGELOG.md
|
||||
COPY LICENSE /app/LICENSE
|
||||
|
||||
COPY bin/backend /app/backend
|
||||
COPY conf /app/conf
|
||||
COPY website /app/website
|
||||
COPY assets /app/assets
|
||||
|
||||
EXPOSE 9000
|
||||
|
||||
WORKDIR /app
|
||||
CMD ["./backend"]
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
echo "go build..."
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build && \
|
||||
|
||||
domain="registry.cn-hangzhou.aliyuncs.com" && \
|
||||
docker build -t $domain/deepzz/eiblog . && \
|
||||
read -p "是否上传到服务器(y/n):" word && \
|
||||
if [ $word = "y" ] ;then
|
||||
docker push $domain/deepzz/eiblog
|
||||
fi
|
||||
44
check.go
@@ -1,44 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CheckEmail(e string) bool {
|
||||
reg := regexp.MustCompile(`^(\w)+([\.\-]\w+)*@(\w)+((\.\w+)+)$`)
|
||||
return reg.MatchString(e)
|
||||
}
|
||||
|
||||
func CheckDomain(domain string) bool {
|
||||
reg := regexp.MustCompile(`^(http://|https://)?[0-9a-zA-Z]+[0-9a-zA-Z\.-]*\.[a-zA-Z]{2,4}$`)
|
||||
return reg.MatchString(domain)
|
||||
}
|
||||
|
||||
func CheckSMS(sms string) bool {
|
||||
reg := regexp.MustCompile(`^\+\d+$`)
|
||||
return reg.MatchString(sms)
|
||||
}
|
||||
|
||||
func CheckPwd(pwd string) bool {
|
||||
return len(pwd) > 5 && len(pwd) < 19
|
||||
}
|
||||
|
||||
func CheckDate(date string) time.Time {
|
||||
if t, err := time.ParseInLocation("2006-01-02 15:04", date, time.Local); err == nil {
|
||||
return t
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func CheckSerieID(sid string) int32 {
|
||||
if id, err := strconv.Atoi(sid); err == nil {
|
||||
return int32(id)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func CheckBool(str string) bool {
|
||||
return str == "true" || str == "1"
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCheckEmail(t *testing.T) {
|
||||
e := "xx@email.com"
|
||||
e1 := "xxxxemail.com"
|
||||
e2 := "xxx#email.com"
|
||||
|
||||
t.Log(CheckEmail(e))
|
||||
t.Log(CheckEmail(e1))
|
||||
t.Log(CheckEmail(e2))
|
||||
}
|
||||
|
||||
func TestCheckDomain(t *testing.T) {
|
||||
d := "123.com"
|
||||
d1 := "http://123.com"
|
||||
d2 := "https://123.com"
|
||||
d3 := "123#.com"
|
||||
d4 := "123.coooom"
|
||||
|
||||
t.Log(CheckDomain(d))
|
||||
t.Log(CheckDomain(d1))
|
||||
t.Log(CheckDomain(d2))
|
||||
t.Log(CheckDomain(d3))
|
||||
t.Log(CheckDomain(d4))
|
||||
}
|
||||
7
cmd/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
Main applications for this project.
|
||||
|
||||
The directory name for each application should match the name of the executable you want to have (e.g., `/cmd/myapp`).
|
||||
|
||||
Don't put a lot of code in the application directory. If you think the code can be imported and used in other projects, then it should live in the `/pkg` directory. If the code is not reusable or if you don't want others to reuse it, put that code in the `/internal` directory. You'll be surprised what others will do, so be explicit about your intentions!
|
||||
|
||||
It's common to have a small `main` function that imports and invokes the code from the `/internal` and `/pkg` directories and nothing else.
|
||||
54
cmd/backup/main.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// Package main provides ...
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
"github.com/eiblog/eiblog/pkg/core/backup/ping"
|
||||
"github.com/eiblog/eiblog/pkg/core/backup/swag"
|
||||
"github.com/eiblog/eiblog/pkg/core/backup/timer"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hi, it's App " + config.Conf.BackupApp.Name)
|
||||
|
||||
endRun := make(chan error, 1)
|
||||
|
||||
runTimer(endRun)
|
||||
|
||||
runHTTPServer(endRun)
|
||||
fmt.Println(<-endRun)
|
||||
}
|
||||
|
||||
func runTimer(endRun chan error) {
|
||||
go func() {
|
||||
endRun <- timer.Start()
|
||||
}()
|
||||
}
|
||||
|
||||
func runHTTPServer(endRun chan error) {
|
||||
if !config.Conf.EiBlogApp.EnableHTTP {
|
||||
return
|
||||
}
|
||||
|
||||
if config.Conf.RunMode == config.ModeProd {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
e := gin.Default()
|
||||
|
||||
// swag
|
||||
swag.RegisterRoutes(e)
|
||||
|
||||
// route
|
||||
ping.RegisterRoutes(e)
|
||||
|
||||
// start
|
||||
address := fmt.Sprintf(":%d", config.Conf.EiBlogApp.HTTPPort)
|
||||
go func() {
|
||||
endRun <- e.Run(address)
|
||||
}()
|
||||
fmt.Println("HTTP server running on: " + address)
|
||||
}
|
||||
72
cmd/eiblog/main.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// Package main provides ...
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
"github.com/eiblog/eiblog/pkg/core/eiblog"
|
||||
"github.com/eiblog/eiblog/pkg/core/eiblog/admin"
|
||||
"github.com/eiblog/eiblog/pkg/core/eiblog/file"
|
||||
"github.com/eiblog/eiblog/pkg/core/eiblog/page"
|
||||
"github.com/eiblog/eiblog/pkg/core/eiblog/swag"
|
||||
"github.com/eiblog/eiblog/pkg/mid"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hi, it's App " + config.Conf.EiBlogApp.Name)
|
||||
|
||||
endRun := make(chan error, 1)
|
||||
|
||||
runHTTPServer(endRun)
|
||||
fmt.Println(<-endRun)
|
||||
}
|
||||
|
||||
func runHTTPServer(endRun chan error) {
|
||||
if !config.Conf.EiBlogApp.EnableHTTP {
|
||||
return
|
||||
}
|
||||
|
||||
if config.Conf.RunMode == config.ModeProd {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
e := gin.Default()
|
||||
// middleware
|
||||
e.Use(mid.UserMiddleware())
|
||||
e.Use(mid.SessionMiddleware(mid.SessionOpts{
|
||||
Name: "su",
|
||||
Secure: config.Conf.RunMode == config.ModeProd,
|
||||
Secret: []byte("ZGlzvcmUoMTAsICI="),
|
||||
}))
|
||||
|
||||
// swag
|
||||
swag.RegisterRoutes(e)
|
||||
|
||||
// static files, page
|
||||
root := filepath.Join(config.WorkDir, "assets")
|
||||
e.Static("/static", root)
|
||||
|
||||
// static files
|
||||
file.RegisterRoutes(e)
|
||||
// frontend pages
|
||||
page.RegisterRoutes(e)
|
||||
// unauthz api
|
||||
admin.RegisterRoutes(e)
|
||||
|
||||
// admin router
|
||||
group := e.Group("/admin", eiblog.AuthFilter)
|
||||
{
|
||||
page.RegisterRoutesAuthz(group)
|
||||
admin.RegisterRoutesAuthz(group)
|
||||
}
|
||||
|
||||
// start
|
||||
address := fmt.Sprintf(":%d", config.Conf.EiBlogApp.HTTPPort)
|
||||
go func() {
|
||||
endRun <- e.Run(address)
|
||||
}()
|
||||
fmt.Println("HTTP server running on: " + address)
|
||||
}
|
||||
3
conf/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Configuration file templates or default configs.
|
||||
|
||||
Put your confd or consul-template template files here.
|
||||
154
conf/app.yml
@@ -1,89 +1,67 @@
|
||||
# 运行模式 dev or prod
|
||||
runmode: dev
|
||||
# 回收箱保留48小时
|
||||
trash: -48
|
||||
# 定时清理回收箱,%d小时
|
||||
clean: 1
|
||||
# 首页展示文章数量
|
||||
pagenum: 10
|
||||
# 管理界面
|
||||
pagesize: 20
|
||||
# 自动截取预览, 字符数
|
||||
length: 400
|
||||
# 截取预览标识
|
||||
identifier: <!--more-->
|
||||
# 起始ID,预留id不时之需, 不用管
|
||||
startid: 11
|
||||
# elasticsearch url
|
||||
searchurl: http://elasticsearch:9200
|
||||
# 评论相关
|
||||
disqus:
|
||||
shortname: deepzz
|
||||
publickey: wdSgxRm9rdGAlLKFcFdToBe3GT4SibmV7Y8EjJQ0r4GWXeKtxpopMAeIeoI2dTEg
|
||||
postscount: https://disqus.com/api/3.0/threads/set.json
|
||||
postslist: https://disqus.com/api/3.0/threads/listPosts.json
|
||||
postcreate: https://disqus.com/api/3.0/posts/create.json
|
||||
interval: 5
|
||||
# 热搜词配置
|
||||
hotwords:
|
||||
appname: eiblog
|
||||
database:
|
||||
driver: sqlite
|
||||
source: ./eiblog.db
|
||||
eshost:
|
||||
eiblogapp:
|
||||
mode:
|
||||
name: cmd-eiblog
|
||||
enablehttp: true
|
||||
httpport: 9000
|
||||
host: example.com
|
||||
staticversion: 1 # 静态文件版本
|
||||
hotwords: # 热搜词
|
||||
- docker
|
||||
# 谷歌统计
|
||||
google:
|
||||
tid: UA-77251712-1
|
||||
v: "1"
|
||||
t: pageview
|
||||
# 静态文件版本
|
||||
staticversion: 1
|
||||
# 七牛CDN
|
||||
kodo:
|
||||
name: eiblog
|
||||
domain: st.deepzz.com
|
||||
accesskey: MB6AXl_Sj_mmFsL-Lt59Dml2Vmy2o8XMmiCbbSeC
|
||||
secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf
|
||||
# 运行模式
|
||||
mode:
|
||||
# you can fix certfile, keyfile, domain
|
||||
enablehttp: true
|
||||
httpport: 9000
|
||||
enablehttps: false
|
||||
httpsport: 443
|
||||
certfile: conf/certs/domain.pem
|
||||
keyfile: conf/certs/domain.key
|
||||
domain: deepzz.com
|
||||
# twitter地址: twitter.com/chenqijing2
|
||||
twitter:
|
||||
card: summary
|
||||
site: chenqijing2
|
||||
image: st.deepzz.com/static/img/avatar.jpg
|
||||
address: twitter.com/chenqijing2
|
||||
# superfeedr url
|
||||
feedrurl: https://deepzz.superfeedr.com/
|
||||
# ping rpcs 地址
|
||||
pingrpcs:
|
||||
- http://ping.baidu.com/ping/RPC2
|
||||
- http://blogsearch.google.com/ping/RPC2
|
||||
- http://rpc.pingomatic.com/
|
||||
|
||||
# 以下数据初始化用,可在后台修改
|
||||
account:
|
||||
# *后台登录用户名
|
||||
username: deepzz
|
||||
# *登录明文密码
|
||||
password: deepzz
|
||||
# 邮箱,用于通知: chenqijing2@163.com
|
||||
email: chenqijing2@163.com
|
||||
# 手机号, "+8615100000000"
|
||||
phonenumber: "+8615100000000"
|
||||
# 家庭住址
|
||||
address: ""
|
||||
blogger:
|
||||
# left显示名称: Deepzz
|
||||
blogname: Deepzz
|
||||
# 小标题: 不抛弃,不放弃
|
||||
subtitle: 不抛弃,不放弃
|
||||
# 备案号: 蜀 ICP 备 16021362 号
|
||||
beian: 蜀 ICP 备 16021362 号
|
||||
# footer显示名称及tab标题: Deepzz's Blog
|
||||
btitle: Deepzz's Blog
|
||||
# 版权声明: 本站使用「<a href="//creativecommons.org/licenses/by/4.0/">署名 4.0 国际</a>」创作共享协议,转载请注明作者及原网址。
|
||||
copyright: 本站使用「<a href="//creativecommons.org/licenses/by/4.0/">署名 4.0 国际</a>」创作共享协议,转载请注明作者及原网址。
|
||||
- mongodb
|
||||
- curl
|
||||
- dns
|
||||
general: # 常规配置
|
||||
pagenum: 10 # 首页展示文章数量
|
||||
pagesize: 20 # 管理界面
|
||||
startid: 11 # 起始ID,预留id不时之需, 不用管
|
||||
descprefix: "Desc:" # 文章描述前缀
|
||||
identifier: <!--more--> # 截取预览标识
|
||||
length: 400 # 自动截取预览, 字符数
|
||||
timezone: Asia/Shanghai # 时区
|
||||
disqus: # 评论相关
|
||||
shortname: xxxxxx
|
||||
publickey: wdSgxRm9rdGAlLKFcFdToBe3GT4SibmV7Y8EjJQ0r4GWXeKtxpopMAeIeoI2dTEg
|
||||
accesstoken: 50023908f39f4607957e909b495326af
|
||||
google: # 谷歌分析
|
||||
url: https://www.google-analytics.com/collect
|
||||
tid: UA-xxxxxx-1
|
||||
v: "1"
|
||||
t: pageview
|
||||
adsense: <script data-ad-client="ca-pub-5384494508691406" async src=""></script>
|
||||
qiniu: # 七牛OSS
|
||||
bucket: eiblog
|
||||
domain: st.deepzz.com
|
||||
accesskey: MB6AXl_Sj_mmFsL-Lt59Dml2Vmy2o8XMmiCbbSeC
|
||||
secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf
|
||||
twitter: # twitter card
|
||||
card: summary
|
||||
site: deepzz02
|
||||
image: st.deepzz.com/static/img/avatar.jpg
|
||||
address: twitter.com/deepzz02
|
||||
feedrpc: # rss ping
|
||||
feedrurl: https://deepzz.superfeedr.com/
|
||||
pingrpc:
|
||||
- http://ping.baidu.com/ping/RPC2
|
||||
- http://rpc.pingomatic.com/
|
||||
# 数据初始化操作,可到博客后台修改
|
||||
account:
|
||||
username: deepzz # *后台登录用户名
|
||||
password: deepzz # *登录明文密码
|
||||
backupapp:
|
||||
mode:
|
||||
name: cmd-backup
|
||||
enablehttp: true
|
||||
httpport: 9001
|
||||
backupto: qiniu # 备份到七牛云
|
||||
interval: 7d # 多久备份一次
|
||||
validity: 60d # 保存时长
|
||||
qiniu: # 七牛OSS
|
||||
bucket: backup
|
||||
domain: st.deepzz.com
|
||||
accesskey: MB6AXl_Sj_mmFsL-Lt59Dml2Vmy2o8XMmiCbbSeC
|
||||
secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
ua,user-agent,userAgent
|
||||
js,javascript
|
||||
谷歌=>google
|
||||
@@ -1,17 +0,0 @@
|
||||
network.host: 0.0.0.0
|
||||
|
||||
index:
|
||||
analysis:
|
||||
analyzer:
|
||||
ik_syno:
|
||||
type: custom
|
||||
tokenizer: ik_max_word
|
||||
filter: [my_synonym_filter]
|
||||
ik_syno_smart:
|
||||
type: custom
|
||||
tokenizer: ik_smart
|
||||
filter: [my_synonym_filter]
|
||||
filter:
|
||||
my_synonym_filter:
|
||||
type: synonym
|
||||
synonyms_path: analysis/synonym.txt
|
||||
@@ -1,15 +0,0 @@
|
||||
# you can override this using by setting a system property, for example -Des.logger.level=DEBUG
|
||||
es.logger.level: INFO
|
||||
rootLogger: ${es.logger.level}, console
|
||||
logger:
|
||||
# log action execution errors for easier debugging
|
||||
action: DEBUG
|
||||
# reduce the logging for aws, too much is logged under the default INFO
|
||||
com.amazonaws: WARN
|
||||
|
||||
appender:
|
||||
console:
|
||||
type: console
|
||||
layout:
|
||||
type: consolePattern
|
||||
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties>
|
||||
<comment>IK Analyzer 扩展配置</comment>
|
||||
<!--用户可以在这里配置自己的扩展字典 -->
|
||||
<entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic</entry>
|
||||
<!--用户可以在这里配置自己的扩展停止词字典-->
|
||||
<entry key="ext_stopwords">custom/ext_stopword.dic</entry>
|
||||
<!--用户可以在这里配置远程扩展字典 -->
|
||||
<!-- <entry key="remote_ext_dict">words_location</entry> -->
|
||||
<!--用户可以在这里配置远程扩展停止词字典-->
|
||||
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
|
||||
</properties>
|
||||
@@ -1,31 +0,0 @@
|
||||
也
|
||||
了
|
||||
仍
|
||||
从
|
||||
以
|
||||
使
|
||||
则
|
||||
却
|
||||
又
|
||||
及
|
||||
对
|
||||
就
|
||||
并
|
||||
很
|
||||
或
|
||||
把
|
||||
是
|
||||
的
|
||||
着
|
||||
给
|
||||
而
|
||||
被
|
||||
让
|
||||
在
|
||||
还
|
||||
比
|
||||
等
|
||||
当
|
||||
与
|
||||
于
|
||||
但
|
||||
@@ -1,14 +0,0 @@
|
||||
medcl
|
||||
elastic
|
||||
elasticsearch
|
||||
kogstash
|
||||
kibana
|
||||
marvel
|
||||
shield
|
||||
watcher
|
||||
beats
|
||||
packetbeat
|
||||
filebeat
|
||||
topbeat
|
||||
metrixbeat
|
||||
kimchy
|
||||
@@ -1,25 +0,0 @@
|
||||
不
|
||||
也
|
||||
了
|
||||
仍
|
||||
从
|
||||
以
|
||||
使
|
||||
则
|
||||
却
|
||||
又
|
||||
及
|
||||
对
|
||||
就
|
||||
并
|
||||
很
|
||||
或
|
||||
把
|
||||
是
|
||||
的
|
||||
着
|
||||
给
|
||||
而
|
||||
被
|
||||
让
|
||||
但
|
||||
@@ -1,316 +0,0 @@
|
||||
丈
|
||||
下
|
||||
世
|
||||
世纪
|
||||
两
|
||||
个
|
||||
中
|
||||
串
|
||||
亩
|
||||
人
|
||||
介
|
||||
付
|
||||
代
|
||||
件
|
||||
任
|
||||
份
|
||||
伏
|
||||
伙
|
||||
位
|
||||
位数
|
||||
例
|
||||
倍
|
||||
像素
|
||||
元
|
||||
克
|
||||
克拉
|
||||
公亩
|
||||
公克
|
||||
公分
|
||||
公升
|
||||
公尺
|
||||
公担
|
||||
公斤
|
||||
公里
|
||||
公顷
|
||||
具
|
||||
册
|
||||
出
|
||||
刀
|
||||
分
|
||||
分钟
|
||||
分米
|
||||
划
|
||||
列
|
||||
则
|
||||
刻
|
||||
剂
|
||||
剑
|
||||
副
|
||||
加仑
|
||||
勺
|
||||
包
|
||||
匙
|
||||
匹
|
||||
区
|
||||
千克
|
||||
千米
|
||||
升
|
||||
卷
|
||||
厅
|
||||
厘
|
||||
厘米
|
||||
双
|
||||
发
|
||||
口
|
||||
句
|
||||
只
|
||||
台
|
||||
叶
|
||||
号
|
||||
名
|
||||
吨
|
||||
听
|
||||
员
|
||||
周
|
||||
周年
|
||||
品
|
||||
回
|
||||
团
|
||||
圆
|
||||
圈
|
||||
地
|
||||
场
|
||||
块
|
||||
坪
|
||||
堆
|
||||
声
|
||||
壶
|
||||
处
|
||||
夜
|
||||
大
|
||||
天
|
||||
头
|
||||
套
|
||||
女
|
||||
孔
|
||||
字
|
||||
宗
|
||||
室
|
||||
家
|
||||
寸
|
||||
对
|
||||
封
|
||||
尊
|
||||
小时
|
||||
尺
|
||||
尾
|
||||
局
|
||||
层
|
||||
届
|
||||
岁
|
||||
师
|
||||
帧
|
||||
幅
|
||||
幕
|
||||
幢
|
||||
平方
|
||||
平方公尺
|
||||
平方公里
|
||||
平方分米
|
||||
平方厘米
|
||||
平方码
|
||||
平方米
|
||||
平方英寸
|
||||
平方英尺
|
||||
平方英里
|
||||
平米
|
||||
年
|
||||
年代
|
||||
年级
|
||||
度
|
||||
座
|
||||
式
|
||||
引
|
||||
张
|
||||
成
|
||||
战
|
||||
截
|
||||
户
|
||||
房
|
||||
所
|
||||
扇
|
||||
手
|
||||
打
|
||||
批
|
||||
把
|
||||
折
|
||||
担
|
||||
拍
|
||||
招
|
||||
拨
|
||||
拳
|
||||
指
|
||||
掌
|
||||
排
|
||||
撮
|
||||
支
|
||||
文
|
||||
斗
|
||||
斤
|
||||
方
|
||||
族
|
||||
日
|
||||
时
|
||||
曲
|
||||
月
|
||||
月份
|
||||
期
|
||||
本
|
||||
朵
|
||||
村
|
||||
束
|
||||
条
|
||||
来
|
||||
杯
|
||||
枚
|
||||
枝
|
||||
枪
|
||||
架
|
||||
柄
|
||||
柜
|
||||
栋
|
||||
栏
|
||||
株
|
||||
样
|
||||
根
|
||||
格
|
||||
案
|
||||
桌
|
||||
档
|
||||
桩
|
||||
桶
|
||||
梯
|
||||
棵
|
||||
楼
|
||||
次
|
||||
款
|
||||
步
|
||||
段
|
||||
毛
|
||||
毫
|
||||
毫升
|
||||
毫米
|
||||
毫克
|
||||
池
|
||||
洲
|
||||
派
|
||||
海里
|
||||
滴
|
||||
炮
|
||||
点
|
||||
点钟
|
||||
片
|
||||
版
|
||||
环
|
||||
班
|
||||
瓣
|
||||
瓶
|
||||
生
|
||||
男
|
||||
画
|
||||
界
|
||||
盆
|
||||
盎司
|
||||
盏
|
||||
盒
|
||||
盘
|
||||
相
|
||||
眼
|
||||
石
|
||||
码
|
||||
碗
|
||||
碟
|
||||
磅
|
||||
种
|
||||
科
|
||||
秒
|
||||
秒钟
|
||||
窝
|
||||
立方公尺
|
||||
立方分米
|
||||
立方厘米
|
||||
立方码
|
||||
立方米
|
||||
立方英寸
|
||||
立方英尺
|
||||
站
|
||||
章
|
||||
笔
|
||||
等
|
||||
筐
|
||||
筒
|
||||
箱
|
||||
篇
|
||||
篓
|
||||
篮
|
||||
簇
|
||||
米
|
||||
类
|
||||
粒
|
||||
级
|
||||
组
|
||||
维
|
||||
缕
|
||||
缸
|
||||
罐
|
||||
网
|
||||
群
|
||||
股
|
||||
脚
|
||||
船
|
||||
艇
|
||||
艘
|
||||
色
|
||||
节
|
||||
英亩
|
||||
英寸
|
||||
英尺
|
||||
英里
|
||||
行
|
||||
袋
|
||||
角
|
||||
言
|
||||
课
|
||||
起
|
||||
趟
|
||||
路
|
||||
车
|
||||
转
|
||||
轮
|
||||
辆
|
||||
辈
|
||||
连
|
||||
通
|
||||
遍
|
||||
部
|
||||
里
|
||||
重
|
||||
针
|
||||
钟
|
||||
钱
|
||||
锅
|
||||
门
|
||||
间
|
||||
队
|
||||
阶段
|
||||
隅
|
||||
集
|
||||
页
|
||||
顶
|
||||
顷
|
||||
项
|
||||
顿
|
||||
颗
|
||||
餐
|
||||
首
|
||||
@@ -1,33 +0,0 @@
|
||||
a
|
||||
an
|
||||
and
|
||||
are
|
||||
as
|
||||
at
|
||||
be
|
||||
but
|
||||
by
|
||||
for
|
||||
if
|
||||
in
|
||||
into
|
||||
is
|
||||
it
|
||||
no
|
||||
not
|
||||
of
|
||||
on
|
||||
or
|
||||
such
|
||||
that
|
||||
the
|
||||
their
|
||||
then
|
||||
there
|
||||
these
|
||||
they
|
||||
this
|
||||
to
|
||||
was
|
||||
will
|
||||
with
|
||||
@@ -1,37 +0,0 @@
|
||||
乡
|
||||
井
|
||||
亭
|
||||
党
|
||||
区
|
||||
厅
|
||||
县
|
||||
园
|
||||
塔
|
||||
家
|
||||
寺
|
||||
局
|
||||
巷
|
||||
市
|
||||
弄
|
||||
所
|
||||
斯基
|
||||
楼
|
||||
江
|
||||
河
|
||||
海
|
||||
湖
|
||||
省
|
||||
维奇
|
||||
署
|
||||
苑
|
||||
街
|
||||
觀
|
||||
观
|
||||
诺夫
|
||||
路
|
||||
部
|
||||
镇
|
||||
阁
|
||||
山
|
||||
子
|
||||
娃
|
||||
@@ -1,131 +0,0 @@
|
||||
丁
|
||||
万
|
||||
万俟
|
||||
上官
|
||||
东方
|
||||
乔
|
||||
于
|
||||
令狐
|
||||
仲孙
|
||||
任
|
||||
何
|
||||
余
|
||||
候
|
||||
傅
|
||||
公冶
|
||||
公孙
|
||||
公羊
|
||||
冯
|
||||
刘
|
||||
单
|
||||
单于
|
||||
卢
|
||||
史
|
||||
叶
|
||||
司徒
|
||||
司空
|
||||
司马
|
||||
吕
|
||||
吴
|
||||
周
|
||||
唐
|
||||
夏
|
||||
夏侯
|
||||
太叔
|
||||
姚
|
||||
姜
|
||||
孔
|
||||
孙
|
||||
孟
|
||||
宇文
|
||||
宋
|
||||
宗政
|
||||
尉迟
|
||||
尹
|
||||
崔
|
||||
常
|
||||
康
|
||||
廖
|
||||
张
|
||||
彭
|
||||
徐
|
||||
慕容
|
||||
戴
|
||||
文
|
||||
方
|
||||
易
|
||||
曹
|
||||
曾
|
||||
朱
|
||||
李
|
||||
杜
|
||||
杨
|
||||
林
|
||||
梁
|
||||
欧阳
|
||||
武
|
||||
段
|
||||
毛
|
||||
江
|
||||
汤
|
||||
沈
|
||||
淳于
|
||||
潘
|
||||
澹台
|
||||
濮阳
|
||||
熊
|
||||
王
|
||||
田
|
||||
申屠
|
||||
白
|
||||
皇甫
|
||||
石
|
||||
秦
|
||||
程
|
||||
罗
|
||||
肖
|
||||
胡
|
||||
苏
|
||||
范
|
||||
董
|
||||
蒋
|
||||
薛
|
||||
袁
|
||||
许
|
||||
诸葛
|
||||
谢
|
||||
谭
|
||||
贺
|
||||
贾
|
||||
赖
|
||||
赫连
|
||||
赵
|
||||
轩辕
|
||||
邓
|
||||
邱
|
||||
邵
|
||||
邹
|
||||
郑
|
||||
郝
|
||||
郭
|
||||
金
|
||||
钟
|
||||
钟离
|
||||
钱
|
||||
长孙
|
||||
闻人
|
||||
闾丘
|
||||
阎
|
||||
陆
|
||||
陈
|
||||
雷
|
||||
韩
|
||||
顾
|
||||
马
|
||||
高
|
||||
魏
|
||||
鲜于
|
||||
黄
|
||||
黎
|
||||
龙
|
||||
龚
|
||||
@@ -1,80 +0,0 @@
|
||||
# Elasticsearch plugin descriptor file
|
||||
# This file must exist as 'plugin-descriptor.properties' at
|
||||
# the root directory of all plugins.
|
||||
#
|
||||
# A plugin can be 'site', 'jvm', or both.
|
||||
#
|
||||
### example site plugin for "foo":
|
||||
#
|
||||
# foo.zip <-- zip file for the plugin, with this structure:
|
||||
# _site/ <-- the contents that will be served
|
||||
# plugin-descriptor.properties <-- example contents below:
|
||||
#
|
||||
# site=true
|
||||
# description=My cool plugin
|
||||
# version=1.0
|
||||
#
|
||||
### example jvm plugin for "foo"
|
||||
#
|
||||
# foo.zip <-- zip file for the plugin, with this structure:
|
||||
# <arbitrary name1>.jar <-- classes, resources, dependencies
|
||||
# <arbitrary nameN>.jar <-- any number of jars
|
||||
# plugin-descriptor.properties <-- example contents below:
|
||||
#
|
||||
# jvm=true
|
||||
# classname=foo.bar.BazPlugin
|
||||
# description=My cool plugin
|
||||
# version=2.0.0-rc1
|
||||
# elasticsearch.version=2.0
|
||||
# java.version=1.7
|
||||
#
|
||||
### mandatory elements for all plugins:
|
||||
#
|
||||
# 'description': simple summary of the plugin
|
||||
description=IK Analyzer for Elasticsearch
|
||||
#
|
||||
# 'version': plugin's version
|
||||
version=1.10.1
|
||||
#
|
||||
# 'name': the plugin name
|
||||
name=analysis-ik
|
||||
|
||||
### mandatory elements for site plugins:
|
||||
#
|
||||
# 'site': set to true to indicate contents of the _site/
|
||||
# directory in the root of the plugin should be served.
|
||||
site=${elasticsearch.plugin.site}
|
||||
#
|
||||
### mandatory elements for jvm plugins :
|
||||
#
|
||||
# 'jvm': true if the 'classname' class should be loaded
|
||||
# from jar files in the root directory of the plugin.
|
||||
# Note that only jar files in the root directory are
|
||||
# added to the classpath for the plugin! If you need
|
||||
# other resources, package them into a resources jar.
|
||||
jvm=true
|
||||
#
|
||||
# 'classname': the name of the class to load, fully-qualified.
|
||||
classname=org.elasticsearch.plugin.analysis.ik.AnalysisIkPlugin
|
||||
#
|
||||
# 'java.version' version of java the code is built against
|
||||
# use the system property java.specification.version
|
||||
# version string must be a sequence of nonnegative decimal integers
|
||||
# separated by "."'s and may have leading zeros
|
||||
java.version=1.7
|
||||
#
|
||||
# 'elasticsearch.version' version of elasticsearch compiled against
|
||||
# You will have to release a new version of the plugin for each new
|
||||
# elasticsearch release. This version is checked when the plugin
|
||||
# is loaded so Elasticsearch will refuse to start in the presence of
|
||||
# plugins with the incorrect elasticsearch.version.
|
||||
elasticsearch.version=2.4.1
|
||||
#
|
||||
### deprecated elements for jvm plugins :
|
||||
#
|
||||
# 'isolated': true if the plugin should have its own classloader.
|
||||
# passing false is deprecated, and only intended to support plugins
|
||||
# that have hard dependencies against each other. If this is
|
||||
# not specified, then the plugin is isolated by default.
|
||||
isolated=${elasticsearch.plugin.isolated}
|
||||
#
|
||||
@@ -1,181 +0,0 @@
|
||||
server {
|
||||
listen 443 ssl http2 fastopen=3 reuseport;
|
||||
|
||||
server_name www.deepzz.com deepzz.com;
|
||||
server_tokens off;
|
||||
|
||||
include /data/eiblog/conf/nginx/ip.blacklist;
|
||||
|
||||
# 现在一般证书是内置的。可以注释该项
|
||||
# https://imququ.com/post/certificate-transparency.html#toc-2
|
||||
# ssl_ct on;
|
||||
# ssl_ct_static_scts /data/eiblog/conf/scts;
|
||||
|
||||
# 中间证书 + 站点证书
|
||||
ssl_certificate /data/eiblog/conf/ssl/domain.pem;
|
||||
|
||||
# 创建 CSR 文件时用的密钥
|
||||
ssl_certificate_key /data/eiblog/conf/ssl/domain.key;
|
||||
|
||||
# openssl dhparam -out dhparams.pem 2048
|
||||
# https://weakdh.org/sysadmin.html
|
||||
ssl_dhparam /data/eiblog/conf/ssl/dhparams.pem;
|
||||
|
||||
# https://github.com/cloudflare/sslconfig/blob/master/conf
|
||||
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
|
||||
|
||||
# 如果启用了 RSA + ECDSA 双证书,Cipher Suite 可以参考以下配置:
|
||||
# ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
|
||||
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||
|
||||
ssl_session_cache shared:SSL:50m;
|
||||
ssl_session_timeout 1d;
|
||||
|
||||
ssl_session_tickets on;
|
||||
|
||||
# openssl rand 48 > session_ticket.key
|
||||
# 单机部署可以不指定 ssl_session_ticket_key
|
||||
# ssl_session_ticket_key /data/eiblog/conf/ssl/session_ticket.key;
|
||||
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
|
||||
# 根证书 + 中间证书
|
||||
# https://imququ.com/post/why-can-not-turn-on-ocsp-stapling.html
|
||||
ssl_trusted_certificate /data/eiblog/conf/ssl/full_chained.pem;
|
||||
|
||||
resolver 8.8.8.8 114.114.114.114 valid=300s;
|
||||
resolver_timeout 10s;
|
||||
|
||||
access_log /data/eiblog/logdata/nginx.log;
|
||||
|
||||
if ($request_method !~ ^(GET|HEAD|POST|OPTIONS)$ ) {
|
||||
return 444;
|
||||
}
|
||||
|
||||
if ($host != 'deepzz.com' ) {
|
||||
rewrite ^/(.*)$ https://deepzz.com/$1 permanent;
|
||||
}
|
||||
|
||||
# webmaster 站点验证相关
|
||||
location ~* (robots\.txt|favicon\.ico|crossdomain\.xml|google4c90d18e696bdcf8\.html|BingSiteAuth\.xml)$ {
|
||||
root /data/eiblog/static;
|
||||
expires 1d;
|
||||
}
|
||||
|
||||
location ^~ /static/uploads/ {
|
||||
root /home/jerry/www/imququ.com/www;
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
|
||||
set $expires_time max;
|
||||
|
||||
valid_referers blocked none server_names *.qgy18.com *.inoreader.com feedly.com *.feedly.com www.udpwork.com theoldreader.com digg.com *.feiworks.com *.newszeit.com r.mail.qq.com yuedu.163.com *.w3ctech.com;
|
||||
if ($invalid_referer) {
|
||||
set $expires_time -1;
|
||||
return 403;
|
||||
}
|
||||
|
||||
expires $expires_time;
|
||||
}
|
||||
|
||||
location ^~ /static/ {
|
||||
root /data/eiblog;
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
expires max;
|
||||
}
|
||||
|
||||
location ^~ /admin/ {
|
||||
proxy_http_version 1.1;
|
||||
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
||||
|
||||
# deny 将完全不允许页面被嵌套,可能会导致一些异常。如果遇到这样的问题,建议改成 SAMEORIGIN
|
||||
# https://imququ.com/post/web-security-and-response-header.html#toc-1
|
||||
add_header X-Frame-Options deny;
|
||||
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host deepzz.com;
|
||||
proxy_set_header X-Real_IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
proxy_pass http://127.0.0.1:9000;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_http_version 1.1;
|
||||
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
||||
add_header X-Frame-Options deny;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
# 改deepzz相关的
|
||||
add_header Content-Security-Policy "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' blob: https:; img-src data: https: https://st.deepzz.com; style-src 'unsafe-inline' https:; child-src https:; connect-src 'self' https://translate.googleapis.com; frame-src https://disqus.com https://www.slideshare.net";
|
||||
# 中间证书证书指纹
|
||||
# https://imququ.com/post/http-public-key-pinning.html
|
||||
add_header Public-Key-Pins 'pin-sha256="lnsM2T/O9/J84sJFdnrpsFp3awZJ+ZZbYpCWhGloaHI="; pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; max-age=2592000; includeSubDomains';
|
||||
add_header Cache-Control no-cache;
|
||||
add_header X-Via Aliyun.QingDao;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
|
||||
proxy_ignore_headers Set-Cookie;
|
||||
|
||||
proxy_hide_header Vary;
|
||||
proxy_hide_header X-Powered-By;
|
||||
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host deepzz.com;
|
||||
proxy_set_header X-Real_IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
proxy_pass http://127.0.0.1:9000;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
server_name www.deepzz.com deepzz.com;
|
||||
server_tokens off;
|
||||
|
||||
access_log /dev/null;
|
||||
|
||||
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
|
||||
return 444;
|
||||
}
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
alias /home/jerry/www/challenges/;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location / {
|
||||
rewrite ^/(.*)$ https://deepzz.com/$1 permanent;
|
||||
}
|
||||
}
|
||||
|
||||
# 原博客,内部做的转发
|
||||
server {
|
||||
server_name blog.deepzz.com;
|
||||
access_log /dev/null;
|
||||
|
||||
location / {
|
||||
rewrite ^/(.*)$ https://blog.deepzz.com/$1 permanent;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443;
|
||||
server_name blog.deepzz.com;
|
||||
|
||||
add_header Strict-Transport-Security "max-age=31536000";
|
||||
add_header X-Frame-Options deny;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-Xss-Protection "1; mode=block;";
|
||||
|
||||
|
||||
location / {
|
||||
proxy_pass https://127.0.0.1:9010;
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
|
||||
#user nobody;
|
||||
worker_processes 1;
|
||||
|
||||
#error_log logs/error.log;
|
||||
#error_log logs/error.log notice;
|
||||
#error_log logs/error.log info;
|
||||
|
||||
#pid logs/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
charset UTF-8;
|
||||
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
#access_log logs/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
|
||||
gzip_comp_level 6;
|
||||
gzip_buffers 16 8k;
|
||||
|
||||
gzip_min_length 1000;
|
||||
gzip_proxied any;
|
||||
gzip_disable "msie6";
|
||||
|
||||
gzip_http_version 1.0;
|
||||
|
||||
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
#charset koi8-r;
|
||||
|
||||
#access_log logs/host.access.log main;
|
||||
|
||||
location / {
|
||||
root html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
#error_page 404 /404.html;
|
||||
|
||||
# redirect server error pages to the static page /50x.html
|
||||
#
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
|
||||
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# proxy_pass http://127.0.0.1;
|
||||
#}
|
||||
|
||||
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# root html;
|
||||
# fastcgi_pass 127.0.0.1:9000;
|
||||
# fastcgi_index index.php;
|
||||
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
||||
# include fastcgi_params;
|
||||
#}
|
||||
|
||||
# deny access to .htaccess files, if Apache's document root
|
||||
# concurs with nginx's one
|
||||
#
|
||||
#location ~ /\.ht {
|
||||
# deny all;
|
||||
#}
|
||||
}
|
||||
|
||||
|
||||
# another virtual host using mix of IP-, name-, and port-based configuration
|
||||
#
|
||||
#server {
|
||||
# listen 8000;
|
||||
# listen somename:8080;
|
||||
# server_name somename alias another.alias;
|
||||
|
||||
# location / {
|
||||
# root html;
|
||||
# index index.html index.htm;
|
||||
# }
|
||||
#}
|
||||
|
||||
|
||||
# HTTPS server
|
||||
#
|
||||
#server {
|
||||
# listen 443 ssl;
|
||||
# server_name localhost;
|
||||
|
||||
# ssl_certificate cert.pem;
|
||||
# ssl_certificate_key cert.key;
|
||||
|
||||
# ssl_session_cache shared:SSL:1m;
|
||||
# ssl_session_timeout 5m;
|
||||
|
||||
# ssl_ciphers HIGH:!aNULL:!MD5;
|
||||
# ssl_prefer_server_ciphers on;
|
||||
|
||||
# location / {
|
||||
# root html;
|
||||
# index index.html index.htm;
|
||||
# }
|
||||
#}
|
||||
|
||||
include /data/eiblog/conf/nginx/domain/*.conf;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
-----BEGIN DH PARAMETERS-----
|
||||
MIIBCAKCAQEAzkJoGFJJGMXQBVIq0DFom7qI3vD7Z8JMQnfCLpoi9AfqW6kGq/bR
|
||||
FhK9fuRkO+GdzZasx1mSNRQeX8GdaQM4GUn0yel7fxlxNC59mxo++P8NvmxQ47l4
|
||||
K9QpIRuqxa5UKIG6g3N5pkLwGjcD9a79v4DJn4XA9cVjRYc4BnYmiArgaMFOmGPy
|
||||
KmvU/VhFv8fnxSfn8uCmAGSuHmfbjx5TMfCqaeXzmmhyvpSl88JZfGlwOtXcOU0K
|
||||
O2JhNRKtaicZlevC8gtpFDNYKnf4K9kiUVmq0JLvuzOxN05sQoPYFCvgMFIYf+ND
|
||||
Jwtv7FWF2hQV3y1Xms7ja4776FcP9QlKuwIBAg==
|
||||
-----END DH PARAMETERS-----
|
||||
@@ -1,59 +0,0 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFXzCCBEegAwIBAgIQFcILcawsNlJ6B2Z9hxvG2DANBgkqhkiG9w0BAQsFADCB
|
||||
vTELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
|
||||
ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwOCBWZXJp
|
||||
U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MTgwNgYDVQQDEy9W
|
||||
ZXJpU2lnbiBVbml2ZXJzYWwgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAe
|
||||
Fw0xNjA4MTEwMDAwMDBaFw0yNjA4MTAyMzU5NTlaMIGXMQswCQYDVQQGEwJDTjEl
|
||||
MCMGA1UEChMcVHJ1c3RBc2lhIFRlY2hub2xvZ2llcywgSW5jLjEfMB0GA1UECxMW
|
||||
U3ltYW50ZWMgVHJ1c3QgTmV0d29yazEdMBsGA1UECxMURG9tYWluIFZhbGlkYXRl
|
||||
ZCBTU0wxITAfBgNVBAMTGFRydXN0QXNpYSBEViBTU0wgQ0EgLSBHNjCCASIwDQYJ
|
||||
KoZIhvcNAQEBBQADggEPADCCAQoCggEBAM6PcUG/2YcVEtzwDU9yj/F5Ed4M5LBW
|
||||
8ln6HwMRuXuDgKIz6t6OBeF7tqaZPwZ8NRgwwhtEcnyeuDPjS/HYvQqEZZWQpnut
|
||||
njNGniplXkOngD48f0Bhdo5Rwtqv13UiV59gfP/PSy81atddMqgtt5WeITaseddh
|
||||
4sVZV0bj2b37lJ0w/2TRm+gzIp12lzliIkZr9OdgAKRWpITs0TtU0jJq6gXR5fe7
|
||||
aut4GOVov5SZHJorXJSTkhdEIyoYWgUxNAIu83Ykw91/bjeXKFVvq8+tZZN3ct5F
|
||||
I7qbHRgcrLqRdZQPkKjQWC9hXFrQVZUSwRMjRN2O3TXvmtprFr4od+0CAwEAAaOC
|
||||
AX0wggF5MBIGA1UdEwEB/wQIMAYBAf8CAQAwNgYDVR0fBC8wLTAroCmgJ4YlaHR0
|
||||
cDovL3Muc3ltY2IuY29tL3VuaXZlcnNhbC1yb290LmNybDAdBgNVHSUEFjAUBggr
|
||||
BgEFBQcDAQYIKwYBBQUHAwIwDgYDVR0PAQH/BAQDAgEGMC4GCCsGAQUFBwEBBCIw
|
||||
IDAeBggrBgEFBQcwAYYSaHR0cDovL3Muc3ltY2QuY29tMGEGA1UdIARaMFgwVgYG
|
||||
Z4EMAQIBMEwwIwYIKwYBBQUHAgEWF2h0dHBzOi8vZC5zeW1jYi5jb20vY3BzMCUG
|
||||
CCsGAQUFBwICMBkaF2h0dHBzOi8vZC5zeW1jYi5jb20vcnBhMCkGA1UdEQQiMCCk
|
||||
HjAcMRowGAYDVQQDExFTeW1hbnRlY1BLSS0yLTYwMjAdBgNVHQ4EFgQU3qQwrOQ/
|
||||
9ScrMXyvkGcdriKe7GQwHwYDVR0jBBgwFoAUtnf6aUhHn1MS1cLqBzJ2B9GXBxkw
|
||||
DQYJKoZIhvcNAQELBQADggEBAMS+q79V8jm2p5T8pdMCS8XuYjCVpsJuXh4QqegO
|
||||
Ors1D4nVEE0Thm7V6fy60UgOxsjXayauQonRoCdApv6bziW9USmUK2qQ5xFsgBBD
|
||||
LzwJnQd7FDUW9ngDNCo/377J2CLqiVsYFqNnpuVzbbWF/6UR+AxGwFzzAgx9QOLP
|
||||
Qucpx6kV+d0Ht2cm/+mwGlzmdr/RwcT5iLW0oAQZkcfzbi+s9bBaIprMOCiyvO/F
|
||||
Gf1YDO4KQHMfda+GO6HpmPl8nDFgP17Bi3QgRjr1kjpZ9WvnPQha1wZLel+VGm/e
|
||||
xOXNrbei6P5U58U0Hy3GsO5r/IxRE5k55tR5o5E2EB0ilSg=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEuTCCA6GgAwIBAgIQQBrEZCGzEyEDDrvkEhrFHTANBgkqhkiG9w0BAQsFADCB
|
||||
vTELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
|
||||
ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwOCBWZXJp
|
||||
U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MTgwNgYDVQQDEy9W
|
||||
ZXJpU2lnbiBVbml2ZXJzYWwgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAe
|
||||
Fw0wODA0MDIwMDAwMDBaFw0zNzEyMDEyMzU5NTlaMIG9MQswCQYDVQQGEwJVUzEX
|
||||
MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0
|
||||
IE5ldHdvcmsxOjA4BgNVBAsTMShjKSAyMDA4IFZlcmlTaWduLCBJbmMuIC0gRm9y
|
||||
IGF1dGhvcml6ZWQgdXNlIG9ubHkxODA2BgNVBAMTL1ZlcmlTaWduIFVuaXZlcnNh
|
||||
bCBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEF
|
||||
AAOCAQ8AMIIBCgKCAQEAx2E3XrEBNNti1xWb/1hajCMj1mCOkdeQmIN65lgZOIzF
|
||||
9uVkhbSicfvtvbnazU0AtMgtc6XHaXGVHzk8skQHnOgO+k1KxCHfKWGPMiJhgsWH
|
||||
H26MfF8WIFFE0XBPV+rjHOPMee5Y2A7Cs0WTwCznmhcrewA3ekEzeOEz4vMQGn+H
|
||||
LL729fdC4uW/h2KJXwBL38Xd5HVEMkE6HnFuacsLdUYI0crSK5XQz/u5QGtkjFdN
|
||||
/BMReYTtXlT2NJ8IAfMQJQYXStrxHXpma5hgZqTZ79IugvHw7wnqRMkVauIDbjPT
|
||||
rJ9VAMf2CGqUuV/c4DPxhGD5WycRtPwW8rtWaoAljQIDAQABo4GyMIGvMA8GA1Ud
|
||||
EwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMG0GCCsGAQUFBwEMBGEwX6FdoFsw
|
||||
WTBXMFUWCWltYWdlL2dpZjAhMB8wBwYFKw4DAhoEFI/l0xqGrI2Oa8PPgGrUSBgs
|
||||
exkuMCUWI2h0dHA6Ly9sb2dvLnZlcmlzaWduLmNvbS92c2xvZ28uZ2lmMB0GA1Ud
|
||||
DgQWBBS2d/ppSEefUxLVwuoHMnYH0ZcHGTANBgkqhkiG9w0BAQsFAAOCAQEASvj4
|
||||
sAPmLGd75JR3Y8xuTPl9Dg3cyLk1uXBPY/ok+myDjEedO2Pzmvl2MpWRsXe8rJq+
|
||||
seQxIcaBlVZaDrHC1LGmWazxY8u4TB1ZkErvkBYoH1quEPuBUDgMbMzxPcP1Y+Oz
|
||||
4yHJJDnp/RVmRvQbEdBNc6N9Rvk97ahfYtTxP/jgdFcrGJ2BtMQo2pSXpXDrrB2+
|
||||
BxHw1dvd5Yzw1TKwg+ZX4o+/vqGqvz0dtdQ46tewXDpPaj+PwGZsY6rp2aQW9IHR
|
||||
lRQOfc2VNNnSj3BzgXucfr2YYdhFh5iQxeuGMMY1v/D/w1WIg0vvBZIGcfK4mJO3
|
||||
7M2CYfE45k+XmCpajQ==
|
||||
-----END CERTIFICATE-----
|
||||
@@ -1 +0,0 @@
|
||||
╟░Щ`*dы≤\ЛвH
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>{{.Title}}</title>
|
||||
<link>https://{{.Domain}}</link>
|
||||
<description>{{.SubTitle}}</description>
|
||||
<atom:link href="https://{{.Domain}}/rss.html" rel="self"/>
|
||||
<atom:link href="{{.FeedrURL}}" rel="hub"/>
|
||||
<language>zh-CN</language>
|
||||
<lastBuildDate>{{.BuildDate}}</lastBuildDate>
|
||||
{{range .Artcs}}
|
||||
<item>
|
||||
<title>{{.Title}}</title>
|
||||
<link>https://{{$.Domain}}/post/{{.Slug}}.html</link>
|
||||
<comments>https://{{$.Domain}}/post/{{.Slug}}.html#comments</comments>
|
||||
<guid>https://{{$.Domain}}/post/{{.Slug}}.html</guid>
|
||||
<description><![CDATA[<blockquote>{{.Content}}<p>本文链接:<a href="https://{{$.Domain}}/post/{{.Slug}}.html">https://{{$.Domain}}/post/{{.Slug}}.html</a>,<a href="https://{{$.Domain}}/post/{{.Slug}}.html#comments">参与评论 »</a></p>]]></description>
|
||||
</item>
|
||||
{{end}}
|
||||
</channel>
|
||||
</rss>
|
||||
603
db.go
@@ -1,603 +0,0 @@
|
||||
// Package main provides ...
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/blackfriday"
|
||||
"github.com/eiblog/eiblog/setting"
|
||||
"github.com/eiblog/utils/logd"
|
||||
db "github.com/eiblog/utils/mgo"
|
||||
"gopkg.in/mgo.v2"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
const (
|
||||
DB = "eiblog"
|
||||
COLLECTION_ACCOUNT = "account"
|
||||
COLLECTION_ARTICLE = "article"
|
||||
COUNTER_SERIE = "serie"
|
||||
COUNTER_ARTICLE = "article"
|
||||
SERIES_MD = "series_md"
|
||||
ARCHIVE_MD = "archive_md"
|
||||
ADD = "add"
|
||||
DELETE = "delete"
|
||||
)
|
||||
|
||||
const (
|
||||
commonHtmlFlags = 0 |
|
||||
blackfriday.HTML_TOC |
|
||||
blackfriday.HTML_USE_XHTML |
|
||||
blackfriday.HTML_USE_SMARTYPANTS |
|
||||
blackfriday.HTML_SMARTYPANTS_FRACTIONS |
|
||||
blackfriday.HTML_SMARTYPANTS_DASHES |
|
||||
blackfriday.HTML_SMARTYPANTS_LATEX_DASHES |
|
||||
blackfriday.HTML_NOFOLLOW_LINKS
|
||||
|
||||
commonExtensions = 0 |
|
||||
blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
|
||||
blackfriday.EXTENSION_TABLES |
|
||||
blackfriday.EXTENSION_FENCED_CODE |
|
||||
blackfriday.EXTENSION_AUTOLINK |
|
||||
blackfriday.EXTENSION_STRIKETHROUGH |
|
||||
blackfriday.EXTENSION_SPACE_HEADERS |
|
||||
blackfriday.EXTENSION_HEADER_IDS |
|
||||
blackfriday.EXTENSION_BACKSLASH_LINE_BREAK |
|
||||
blackfriday.EXTENSION_DEFINITION_LISTS
|
||||
)
|
||||
|
||||
// Global Account
|
||||
var (
|
||||
Ei *Account
|
||||
lock sync.Mutex
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 数据库加索引
|
||||
ms, c := db.Connect(DB, COLLECTION_ACCOUNT)
|
||||
index := mgo.Index{
|
||||
Key: []string{"username"},
|
||||
Unique: true,
|
||||
DropDups: true,
|
||||
Background: true,
|
||||
Sparse: true,
|
||||
}
|
||||
if err := c.EnsureIndex(index); err != nil {
|
||||
logd.Fatal(err)
|
||||
}
|
||||
ms.Close()
|
||||
ms, c = db.Connect(DB, COLLECTION_ARTICLE)
|
||||
index = mgo.Index{
|
||||
Key: []string{"id"},
|
||||
Unique: true,
|
||||
DropDups: true,
|
||||
Background: true,
|
||||
Sparse: true,
|
||||
}
|
||||
if err := c.EnsureIndex(index); err != nil {
|
||||
logd.Fatal(err)
|
||||
}
|
||||
index = mgo.Index{
|
||||
Key: []string{"slug"},
|
||||
Unique: true,
|
||||
DropDups: true,
|
||||
Background: true,
|
||||
Sparse: true,
|
||||
}
|
||||
if err := c.EnsureIndex(index); err != nil {
|
||||
logd.Fatal(err)
|
||||
}
|
||||
ms.Close()
|
||||
// 读取帐号信息
|
||||
Ei = loadAccount()
|
||||
// 获取文章
|
||||
Ei.Articles = loadArticles()
|
||||
// 生成markdown文档
|
||||
go generateMarkdown()
|
||||
// 启动定时器
|
||||
go timer()
|
||||
// 获取评论数量
|
||||
go PostsCount()
|
||||
}
|
||||
|
||||
// 读取或初始化帐号信息
|
||||
func loadAccount() (a *Account) {
|
||||
a = &Account{}
|
||||
err := db.FindOne(DB, COLLECTION_ACCOUNT, bson.M{"username": setting.Conf.Account.Username}, a)
|
||||
// 初始化用户数据
|
||||
if err == mgo.ErrNotFound {
|
||||
a = &Account{
|
||||
Username: setting.Conf.Account.Username,
|
||||
Password: EncryptPasswd(setting.Conf.Account.Username, setting.Conf.Account.Password),
|
||||
Email: setting.Conf.Account.Email,
|
||||
PhoneN: setting.Conf.Account.PhoneNumber,
|
||||
Address: setting.Conf.Account.Address,
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
a.BlogName = setting.Conf.Blogger.BlogName
|
||||
a.SubTitle = setting.Conf.Blogger.SubTitle
|
||||
a.BeiAn = setting.Conf.Blogger.BeiAn
|
||||
a.BTitle = setting.Conf.Blogger.BTitle
|
||||
a.Copyright = setting.Conf.Blogger.Copyright
|
||||
err = db.Insert(DB, COLLECTION_ACCOUNT, a)
|
||||
generateTopic()
|
||||
} else if err != nil {
|
||||
logd.Fatal(err)
|
||||
}
|
||||
a.CH = make(chan string, 2)
|
||||
a.MapArticles = make(map[string]*Article)
|
||||
a.Tags = make(map[string]SortArticles)
|
||||
return
|
||||
}
|
||||
|
||||
func loadArticles() (artcs SortArticles) {
|
||||
err := db.FindAll(DB, COLLECTION_ARTICLE, bson.M{"isdraft": false, "deletetime": bson.M{"$eq": time.Time{}}}, &artcs)
|
||||
if err != nil {
|
||||
logd.Fatal(err)
|
||||
}
|
||||
sort.Sort(artcs)
|
||||
for i, v := range artcs {
|
||||
// 渲染文章
|
||||
GenerateExcerptAndRender(v)
|
||||
Ei.MapArticles[v.Slug] = v
|
||||
// 分析文章
|
||||
if v.ID < setting.Conf.StartID {
|
||||
continue
|
||||
}
|
||||
if i > 0 {
|
||||
v.Prev = artcs[i-1]
|
||||
}
|
||||
if artcs[i+1].ID >= setting.Conf.StartID {
|
||||
v.Next = artcs[i+1]
|
||||
}
|
||||
ManageTagsArticle(v, false, ADD)
|
||||
ManageSeriesArticle(v, false, ADD)
|
||||
ManageArchivesArticle(v, false, ADD)
|
||||
}
|
||||
Ei.CH <- SERIES_MD
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
return
|
||||
}
|
||||
|
||||
// generate series,archive markdown
|
||||
func generateMarkdown() {
|
||||
for {
|
||||
switch typ := <-Ei.CH; typ {
|
||||
case SERIES_MD:
|
||||
sort.Sort(Ei.Series)
|
||||
var buffer bytes.Buffer
|
||||
buffer.WriteString(Ei.SeriesSay)
|
||||
buffer.WriteString("\n\n")
|
||||
for _, serie := range Ei.Series {
|
||||
buffer.WriteString(fmt.Sprintf("### %s{#toc-%d}", serie.Name, serie.ID))
|
||||
buffer.WriteString("\n")
|
||||
buffer.WriteString(serie.Desc)
|
||||
buffer.WriteString("\n\n")
|
||||
for _, artc := range serie.Articles {
|
||||
//eg. * [标题一](/post/hello-world.html) <span class="date">(Man 02, 2006)</span>
|
||||
buffer.WriteString("* [" + artc.Title + "](/post/" + artc.Slug + ".html) <span class=\"date\">(" + artc.CreateTime.Format("Jan 02, 2006") + ")</span>\n")
|
||||
}
|
||||
buffer.WriteByte('\n')
|
||||
}
|
||||
Ei.PageSeries = string(renderPage(buffer.Bytes()))
|
||||
case ARCHIVE_MD:
|
||||
sort.Sort(Ei.Archives)
|
||||
var buffer bytes.Buffer
|
||||
buffer.WriteString(Ei.ArchivesSay)
|
||||
buffer.WriteString("\n\n")
|
||||
for _, archive := range Ei.Archives {
|
||||
buffer.WriteString(fmt.Sprintf("### %s", archive.Time.Format("2006年01月")))
|
||||
buffer.WriteString("\n\n")
|
||||
for _, artc := range archive.Articles {
|
||||
buffer.WriteString("* [" + artc.Title + "](/post/" + artc.Slug + ".html) <span class=\"date\">(" + artc.CreateTime.Format("Jan 02, 2006") + ")</span>\n")
|
||||
}
|
||||
buffer.WriteByte('\n')
|
||||
}
|
||||
Ei.PageArchives = string(renderPage(buffer.Bytes()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// init account: generate blogroll and about page
|
||||
func generateTopic() {
|
||||
about := &Article{
|
||||
ID: db.NextVal(DB, COUNTER_ARTICLE),
|
||||
Author: setting.Conf.Account.Username,
|
||||
Title: "关于",
|
||||
Slug: "about",
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
}
|
||||
blogroll := &Article{
|
||||
ID: db.NextVal(DB, COUNTER_ARTICLE),
|
||||
Author: setting.Conf.Account.Username,
|
||||
Title: "友情链接",
|
||||
Slug: "blogroll",
|
||||
UpdateTime: time.Now(),
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
err := db.Insert(DB, COLLECTION_ARTICLE, blogroll)
|
||||
if err != nil {
|
||||
logd.Fatal(err)
|
||||
}
|
||||
err = db.Insert(DB, COLLECTION_ARTICLE, about)
|
||||
if err != nil {
|
||||
logd.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// render page
|
||||
func renderPage(md []byte) []byte {
|
||||
renderer := blackfriday.HtmlRenderer(commonHtmlFlags, "", "")
|
||||
return blackfriday.Markdown(md, renderer, commonExtensions)
|
||||
}
|
||||
|
||||
// 文章分页
|
||||
func PageList(p, n int) (prev int, next int, artcs []*Article) {
|
||||
var l int
|
||||
for l = len(Ei.Articles); l > 0; l-- {
|
||||
if Ei.Articles[l-1].ID >= setting.Conf.StartID {
|
||||
break
|
||||
}
|
||||
}
|
||||
if l == 0 {
|
||||
return 0, 0, nil
|
||||
}
|
||||
m := l / n
|
||||
if d := l % n; d > 0 {
|
||||
m++
|
||||
}
|
||||
if p > m {
|
||||
p = m
|
||||
}
|
||||
if p > 1 {
|
||||
prev = p - 1
|
||||
}
|
||||
if p < m {
|
||||
next = p + 1
|
||||
}
|
||||
s := (p - 1) * n
|
||||
e := p * n
|
||||
if e > l {
|
||||
e = l
|
||||
}
|
||||
artcs = Ei.Articles[s:e]
|
||||
return
|
||||
}
|
||||
|
||||
func ManageTagsArticle(artc *Article, s bool, do string) {
|
||||
switch do {
|
||||
case ADD:
|
||||
for _, tag := range artc.Tags {
|
||||
Ei.Tags[tag] = append(Ei.Tags[tag], artc)
|
||||
if s {
|
||||
sort.Sort(Ei.Tags[tag])
|
||||
}
|
||||
}
|
||||
case DELETE:
|
||||
for _, tag := range artc.Tags {
|
||||
for i, v := range Ei.Tags[tag] {
|
||||
if v == artc {
|
||||
Ei.Tags[tag] = append(Ei.Tags[tag][0:i], Ei.Tags[tag][i+1:]...)
|
||||
if len(Ei.Tags[tag]) == 0 {
|
||||
delete(Ei.Tags, tag)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ManageSeriesArticle(artc *Article, s bool, do string) {
|
||||
switch do {
|
||||
case ADD:
|
||||
for i, serie := range Ei.Series {
|
||||
if serie.ID == artc.SerieID {
|
||||
Ei.Series[i].Articles = append(Ei.Series[i].Articles, artc)
|
||||
if s {
|
||||
sort.Sort(Ei.Series[i].Articles)
|
||||
Ei.CH <- SERIES_MD
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
case DELETE:
|
||||
for i, serie := range Ei.Series {
|
||||
if serie.ID == artc.SerieID {
|
||||
for j, v := range serie.Articles {
|
||||
if v == artc {
|
||||
Ei.Series[i].Articles = append(Ei.Series[i].Articles[0:j], Ei.Series[i].Articles[j+1:]...)
|
||||
Ei.CH <- SERIES_MD
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ManageArchivesArticle(artc *Article, s bool, do string) {
|
||||
switch do {
|
||||
case ADD:
|
||||
add := false
|
||||
y, m, _ := artc.CreateTime.Date()
|
||||
for i, archive := range Ei.Archives {
|
||||
ay, am, _ := archive.Time.Date()
|
||||
if y == ay && m == am {
|
||||
add = true
|
||||
Ei.Archives[i].Articles = append(Ei.Archives[i].Articles, artc)
|
||||
if s {
|
||||
sort.Sort(Ei.Archives[i].Articles)
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !add {
|
||||
Ei.Archives = append(Ei.Archives, &Archive{Time: artc.CreateTime, Articles: SortArticles{artc}})
|
||||
}
|
||||
case DELETE:
|
||||
for i, archive := range Ei.Archives {
|
||||
ay, am, _ := archive.Time.Date()
|
||||
if y, m, _ := artc.CreateTime.Date(); ay == y && am == m {
|
||||
for j, v := range archive.Articles {
|
||||
if v == artc {
|
||||
Ei.Archives[i].Articles = append(Ei.Archives[i].Articles[0:j], Ei.Archives[i].Articles[j+1:]...)
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染markdown操作和截取摘要操作
|
||||
var reg = regexp.MustCompile(setting.Conf.Identifier)
|
||||
|
||||
// header
|
||||
var regH = regexp.MustCompile("</nav></div>")
|
||||
|
||||
func GenerateExcerptAndRender(artc *Article) {
|
||||
content := renderPage([]byte(artc.Content))
|
||||
index := regH.FindIndex(content)
|
||||
if index != nil {
|
||||
artc.Header = string(content[0:index[1]])
|
||||
artc.Content = string(content[index[1]:])
|
||||
} else {
|
||||
artc.Content = string(content)
|
||||
}
|
||||
index = reg.FindStringIndex(artc.Content)
|
||||
if index != nil {
|
||||
artc.Excerpt = IgnoreHtmlTag(artc.Content[0:index[0]])
|
||||
} else {
|
||||
uc := []rune(artc.Content)
|
||||
length := setting.Conf.Length
|
||||
if len(uc) < length {
|
||||
length = len(uc)
|
||||
}
|
||||
artc.Excerpt = IgnoreHtmlTag(string(uc[0:length]))
|
||||
}
|
||||
}
|
||||
|
||||
// 读取草稿箱
|
||||
func LoadDraft() (artcs SortArticles, err error) {
|
||||
err = db.FindAll(DB, COLLECTION_ARTICLE, bson.M{"isdraft": true}, &artcs)
|
||||
sort.Sort(artcs)
|
||||
return
|
||||
}
|
||||
|
||||
// 读取回收箱
|
||||
func LoadTrash() (artcs SortArticles, err error) {
|
||||
err = db.FindAll(DB, COLLECTION_ARTICLE, bson.M{"deletetime": bson.M{"$ne": time.Time{}}}, &artcs)
|
||||
sort.Sort(artcs)
|
||||
return
|
||||
}
|
||||
|
||||
// 添加文章
|
||||
func AddArticle(artc *Article) error {
|
||||
// 分配ID, 占位至起始id
|
||||
for {
|
||||
if id := db.NextVal(DB, COUNTER_ARTICLE); id < setting.Conf.StartID {
|
||||
continue
|
||||
} else {
|
||||
artc.ID = id
|
||||
break
|
||||
}
|
||||
}
|
||||
if !artc.IsDraft {
|
||||
defer GenerateExcerptAndRender(artc)
|
||||
Ei.MapArticles[artc.Slug] = artc
|
||||
Ei.Articles = append([]*Article{artc}, Ei.Articles...)
|
||||
sort.Sort(Ei.Articles)
|
||||
AddToLinkedList(artc.ID)
|
||||
ManageTagsArticle(artc, true, ADD)
|
||||
ManageSeriesArticle(artc, true, ADD)
|
||||
ManageArchivesArticle(artc, true, ADD)
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
if artc.SerieID > 0 {
|
||||
Ei.CH <- SERIES_MD
|
||||
}
|
||||
}
|
||||
return db.Insert(DB, COLLECTION_ARTICLE, artc)
|
||||
}
|
||||
|
||||
// 删除文章,移入回收箱
|
||||
func DelArticles(ids ...int32) error {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
for _, id := range ids {
|
||||
i, artc := GetArticle(id)
|
||||
DelFromLinkedList(artc)
|
||||
Ei.Articles = append(Ei.Articles[:i], Ei.Articles[i+1:]...)
|
||||
delete(Ei.MapArticles, artc.Slug)
|
||||
ManageTagsArticle(artc, false, DELETE)
|
||||
ManageSeriesArticle(artc, false, DELETE)
|
||||
ManageArchivesArticle(artc, false, DELETE)
|
||||
err := UpdateArticle(bson.M{"id": id}, bson.M{"$set": bson.M{"deletetime": time.Now()}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
artc = nil
|
||||
}
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
Ei.CH <- SERIES_MD
|
||||
return nil
|
||||
}
|
||||
|
||||
func DelFromLinkedList(artc *Article) {
|
||||
if artc.Prev == nil && artc.Next != nil {
|
||||
artc.Next.Prev = nil
|
||||
} else if artc.Prev != nil && artc.Next == nil {
|
||||
artc.Prev.Next = nil
|
||||
} else if artc.Prev != nil && artc.Next != nil {
|
||||
artc.Prev.Next = artc.Next
|
||||
artc.Next.Prev = artc.Prev
|
||||
}
|
||||
}
|
||||
|
||||
func AddToLinkedList(id int32) {
|
||||
i, artc := GetArticle(id)
|
||||
if i == 0 && Ei.Articles[i+1].ID >= setting.Conf.StartID {
|
||||
artc.Next = Ei.Articles[i+1]
|
||||
Ei.Articles[i+1].Prev = artc
|
||||
} else if i > 0 && Ei.Articles[i-1].ID >= setting.Conf.StartID {
|
||||
artc.Prev = Ei.Articles[i-1]
|
||||
if Ei.Articles[i-1].Next != nil {
|
||||
artc.Next = Ei.Articles[i-1].Next
|
||||
Ei.Articles[i-1].Next.Prev = artc
|
||||
}
|
||||
Ei.Articles[i-1].Next = artc
|
||||
}
|
||||
}
|
||||
|
||||
// 从缓存获取文章
|
||||
func GetArticle(id int32) (int, *Article) {
|
||||
for i, artc := range Ei.Articles {
|
||||
if id == artc.ID {
|
||||
return i, artc
|
||||
}
|
||||
}
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
// 定时清除回收箱文章
|
||||
func timer() {
|
||||
delT := time.NewTicker(time.Duration(setting.Conf.Clean) * time.Hour)
|
||||
for {
|
||||
<-delT.C
|
||||
db.Remove(DB, COLLECTION_ARTICLE, bson.M{"deletetime": bson.M{"$gt": time.Time{}, "$lt": time.Now().Add(time.Duration(setting.Conf.Trash) * time.Hour)}})
|
||||
}
|
||||
}
|
||||
|
||||
// 操作帐号字段
|
||||
func UpdateAccountField(M bson.M) error {
|
||||
return db.Update(DB, COLLECTION_ACCOUNT, bson.M{"username": Ei.Username}, M)
|
||||
}
|
||||
|
||||
// 删除草稿箱或回收箱,永久删除
|
||||
func RemoveArticle(id int32) error {
|
||||
return db.Remove(DB, COLLECTION_ARTICLE, bson.M{"id": id})
|
||||
}
|
||||
|
||||
// 恢复删除文章到草稿箱
|
||||
func RecoverArticle(id int32) error {
|
||||
return db.Update(DB, COLLECTION_ARTICLE, bson.M{"id": id}, bson.M{"$set": bson.M{"deletetime": time.Time{}, "isdraft": true}})
|
||||
}
|
||||
|
||||
// 更新文章
|
||||
func UpdateArticle(query, update interface{}) error {
|
||||
return db.Update(DB, COLLECTION_ARTICLE, query, update)
|
||||
}
|
||||
|
||||
// 编辑文档
|
||||
func QueryArticle(id int32) *Article {
|
||||
artc := &Article{}
|
||||
if err := db.FindOne(DB, COLLECTION_ARTICLE, bson.M{"id": id}, artc); err != nil {
|
||||
return nil
|
||||
}
|
||||
return artc
|
||||
}
|
||||
|
||||
// 添加专题
|
||||
func AddSerie(name, slug, desc string) error {
|
||||
serie := &Serie{db.NextVal(DB, COUNTER_SERIE), name, slug, desc, time.Now(), nil}
|
||||
Ei.Series = append(Ei.Series, serie)
|
||||
sort.Sort(Ei.Series)
|
||||
Ei.CH <- SERIES_MD
|
||||
return UpdateAccountField(bson.M{"$addToSet": bson.M{"blogger.series": serie}})
|
||||
}
|
||||
|
||||
// 更新专题
|
||||
func UpdateSerie(serie *Serie) error {
|
||||
Ei.CH <- SERIES_MD
|
||||
return db.Update(DB, COLLECTION_ACCOUNT, bson.M{"username": Ei.Username, "blogger.series.id": serie.ID}, bson.M{"$set": bson.M{"blogger.series.$": serie}})
|
||||
}
|
||||
|
||||
// 删除专题
|
||||
func DelSerie(id int32) error {
|
||||
for i, serie := range Ei.Series {
|
||||
if id == serie.ID {
|
||||
if len(serie.Articles) > 0 {
|
||||
return fmt.Errorf("请删除该专题下的所有文章")
|
||||
}
|
||||
err := UpdateAccountField(bson.M{"$pull": bson.M{"blogger.series": bson.M{"id": id}}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Ei.Series[i] = nil
|
||||
Ei.Series = append(Ei.Series[:i], Ei.Series[i+1:]...)
|
||||
Ei.CH <- SERIES_MD
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 查找专题
|
||||
func QuerySerie(id int32) *Serie {
|
||||
for _, serie := range Ei.Series {
|
||||
if serie.ID == id {
|
||||
return serie
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func PageListBack(se int, kw string, draft, del bool, p, n int) (max int, artcs []*Article) {
|
||||
M := bson.M{}
|
||||
if draft {
|
||||
M["isdraft"] = true
|
||||
} else if del {
|
||||
M["deletetime"] = bson.M{"$ne": time.Time{}}
|
||||
} else {
|
||||
M["isdraft"] = false
|
||||
M["deletetime"] = bson.M{"$eq": time.Time{}}
|
||||
if se > 0 {
|
||||
M["serieid"] = se
|
||||
}
|
||||
if kw != "" {
|
||||
M["title"] = bson.M{"$regex": kw, "$options": "$i"}
|
||||
}
|
||||
}
|
||||
ms, c := db.Connect(DB, COLLECTION_ARTICLE)
|
||||
defer ms.Close()
|
||||
err := c.Find(M).Select(bson.M{"content": 0}).Sort("-createtime").Limit(n).Skip((p - 1) * n).All(&artcs)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
}
|
||||
count, err := c.Find(M).Count()
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
}
|
||||
max = count / n
|
||||
if count%n > 0 {
|
||||
max++
|
||||
}
|
||||
return
|
||||
}
|
||||
44
db_test.go
@@ -1,44 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPageListBack(t *testing.T) {
|
||||
_, artcs := PageListBack(0, "", false, false, 1, 20)
|
||||
for _, artc := range artcs {
|
||||
t.Log(*artc)
|
||||
}
|
||||
t.Log("------------------------------------------------------------")
|
||||
_, artcs = PageListBack(0, "", false, false, 2, 10)
|
||||
for _, artc := range artcs {
|
||||
t.Log(*artc)
|
||||
}
|
||||
t.Log("------------------------------------------------------------")
|
||||
_, artcs = PageListBack(3, "", false, false, 1, 20)
|
||||
for _, artc := range artcs {
|
||||
t.Log(*artc)
|
||||
}
|
||||
t.Log("------------------------------------------------------------")
|
||||
_, artcs = PageListBack(3, "19", false, false, 1, 20)
|
||||
for _, artc := range artcs {
|
||||
t.Log(*artc)
|
||||
}
|
||||
t.Log("------------------------------------------------------------")
|
||||
_, artcs = PageListBack(0, "", false, true, 1, 20)
|
||||
for _, artc := range artcs {
|
||||
t.Log(*artc)
|
||||
}
|
||||
t.Log("------------------------------------------------------------")
|
||||
_, artcs = PageListBack(0, "", true, false, 1, 20)
|
||||
for _, artc := range artcs {
|
||||
t.Log(*artc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddSerie(t *testing.T) {
|
||||
err := AddSerie("测试", "nothing", "这里是描述")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
185
disqus.go
@@ -1,185 +0,0 @@
|
||||
// Package main provides ...
|
||||
// Get article' comments count
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/setting"
|
||||
"github.com/eiblog/utils/logd"
|
||||
)
|
||||
|
||||
type result struct {
|
||||
Code int
|
||||
Response []struct {
|
||||
Posts int
|
||||
Identifiers []string
|
||||
}
|
||||
}
|
||||
|
||||
func PostsCount() {
|
||||
if setting.Conf.Disqus.PostsCount == "" || setting.Conf.Disqus.PublicKey == "" || setting.Conf.Disqus.ShortName == "" {
|
||||
return
|
||||
}
|
||||
baseUrl := setting.Conf.Disqus.PostsCount +
|
||||
"?api_key=" + setting.Conf.Disqus.PublicKey +
|
||||
"&forum=" + setting.Conf.Disqus.ShortName + "&"
|
||||
var count, index int
|
||||
for index < len(Ei.Articles) {
|
||||
logd.Debugf("count=====%d, index=======%d, length=======%d, bool=========%t\n", count, index, len(Ei.Articles), index < len(Ei.Articles) && count < 50)
|
||||
var threads []string
|
||||
for ; index < len(Ei.Articles) && count < 50; index++ {
|
||||
artc := Ei.Articles[index]
|
||||
threads = append(threads, fmt.Sprintf("thread:ident=post-%s", artc.Slug))
|
||||
count++
|
||||
}
|
||||
count = 0
|
||||
url := baseUrl + strings.Join(threads, "&")
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
break
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
break
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
logd.Error(string(b))
|
||||
break
|
||||
}
|
||||
rst := result{}
|
||||
err = json.Unmarshal(b, &rst)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
break
|
||||
}
|
||||
for _, v := range rst.Response {
|
||||
i := strings.Index(v.Identifiers[0], "-")
|
||||
artc := Ei.MapArticles[v.Identifiers[0][i+1:]]
|
||||
if artc != nil {
|
||||
artc.Count = v.Posts
|
||||
}
|
||||
}
|
||||
}
|
||||
time.AfterFunc(time.Duration(setting.Conf.Disqus.Interval)*time.Hour, PostsCount)
|
||||
}
|
||||
|
||||
type postsList struct {
|
||||
Cursor struct {
|
||||
HasNext bool
|
||||
Next string
|
||||
}
|
||||
Code int
|
||||
Response []struct {
|
||||
Parent int
|
||||
Id string
|
||||
CreatedAt string
|
||||
Message string
|
||||
Author struct {
|
||||
Name string
|
||||
ProfileUrl string
|
||||
Avatar struct {
|
||||
Cache string
|
||||
}
|
||||
}
|
||||
Thread string
|
||||
}
|
||||
}
|
||||
|
||||
func PostsList(slug, cursor string) *postsList {
|
||||
if setting.Conf.Disqus.PostsList == "" || setting.Conf.Disqus.PublicKey == "" || setting.Conf.Disqus.ShortName == "" {
|
||||
return nil
|
||||
}
|
||||
url := setting.Conf.Disqus.PostsList + "?limit=50&api_key=" +
|
||||
setting.Conf.Disqus.PublicKey + "&forum=" + setting.Conf.Disqus.ShortName +
|
||||
"&cursor=" + cursor + "&thread:ident=post-" + slug
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return nil
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
logd.Error(string(b))
|
||||
return nil
|
||||
}
|
||||
pl := &postsList{}
|
||||
err = json.Unmarshal(b, pl)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return nil
|
||||
}
|
||||
return pl
|
||||
}
|
||||
|
||||
type PostCreate struct {
|
||||
Message string `json:"message"`
|
||||
Parent string `json:"parent"`
|
||||
Thread string `json:"thread"`
|
||||
AuthorEmail string `json:"author_email"`
|
||||
AuthorName string `json:"autor_name"`
|
||||
IpAddress string `json:"ip_address"`
|
||||
Identifier string `json:"identifier"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
}
|
||||
|
||||
type PostResponse struct {
|
||||
Code int `json:"code"`
|
||||
Response struct {
|
||||
Id string `json:"id"`
|
||||
} `json:"response"`
|
||||
}
|
||||
|
||||
func PostComment(pc *PostCreate) string {
|
||||
if setting.Conf.Disqus.PostsList == "" || setting.Conf.Disqus.PublicKey == "" || setting.Conf.Disqus.ShortName == "" {
|
||||
return ""
|
||||
}
|
||||
url := setting.Conf.Disqus.PostCreate +
|
||||
"?api_key=E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F" +
|
||||
"&message=" + pc.Message + "&parent=" + pc.Parent +
|
||||
"&thread=" + pc.Thread + "&author_email=" + pc.AuthorEmail +
|
||||
"&author_name=" + pc.AuthorName
|
||||
|
||||
request, err := http.NewRequest("POST", url, nil)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return ""
|
||||
}
|
||||
request.Header.Set("Referer", "https://disqus.com")
|
||||
resp, err := http.DefaultClient.Do(request)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return ""
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return ""
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
logd.Error(string(b))
|
||||
return ""
|
||||
}
|
||||
pr := &PostResponse{}
|
||||
err = json.Unmarshal(b, pr)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return ""
|
||||
}
|
||||
logd.Print(pr.Response.Id)
|
||||
return pr.Response.Id
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDisqus(t *testing.T) {
|
||||
PostsCount()
|
||||
}
|
||||
|
||||
func TestPostComment(t *testing.T) {
|
||||
pc := &PostCreate{
|
||||
Message: "hahahaha",
|
||||
Thread: "52799014",
|
||||
AuthorEmail: "deepzz.qi@gmail.com",
|
||||
AuthorName: "deepzz",
|
||||
}
|
||||
|
||||
id := PostComment(pc)
|
||||
if id == "" {
|
||||
t.Error("post failed")
|
||||
return
|
||||
}
|
||||
t.Log("post success")
|
||||
}
|
||||
18
dist.sh
@@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# GOFLAGS='-ldflags="-s -w"'
|
||||
version=`git describe --tags`
|
||||
arch=$(go env GOARCH)
|
||||
|
||||
for os in linux darwin windows; do
|
||||
echo "... building $version for $os/$arch"
|
||||
TARGET="eiblog-$version.$os-$arch"
|
||||
GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build
|
||||
if [ "$os" == "windows" ]; then
|
||||
tar czvf $TARGET.tar.gz conf static views eiblog.exe
|
||||
rm eiblog.exe
|
||||
else
|
||||
tar czvf $TARGET.tar.gz conf static views eiblog
|
||||
rm eiblog
|
||||
fi
|
||||
done
|
||||
@@ -1,37 +1,35 @@
|
||||
version: '2'
|
||||
version: '3'
|
||||
services:
|
||||
mongodb:
|
||||
image: mongo:3.2
|
||||
container_name: eidb
|
||||
volumes:
|
||||
- /data/eiblog/mgodb:/data/db
|
||||
- ${PWD}/mgodb:/data/db
|
||||
restart: always
|
||||
elasticsearch:
|
||||
image: elasticsearch:2.4.1
|
||||
container_name: eisearch
|
||||
image: deepzz0/elasticsearch:2.4.1
|
||||
volumes:
|
||||
- /data/eiblog/conf/es/config:/usr/share/elasticsearch/config
|
||||
- /data/eiblog/conf/es/plugins:/usr/share/elasticsearch/plugins
|
||||
- /data/eiblog/esdata/data:/usr/share/elasticsearch/data
|
||||
- /data/eiblog/esdata/logs:/usr/share/elasticsearch/logs
|
||||
environment:
|
||||
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
|
||||
- ${PWD}/esdata:/usr/share/elasticsearch/data
|
||||
restart: always
|
||||
eiblog:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/deepzz/eiblog
|
||||
container_name: eiblog
|
||||
extra_hosts:
|
||||
- "disqus.com:23.235.33.134"
|
||||
iamge: deepzz0/eiblog:latest
|
||||
volumes:
|
||||
- /data/eiblog/logdata:/eiblog/logdata
|
||||
- /data/eiblog/conf:/eiblog/conf
|
||||
- /data/eiblog/static:/eiblog/static
|
||||
- /data/eiblog/views:/eiblog/views
|
||||
- ${PWD}/conf:/app/conf
|
||||
extra_hosts:
|
||||
- "disqus.com:151.101.192.134"
|
||||
- "deepzz.disqus.com:151.101.192.134"
|
||||
links:
|
||||
- elasticsearch
|
||||
- mongodb
|
||||
- elasticsearch
|
||||
- mongodb
|
||||
environment:
|
||||
- GODEBUG=netdns=cgo
|
||||
- GODEBUG=netdns=cgo
|
||||
- RUN_MODE=prod
|
||||
ports:
|
||||
- "9000:9000"
|
||||
- 127.0.0.1:9000:9000
|
||||
restart: always
|
||||
backup:
|
||||
image: deepzz0/backup:latest
|
||||
volumes:
|
||||
- ${PWD}/conf:/app/conf
|
||||
links:
|
||||
- mongodb
|
||||
restart: always
|
||||
|
||||
93
docs/README.md
Normal file
@@ -0,0 +1,93 @@
|
||||
# EiBlog [](https://travis-ci.org/eiblog/eiblog) [](LICENSE.md) [](https://github.com/eiblog/eiblog/releases)
|
||||
|
||||
> 博客项目结构参考模版:https://github.com/deepzz0/appdemo
|
||||
|
||||
EiBlog 镜像仓库地址:https://hub.docker.com/u/deepzz0
|
||||
|
||||
用过其它博客系统,不喜欢,不够轻,不够快!这是我开发的第二款博客系统,也实在不想再在这件事情上过多纠结了。`EiBlog` 是一个比较稳定的博客系统,现已迭代至 `2.0` 版本,稳定性和维护你是不用担心的。
|
||||
|
||||
但它有着部署简单(上线复杂!)的特点,不推荐没有计算机知识的朋友搭建,欢迎咨询。该博客的个中优点(简洁、轻快,安全),等你体验。
|
||||
|
||||
### 快速体验
|
||||
|
||||
1、下载程序压缩包:到 [这里](https://github.com/eiblog/eiblog/releases) 下载 eiblog 相应系统压缩包,然后解压缩。
|
||||
|
||||
2、启动数据库服务:博客支持多种数据库后端,如MongoDB、MySQL、Postgres、SQLite等。
|
||||
|
||||
```
|
||||
# 修改 conf/app.yml 数据库连接配置
|
||||
# driver可选:mongodb、mysql、postgres、sqlite、sqlserver、clickhouse、redis等
|
||||
# source为相应的连接地址
|
||||
database:
|
||||
driver: postgres
|
||||
source: host=localhost port=5432 user=postgres dbname=eiblog sslmode=disable password=MTI3LjAuMC4x
|
||||
```
|
||||
|
||||
3、启动 ES 搜索服务:博客使用 ElasticSearch 2.4.1 做为搜索引擎。
|
||||
|
||||
```
|
||||
# 修改 conf/app.yml ElasticSearch连接配置
|
||||
# 如果不启用搜索功能可以置空
|
||||
eshost: http://localhost:9200
|
||||
```
|
||||
|
||||
4、启动博客程序。
|
||||
|
||||
```
|
||||
./backend
|
||||
```
|
||||
|
||||
然后访问 `localhost:9000` 就可以了。
|
||||
|
||||
### 功能特性
|
||||
|
||||
本着博客本质用来分享知识的特点,`EiBlog` 不会有较强的定制功能(包括主题,CDN支持等),仅保持常用简单页面与功能:
|
||||
|
||||
```
|
||||
首页、专题、归档、友链、关于、搜索
|
||||
```
|
||||
|
||||
功能说明:
|
||||
|
||||
- [x] 博客归档,利用时间线帮助我们将归纳博文,内容少于一年按月归档,大于则按年归档。
|
||||
- [x] 博客专题,有时候博文是同一系列,专题能够帮助我们很好归纳博文,对阅读者是非常友好的。
|
||||
- [x] 标签系统,每篇博文都可以打上不同标签,使得在归档和专题不满足的情况下自定义归档,这块辅助搜索简直完美。
|
||||
- [x] 搜索系统,依托ElasticSearch实现的站内搜索,速度与效率并存,再加上google opensearch,搜索只流畅。
|
||||
- [x] 管理后台,内嵌全功能 `Typecho` 后台系统,全功能 `Markdown` 编辑器让你感觉什么是简洁清爽。
|
||||
- [x] 谷歌统计,由于google api的速度问题,从而实现了后端API异步统计,使得博客页面加载飞速。
|
||||
- [x] Disqus评论,国内评论系统不友好,因此选择disqus,又由于众所周知原因国内不能用,实现另类disqus评论方式。
|
||||
- [x] 多存储后端,支持mongodb、mysql、postgres、sqlite等存储后端。
|
||||
- [x] 七牛CDN,支持在 `Markdown` 编辑器直接上传附件,让你只考虑编辑内容,解放思想。
|
||||
- [x] 自动备份,支持多存储后端的备份功能,备份数据保存到七牛CDN上。
|
||||
|
||||
当然,为了让整个系统加载速度更快,还做了更多优化措施:
|
||||
|
||||
* 文章评论数量(不重要)通过后端跑定时任务获取,所以有时评论数量是不对的,这样减少了 API 调用。
|
||||
* 整站内容全部内存缓存,`mardown` 文档全部转换为 html 进行缓存,减少了转换过程。
|
||||
* `.js`、`.css` 等静态文件浏览器本地存储,小图片 base64 内置到 css 中,二次访问不会产生网络带来的延迟,加速访问。通过版本控制更新。
|
||||
* 最佳实践 nginx 配置,可以查看 `eiblog.conf`,开启压缩缩小传输量,服务器传输证书链、开启 `Session Resumption`、`Session Ticket`、`OCSP Stapling `等加速证书握手,再次提高速度。
|
||||
|
||||
### 博客页面
|
||||
|
||||
可以容易的看到 [httpsecurityreport](https://httpsecurityreport.com/?report=deepzz.com) 评分`96`,[ssllabs](https://www.ssllabs.com/ssltest/analyze.html?d=deepzz.com&latest) 评分`A+`,[myssl](https://myssl.com/deepzz.com) 评分`A+`,堪称完美。这些安全的相关配置会在后面的部署过程中接触到。
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||
|
||||
### 更多文档
|
||||
|
||||
* [安装部署](https://eiblog.github.io/eiblog/install)
|
||||
* [写作须知](https://eiblog.github.io/eiblog/writing)
|
||||
* [好玩功能](https://eiblog.github.io/eiblog/amusing)
|
||||
* [如何备份](https://eiblog.github.io/eiblog/backup)
|
||||
|
||||
### 贡献成员
|
||||
|
||||

|
||||
|
||||
### 授权许可
|
||||
|
||||
本项目采用 MIT 开源授权许可证,完整的授权说明已放置在 [LICENSE](https://github.com/eiblog/eiblog/blob/master/LICENSE) 文件中。
|
||||
|
||||
1
docs/_config.yml
Normal file
@@ -0,0 +1 @@
|
||||
theme: jekyll-theme-cayman
|
||||
25
docs/amusing.md
Normal file
@@ -0,0 +1,25 @@
|
||||
### Twitter Card
|
||||
相信很多人不明白为什么会这样专注 twitter。首先 twitter 是一个社交网站,国际性的。其次我们可以使用它的Twitter Card 功能非常的酷。
|
||||
|
||||
当你配置好 Twitter 相关的参数后`conf/app.yml`:
|
||||
```
|
||||
# twitter地址: twitter.com/chenqijing2
|
||||
twitter:
|
||||
card: summary
|
||||
site: chenqijing2
|
||||
image: st.deepzz.com/static/img/avatar.jpg
|
||||
address: twitter.com/chenqijing2
|
||||
```
|
||||
|
||||
每当你发部一个推文,你如果带上你的网址,它会自动给你展示成卡片的形式
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
可以看到`,`之前是没有内容的,该内容是我们文章的描述。
|
||||
|
||||
### Google OpenSearch
|
||||
在 Chrome 浏览器上,你可以在输入网站后按 TAB 键进入搜索模式,如:
|
||||
|
||||

|
||||
42
docs/backup.md
Normal file
@@ -0,0 +1,42 @@
|
||||
### 备份数据
|
||||
|
||||
EiBlog 镜像仓库地址:https://hub.docker.com/u/deepzz0,备份镜像为:deepzz0/backup。
|
||||
|
||||
|
||||
|
||||
目前仅支持同步 mongodb 数据到七牛云,参考 `app.yml`:
|
||||
|
||||
```
|
||||
backupapp:
|
||||
mode:
|
||||
name: cmd-backup
|
||||
enablehttp: true
|
||||
httpport: 9001
|
||||
backupto: qiniu # 备份到七牛云
|
||||
interval: 7d # 多久备份一次
|
||||
validity: 60d # 保存时长
|
||||
qiniu: # 七牛OSS
|
||||
bucket: backup
|
||||
domain: st.deepzz.com
|
||||
accesskey: MB6AXl_Sj_mmFsL-Lt59Dml2Vmy2o8XMmiCbbSeC
|
||||
secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 运行
|
||||
|
||||
1、获取备份镜像:
|
||||
|
||||
```
|
||||
$ docker pull deepzz0/backup
|
||||
```
|
||||
|
||||
2、启动备份镜像:
|
||||
|
||||
```
|
||||
$ docker run --name backup \
|
||||
-v ${PWD}/conf:/app/conf
|
||||
```
|
||||
|
||||
Docker-compose 请参考项目根目录下的 `docker-compose.yml` 文件。
|
||||
132
docs/install.md
Normal file
@@ -0,0 +1,132 @@
|
||||
这里只介绍通过 docker 进行安装部署的方式,二进制安装也可参考。
|
||||
|
||||
* [存储后端](#存储后端)
|
||||
* [搜索引擎](#搜索引擎)
|
||||
* [准备工作](#准备工作)
|
||||
* [开始部署](#开始部署)
|
||||
|
||||
博主提供了下面将要用到的镜像,可到这里查看:[https://hub.docker.com/u/deepzz0](https://hub.docker.com/u/deepzz0)。由于所有配置均在 `app/conf.yml` 下,所以在通过 docker 部署时建议将配置映射出来方便调试。
|
||||
|
||||
### 存储后端
|
||||
|
||||
首先启动我们的存储后端,用来存储我们的博客数据。eiblog 目前支持多种存储后端:
|
||||
|
||||
```
|
||||
# driver # source
|
||||
mongodb mongodb://localhost:27017
|
||||
postgres host=localhost port=5432 user=user dbname=eiblog sslmode=disable password=password
|
||||
mysql user:password@tcp(127.0.0.1:3306)/eiblog?charset=utf8mb4&parseTime=True&loc=Local
|
||||
sqlite /path/eiblog.db
|
||||
sqlserver sqlserver://user:password@localhost:9930?database=eiblog
|
||||
clickhouse tcp://localhost:9000?database=eiblog&username=user&password=password&read_timeout=10&write_timeout=20
|
||||
```
|
||||
|
||||
选择自己最熟悉的方式作为存储后端,然后修改 `conf/app.yml` 下的数据库地址:
|
||||
|
||||
```
|
||||
database:
|
||||
driver: postgres
|
||||
source: host=localhost port=5432 user=postgres dbname=eiblog sslmode=disable password=MTI3LjAuMC4x
|
||||
```
|
||||
|
||||
### 搜索引擎
|
||||
|
||||
博客强依赖 ElasticSearch 搜索引擎,如果仅调试可以跳过不部署。但对外提供服务强烈建议部署上 ES,这样可以提高体验感。博主提供了一个已经配置好的 docker 镜像:`deepzz0/elasticsearch`:
|
||||
|
||||
```
|
||||
# 运行
|
||||
$ docker run --name es \
|
||||
-p 9200:9200 \
|
||||
deepzz0/elasticsearch:2.4.1
|
||||
```
|
||||
|
||||
修改 `conf/app.yml` 下的 `eshost` 配置:
|
||||
|
||||
```
|
||||
# 如果不提供搜索,请置空
|
||||
eshost: http://localhost:9200
|
||||
```
|
||||
|
||||
### 准备工作
|
||||
|
||||
整个博客部署的复杂点就在这里了,如果你真的想要一款不想再更换的博客,那么继续。
|
||||
|
||||
#### 提前准备
|
||||
|
||||
请提前准备好以下内容,方便后续工作:
|
||||
|
||||
* `一台服务器`,对外提供访问能力。
|
||||
* `一个域名`,如果服务器在国内域名需要备案(免费域名不建议)。
|
||||
* `SSL证书`,博客要求全站 HTTPS 访问 + 七牛 CDN。
|
||||
* `Disqus评论`,作为博客评论系统,如果申请请自行 Google。简单说需要提供 `shortname` 和 `public key`。
|
||||
* `Google Analystic`,数据统计分析工具。
|
||||
* `Superfeedr`,加速 RSS 订阅。
|
||||
* `Twitter账号`,希望你能有一个 twitter 账号。
|
||||
|
||||
要求很多吧。其实当初该博客系统只是为个人而设计的,是自己心中想要的那一款。博主些这篇文章不是想要多少人来用该博客,而是希望对那些追求至极的朋友说:你需要这款博客系统。
|
||||
|
||||
#### 文件准备
|
||||
|
||||
博主是一个有强迫症的人,一些文件的路径我使用了固定的路径,请大家见谅。假如你的 cdn 域名为 `st.example.com`,你需要确定这些文件已经在你的 cdn 中,它们路径分别是:
|
||||
|
||||
| 文件 | 地址 | 描述 |
|
||||
| ------------------ | -------------------------------------------- | ------------------------------------------------------------ |
|
||||
| favicon.ico | st.example.com/static/img/favicon.ico | cdn 名为 `static/img/favicon.ico`。你也可以在代理服务器自行配置,只要通过 example.com/favicon.ico 也是能够访问到。 |
|
||||
| bg04.jpg | st.example.com/static/img/bg04.jpg | cdn 名为 `static/img/bg04.jpg`,首页左侧的大背景图,需要更名请到 website/st_blog.css 修改。 |
|
||||
| avatar.png | st.example.com/static/img/avatar.png | cdn 名为 `static/img/avatar.png`,个人博客头像 |
|
||||
| blank.gif | st.example.com/static/img/blank.gif | cdn 名为 `static/img/blank.gif`,空白图片,复制链接下载 https://st.deepzz.com/static/img/blank.gif。 |
|
||||
| default_avatar.png | st.example.com/static/img/default_avatar.png | cdn 名为 `static/img/default_avatar.png`,disqus 默认头像图片,复制链接下载 https://st.deepzz.com/static/img/default_avatar.png |
|
||||
|
||||
> 注意:
|
||||
>
|
||||
> 1. cdn 提到的文件下载,请复制链接进行下载,因为博主使用了防盗链功能。
|
||||
> 2. 每次修改 app.yml 文件(如:更换 cdn 域名或更新头像),如果你不知道是否应该提高 staticversion 一个版本,那么最好提高一个 +1。
|
||||
> 3. 每次手动修改 website 内的以 `st_` 开头的文件,请将 `app.yml` 中的 staticversion 提高一个版本。
|
||||
|
||||
#### 配置说明
|
||||
|
||||
走到这里,我相信只走到 `80%` 的路程。放弃还来得及。这里会对 `eiblog/conf` 下的所有文件做说明,希望你做好准备。
|
||||
|
||||
具体的配置内容已经在 `app.yml` 中进行说明了。
|
||||
|
||||
如果用 nginx 作为代理服务器,博主提供了一份示例配置 `eiblog/eiblog.conf`,该配置涉及到 `ssl` 相关配置建议存放于 `/etc/nginx/ssl` 下。其中关于 `ssl_dhparam`、站点认证均提供了相关配置。
|
||||
|
||||
### 开始部署
|
||||
|
||||
下面是博主通过 `docker-compose` 一键部署的文件内容,仅供参考:
|
||||
|
||||
```
|
||||
version: '3'
|
||||
services:
|
||||
mongodb:
|
||||
image: mongo:3.2
|
||||
volumes:
|
||||
- ${PWD}/mgodb:/data/db
|
||||
restart: always
|
||||
elasticsearch:
|
||||
image: deepzz0/elasticsearch:2.4.1
|
||||
volumes:
|
||||
- ${PWD}/esdata:/usr/share/elasticsearch/data
|
||||
restart: always
|
||||
eiblog:
|
||||
iamge: deepzz0/eiblog:latest
|
||||
volumes:
|
||||
- ${PWD}/conf:/app/conf
|
||||
extra_hosts:
|
||||
- "disqus.com:151.101.192.134"
|
||||
links:
|
||||
- elasticsearch
|
||||
- mongodb
|
||||
ports:
|
||||
- 9000:9000
|
||||
restart: always
|
||||
backup:
|
||||
image: deepzz0/backup:latest
|
||||
volumes:
|
||||
- ${PWD}/conf:/app/conf
|
||||
links:
|
||||
- mongodb
|
||||
restart: always
|
||||
```
|
||||
|
||||
当启动成功之后,后续的代理配置请参考 `eiblog/eiblog.conf`。
|
||||
75
docs/writing.md
Normal file
@@ -0,0 +1,75 @@
|
||||
### 郑重提醒
|
||||
**标题**、**slug**、**内容**。在你点击保存的时候一定确保三者不能为空,否则页面刷新内容就没了。所以,养成一个良好的写作习惯很重要。
|
||||
|
||||
当然,博客的自动保存功能也非常的好。在你不确定是否发布前,你可以将之保存到草稿,以便下次继续编辑。
|
||||
|
||||
### 文章标题
|
||||
文章标题,这个可能要看个人习惯。我习惯从三级标题开始(###),依次往下四级标题,五级标题...。要注意的是一定不能跳级:
|
||||
```
|
||||
### 标题一
|
||||
|
||||
#### 标题1.1
|
||||
#### 标题1.2
|
||||
##### 标题1.2.1
|
||||
##### 标题1.2.2
|
||||
|
||||
### 标题二
|
||||
|
||||
##### 标题2.1
|
||||
|
||||
##### 标题2.2
|
||||
###### 标题2.2.1
|
||||
###### 标题2.2.2
|
||||
```
|
||||
|
||||
结果是:
|
||||
|
||||

|
||||
|
||||
### 文章描述
|
||||
文章描述,主要是给`html->head->meta`中的 name 为 description 用的。现采用了一个临时的办法:在文章的第一行通过前缀识别(只看第一行)。
|
||||
|
||||
该前缀可到`conf/app.yml`设置,默认为`Desc:`,如:
|
||||
|
||||

|
||||
|
||||
### 图片懒加载
|
||||
博客系统提供图片懒加载功能(浏览到某个位置,图片才会加载),以此来提高页面加载速度。我们可根据需要是否使用。当然由此带来的坏处就是rss不能够正确加载图片。后续看是否解决这个问题或朋友提PR。
|
||||
|
||||
首先看下图片的`markdown`标准写法:
|
||||
```
|
||||

|
||||
```
|
||||
如:
|
||||
```
|
||||

|
||||
```
|
||||

|
||||
|
||||
懒加载,需要为该图片指定大小(长高):
|
||||
```
|
||||

|
||||
```
|
||||
|
||||
x 为小写字母(x,y,z)中的 x。使页面未加载时也占了相应的位置大小,这样设计是为了让读者在浏览页面时不会感到抖动。
|
||||
|
||||
如:
|
||||
```
|
||||

|
||||
```
|
||||
|
||||
### 摘要截取
|
||||
摘要截取主要是提供给首页显示,如:
|
||||
|
||||

|
||||
|
||||
红框中圈出来的就是截取出来的内容。在 `conf/app.yml` 的配置项有两个:
|
||||
|
||||
```
|
||||
# 自动截取预览, 字符数
|
||||
length: 400
|
||||
# 截取预览标识
|
||||
identifier: <!--more-->
|
||||
```
|
||||
当程序不能检查到 identifier 的标识符时,会采用长度的方式进行截取。
|
||||
|
||||
107
eiblog.conf
Normal file
@@ -0,0 +1,107 @@
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
|
||||
# gzip
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_comp_level 6;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_min_length 1000;
|
||||
gzip_proxied any;
|
||||
gzip_disable "msie6";
|
||||
gzip_http_version 1.0;
|
||||
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
|
||||
|
||||
server {
|
||||
server_name www.deepzz.com deepzz.com;
|
||||
server_tokens off;
|
||||
|
||||
location / {
|
||||
rewrite ^/(.*)$ https://$host/$1 permanent;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2 fastopen=3 reuseport;
|
||||
server_name www.deepzz.com deepzz.com;
|
||||
server_tokens off;
|
||||
|
||||
# 站点证书 + 中间证书, 私钥.
|
||||
ssl_certificate /etc/nginx/ssl/domain.rsa.pem;
|
||||
ssl_certificate_key /etc/nginx/ssl/domain.rsa.key;
|
||||
# ssl_certificate /etc/nginx/ssl/domain.ecc.pem;
|
||||
# ssl_certificate_key /etc/nginx/ssl/domain.ecc.key;
|
||||
# https://github.com/cloudflare/sslconfig/blob/master/conf
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
|
||||
# 如果启用 RSA+ECDSA 双证书, Cipher Suite 可以参考以下配置.
|
||||
# ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
|
||||
|
||||
# openssl dhparam -out dhparams.pem 2048
|
||||
# https://weakdh.org/sysadmin.html
|
||||
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
|
||||
|
||||
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
|
||||
ssl_session_cache shared:SSL:50m;
|
||||
ssl_session_timeout 1d;
|
||||
ssl_session_tickets on;
|
||||
|
||||
# 中间证书 + 根证书.
|
||||
# OCSP装订: https://imququ.com/post/why-can-not-turn-on-ocsp-stapling.html
|
||||
ssl_trusted_certificate /etc/nginx/ssl/full_chained.pem;
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
|
||||
if ($request_method !~ ^(GET|HEAD|POST|PUT|OPTIONS)$ ) {
|
||||
return 444;
|
||||
}
|
||||
|
||||
# webmaster 站点验证相关.
|
||||
location ~* (favicon\.ico|google4c90d18e696bdcf8\.html|BingSiteAuth\.xml|ads\.txt)$ {
|
||||
root /usr/share/nginx/html;
|
||||
expires 1d;
|
||||
}
|
||||
|
||||
# proxy setting
|
||||
proxy_http_version 1.1;
|
||||
|
||||
proxy_ignore_headers Set-Cookie;
|
||||
proxy_hide_header Vary;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
location ^~ /admin/ {
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
||||
# https://imququ.com/post/web-security-and-response-header.html#toc-1
|
||||
# 期望CT: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT
|
||||
add_header Expect-CT "max-age=180";
|
||||
add_header Cache-Control no-cache;
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header X-Via Aliyun.QingDao;
|
||||
add_header X-Powered-By eiblog/2.x;
|
||||
|
||||
proxy_pass http://127.0.0.1:9000;
|
||||
}
|
||||
|
||||
location / {
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
||||
# https://imququ.com/post/web-security-and-response-header.html#toc-1
|
||||
# 期望CT: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT
|
||||
add_header Expect-CT "max-age=180";
|
||||
add_header Cache-Control no-cache;
|
||||
# 内容安全策略: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
|
||||
add_header Content-Security-Policy "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' blob: https:; img-src data: https:; media-src https:; style-src 'unsafe-inline' https:; child-src https:; connect-src 'self'; frame-src https://disqus.com";
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header X-Via Aliyun.QingDao;
|
||||
add_header X-Powered-By eiblog/2.x;
|
||||
|
||||
proxy_pass http://127.0.0.1:9000;
|
||||
}
|
||||
}
|
||||
|
||||
287
elasticsearch.go
@@ -1,287 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/setting"
|
||||
"github.com/eiblog/utils/logd"
|
||||
)
|
||||
|
||||
const (
|
||||
INDEX = "eiblog"
|
||||
TYPE = "article"
|
||||
|
||||
ES_FILTER = `"filter":{"bool":{"must":[%s]}}`
|
||||
ES_TERM = `{"term":{"%s":"%s"}}`
|
||||
ES_DATE = `{"range":{"date":{"gte":"%s","lte": "%s","format": "yyyy-MM-dd||yyyy-MM||yyyy"}}}` // 2016-10||/M
|
||||
)
|
||||
|
||||
var es *ElasticService
|
||||
|
||||
func init() {
|
||||
es = &ElasticService{url: setting.Conf.SearchURL, c: new(http.Client)}
|
||||
initIndex()
|
||||
}
|
||||
|
||||
func initIndex() {
|
||||
mappings := fmt.Sprintf(`{"mappings":{"%s":{"properties":{"content":{"analyzer":"ik_syno","search_analyzer":"ik_syno","term_vector":"with_positions_offsets","type":"string"},"date":{"index":"not_analyzed","type":"date"},"slug":{"type":"string"},"tag":{"index":"not_analyzed","type":"string"},"title":{"analyzer":"ik_syno","search_analyzer":"ik_syno","term_vector":"with_positions_offsets","type":"string"}}}}}`, TYPE)
|
||||
err := CreateIndexAndMappings(INDEX, TYPE, []byte(mappings))
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Elasticsearch(qStr string, size, from int) *ESSearchResult {
|
||||
// 分析查询字符串
|
||||
reg := regexp.MustCompile(`(tag|slug|date):`)
|
||||
indexs := reg.FindAllStringIndex(qStr, -1)
|
||||
length := len(indexs)
|
||||
var str, kw string
|
||||
var filter []string
|
||||
if length == 0 { // 全文搜索
|
||||
kw = qStr
|
||||
}
|
||||
// 字段搜索,检出 全文搜索
|
||||
for i, index := range indexs {
|
||||
if i == length-1 {
|
||||
str = qStr[index[0]:]
|
||||
if space := strings.Index(str, " "); space != -1 && space < len(str)-1 {
|
||||
kw = str[space+1:]
|
||||
str = str[:space]
|
||||
}
|
||||
} else {
|
||||
str = strings.TrimSpace(qStr[index[0]:indexs[i+1][0]])
|
||||
}
|
||||
kv := strings.Split(str, ":")
|
||||
switch kv[0] {
|
||||
case "slug":
|
||||
filter = append(filter, fmt.Sprintf(ES_TERM, kv[0], kv[1]))
|
||||
case "tag":
|
||||
filter = append(filter, fmt.Sprintf(ES_TERM, kv[0], kv[1]))
|
||||
case "date":
|
||||
var date string
|
||||
switch len(kv[1]) {
|
||||
case 4:
|
||||
date = fmt.Sprintf(ES_DATE, kv[1], kv[1]+"||/y")
|
||||
case 7:
|
||||
date = fmt.Sprintf(ES_DATE, kv[1], kv[1]+"||/M")
|
||||
case 10:
|
||||
date = fmt.Sprintf(ES_DATE, kv[1], kv[1]+"||/d")
|
||||
default:
|
||||
break
|
||||
}
|
||||
filter = append(filter, date)
|
||||
}
|
||||
}
|
||||
// 判断是否为空,选择搜索方式
|
||||
var dsl string
|
||||
if kw != "" {
|
||||
dsl = strings.Replace(strings.Replace(`{"highlight":{"fields":{"content":{},"title":{}},"post_tags":["\u003c/b\u003e"],"pre_tags":["\u003cb\u003e"]},"query":{"dis_max":{"queries":[{"match":{"title":{"boost":4,"minimum_should_match":"50%","query":"$1"}}},{"match":{"content":{"boost":4,"minimum_should_match":"75%","query":"$1"}}},{"match":{"tag":{"boost":2,"minimum_should_match":"100%","query":"$1"}}},{"match":{"slug":{"boost":1,"minimum_should_match":"100%","query":"$1"}}}],"tie_breaker":0.3}},$2}`, "$1", kw, -1), "$2", fmt.Sprintf(ES_FILTER, strings.Join(filter, ",")), -1)
|
||||
} else {
|
||||
dsl = fmt.Sprintf("{"+ES_FILTER+"}", strings.Join(filter, ","))
|
||||
}
|
||||
docs, err := IndexQueryDSL(INDEX, TYPE, size, from, []byte(dsl))
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return nil
|
||||
}
|
||||
return docs
|
||||
}
|
||||
|
||||
func ElasticIndex(artc *Article) error {
|
||||
img := PickFirstImage(artc.Content)
|
||||
mapping := map[string]interface{}{
|
||||
"title": artc.Title,
|
||||
"content": IgnoreHtmlTag(artc.Content),
|
||||
"slug": artc.Slug,
|
||||
"tag": artc.Tags,
|
||||
"img": img,
|
||||
"date": artc.CreateTime,
|
||||
}
|
||||
b, _ := json.Marshal(mapping)
|
||||
return IndexOrUpdateDocument(INDEX, TYPE, artc.ID, b)
|
||||
}
|
||||
|
||||
func ElasticDelIndex(ids []int32) error {
|
||||
var target []string
|
||||
for _, id := range ids {
|
||||
target = append(target, fmt.Sprint(id))
|
||||
}
|
||||
return DeleteDocument(INDEX, TYPE, target)
|
||||
}
|
||||
|
||||
///////////////////////////// Elasticsearch api /////////////////////////////
|
||||
type ElasticService struct {
|
||||
c *http.Client
|
||||
url string
|
||||
}
|
||||
|
||||
type IndicesCreateResult struct {
|
||||
Acknowledged bool `json:"acknowledged"`
|
||||
}
|
||||
|
||||
func (s *ElasticService) ParseURL(format string, params ...interface{}) string {
|
||||
return fmt.Sprintf(s.url+format, params...)
|
||||
}
|
||||
|
||||
func (s *ElasticService) Do(req *http.Request) (interface{}, error) {
|
||||
resp, err := s.c.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
switch req.Method {
|
||||
case "POST":
|
||||
fallthrough
|
||||
case "DELETE":
|
||||
fallthrough
|
||||
case "PUT":
|
||||
fallthrough
|
||||
case "GET":
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b, nil
|
||||
case "HEAD":
|
||||
return resp.StatusCode, nil
|
||||
|
||||
default:
|
||||
return nil, errors.New("unknown methods")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func CreateIndexAndMappings(index, typ string, mappings []byte) (err error) {
|
||||
req, err := http.NewRequest("HEAD", es.ParseURL("/%s/%s", index, typ), nil)
|
||||
code, err := es.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if code.(int) == http.StatusOK {
|
||||
return nil
|
||||
}
|
||||
req, err = http.NewRequest("PUT", es.ParseURL("/%s", index), bytes.NewReader(mappings))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := es.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var rst IndicesCreateResult
|
||||
err = json.Unmarshal(data.([]byte), &rst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !rst.Acknowledged {
|
||||
return errors.New(string(data.([]byte)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func IndexOrUpdateDocument(index, typ string, id int32, doc []byte) (err error) {
|
||||
req, err := http.NewRequest("PUT", es.ParseURL("/%s/%s/%d", index, typ, id), bytes.NewReader(doc))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := es.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logd.Debug(string(data.([]byte)))
|
||||
return nil
|
||||
}
|
||||
|
||||
type ESDeleteDocument struct {
|
||||
Index string `json:"_index"`
|
||||
Type string `json:"_type"`
|
||||
ID string `json:"_id"`
|
||||
}
|
||||
|
||||
type ESDeleteResult struct {
|
||||
Errors bool `json:"errors"`
|
||||
Iterms []map[string]struct {
|
||||
Error string `json:"error"`
|
||||
} `json:"iterms"`
|
||||
}
|
||||
|
||||
func DeleteDocument(index, typ string, ids []string) error {
|
||||
var buff bytes.Buffer
|
||||
for _, id := range ids {
|
||||
dd := &ESDeleteDocument{Index: index, Type: typ, ID: id}
|
||||
m := map[string]*ESDeleteDocument{"delete": dd}
|
||||
b, _ := json.Marshal(m)
|
||||
buff.Write(b)
|
||||
buff.WriteByte('\n')
|
||||
}
|
||||
req, err := http.NewRequest("POST", es.ParseURL("/_bulk"), bytes.NewReader(buff.Bytes()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := es.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var result ESDeleteResult
|
||||
err = json.Unmarshal(data.([]byte), &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.Errors {
|
||||
for _, iterm := range result.Iterms {
|
||||
for _, s := range iterm {
|
||||
if s.Error != "" {
|
||||
return errors.New(s.Error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ESSearchResult struct {
|
||||
Took float32 `json:"took"`
|
||||
Hits struct {
|
||||
Total int `json:"total"`
|
||||
Hits []struct {
|
||||
ID string `json:"_id"`
|
||||
Source struct {
|
||||
Slug string `json:"slug"`
|
||||
Content string `json:"content"`
|
||||
Date time.Time `json:"date"`
|
||||
Title string `json:"title"`
|
||||
Img string `json:"img"`
|
||||
} `json:"_source"`
|
||||
Highlight struct {
|
||||
Title []string `json:"title"`
|
||||
Content []string `json:"content"`
|
||||
} `json:"highlight"`
|
||||
} `json:"hits"`
|
||||
} `json:"hits"`
|
||||
}
|
||||
|
||||
func IndexQueryDSL(index, typ string, size, from int, dsl []byte) (*ESSearchResult, error) {
|
||||
req, err := http.NewRequest("POST", es.ParseURL("/%s/%s/_search?size=%d&from=%d", index, typ, size, from), bytes.NewReader(dsl))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data, err := es.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &ESSearchResult{}
|
||||
err = json.Unmarshal(data.([]byte), result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateIndexAndMappings(t *testing.T) {
|
||||
mapping := map[string]interface{}{
|
||||
"mappings": map[string]interface{}{
|
||||
"article": map[string]interface{}{
|
||||
"properties": map[string]interface{}{
|
||||
"title": map[string]string{
|
||||
"type": "string",
|
||||
"term_vector": "with_positions_offsets",
|
||||
"analyzer": "ik_syno",
|
||||
"search_analyzer": "ik_syno",
|
||||
},
|
||||
"content": map[string]string{
|
||||
"type": "string",
|
||||
"term_vector": "with_positions_offsets",
|
||||
"analyzer": "ik_syno",
|
||||
"search_analyzer": "ik_syno",
|
||||
},
|
||||
"slug": map[string]string{
|
||||
"type": "string",
|
||||
},
|
||||
"tags": map[string]string{
|
||||
"type": "string",
|
||||
"index": "not_analyzed",
|
||||
},
|
||||
"update_time": map[string]string{
|
||||
"type": "date",
|
||||
"index": "not_analyzed",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
b, _ := json.Marshal(mapping)
|
||||
err := CreateIndexAndMappings(INDEX, TYPE, b)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexDocument(t *testing.T) {
|
||||
mapping := map[string]interface{}{
|
||||
"title": "简单到不知道为什么",
|
||||
"content": `最近有很多朋友邮件或者留言询问本博客服务端配置相关问题,基本都是关于 HTTPS 和 HTTP/2 的,其实我的 Nginx 配置在之前的文章中多次提到过,不过都比较分散。为了方便大家参考,本文贴出完整配置。本文内容会随时调整或更新,请大家不要把本文内容全文转载到第三方平台,以免给他人造成困扰或误导。另外限于篇幅,本文不会对配置做过多说明,如有疑问或不同意见,欢迎留言指出。
|
||||
`,
|
||||
"slug": "vim3",
|
||||
"tags": []string{"js", "javascript", "test"},
|
||||
"update_time": "2015-12-15T13:05:55Z",
|
||||
}
|
||||
b, _ := json.Marshal(mapping)
|
||||
err := IndexOrUpdateDocument(INDEX, TYPE, int32(11), b)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexQueryDSL(t *testing.T) {
|
||||
kw := "实现访问限制"
|
||||
dsl := map[string]interface{}{
|
||||
"query": map[string]interface{}{
|
||||
"dis_max": map[string]interface{}{
|
||||
"queries": []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"match": map[string]interface{}{
|
||||
"title": map[string]interface{}{
|
||||
"query": kw,
|
||||
"minimum_should_match": "50%",
|
||||
"boost": 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"match": map[string]interface{}{
|
||||
"content": map[string]interface{}{
|
||||
"query": kw,
|
||||
"minimum_should_match": "75%",
|
||||
"boost": 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"match": map[string]interface{}{
|
||||
"tags": map[string]interface{}{
|
||||
"query": kw,
|
||||
"minimum_should_match": "100%",
|
||||
"boost": 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"match": map[string]interface{}{
|
||||
"slug": map[string]interface{}{
|
||||
"query": kw,
|
||||
"minimum_should_match": "100%",
|
||||
"boost": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"tie_breaker": 0.3,
|
||||
},
|
||||
},
|
||||
"highlight": map[string]interface{}{
|
||||
"pre_tags": []string{"<b>"},
|
||||
"post_tags": []string{"</b>"},
|
||||
"fields": map[string]interface{}{
|
||||
"title": map[string]string{},
|
||||
"content": map[string]string{
|
||||
// "fragment_size": 150,
|
||||
// "number_of_fragments": "3",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
b, _ := json.Marshal(dsl)
|
||||
fmt.Println(string(b))
|
||||
_, err := IndexQueryDSL(INDEX, TYPE, 10, 1, b)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
367
front.go
@@ -1,367 +0,0 @@
|
||||
// Package main provides ...
|
||||
// 这里是前端页面展示相关接口
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/setting"
|
||||
"github.com/eiblog/utils/logd"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Filter() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 过滤黑名单
|
||||
BlackFilter(c)
|
||||
// 用户cookie,用于统计
|
||||
UserCookie(c)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// 用户识别
|
||||
func UserCookie(c *gin.Context) {
|
||||
cookie, err := c.Cookie("u")
|
||||
if err != nil || cookie == "" {
|
||||
c.SetCookie("u", RandUUIDv4(), 86400*730, "/", "", true, true)
|
||||
}
|
||||
}
|
||||
|
||||
// 黑名单过滤
|
||||
func BlackFilter(c *gin.Context) {
|
||||
ip := c.ClientIP()
|
||||
if setting.BlackIP[ip] {
|
||||
c.Abort()
|
||||
c.String(http.StatusForbidden, "Your IP is blacklisted.")
|
||||
}
|
||||
}
|
||||
|
||||
// 解析静态文件版本
|
||||
func StaticVersion(c *gin.Context) (version int) {
|
||||
cookie, err := c.Request.Cookie("v")
|
||||
if err != nil || cookie.Value != fmt.Sprint(setting.Conf.StaticVersion) {
|
||||
return setting.Conf.StaticVersion
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func GetBase() gin.H {
|
||||
return gin.H{
|
||||
"Favicon": setting.Conf.Favicon,
|
||||
"BlogName": Ei.BlogName,
|
||||
"SubTitle": Ei.SubTitle,
|
||||
"Twitter": setting.Conf.Twitter,
|
||||
"CopyYear": time.Now().Year(),
|
||||
"BTitle": Ei.BTitle,
|
||||
"BeiAn": Ei.BeiAn,
|
||||
"Domain": setting.Conf.Mode.Domain,
|
||||
"Kodo": setting.Conf.Kodo,
|
||||
}
|
||||
}
|
||||
|
||||
func HandleNotFound(c *gin.Context) {
|
||||
h := GetBase()
|
||||
h["Version"] = StaticVersion(c)
|
||||
h["Title"] = "Not Found"
|
||||
h["Path"] = ""
|
||||
c.Status(http.StatusNotFound)
|
||||
RenderHTMLFront(c, "notfound", h)
|
||||
}
|
||||
|
||||
func HandleHomePage(c *gin.Context) {
|
||||
h := GetBase()
|
||||
h["Version"] = StaticVersion(c)
|
||||
h["Title"] = Ei.BTitle + " | " + Ei.SubTitle
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["CurrentPage"] = "blog-home"
|
||||
pn, err := strconv.Atoi(c.Query("pn"))
|
||||
if err != nil || pn < 1 {
|
||||
pn = 1
|
||||
}
|
||||
h["Prev"], h["Next"], h["List"] = PageList(pn, setting.Conf.PageNum)
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLFront(c, "home", h)
|
||||
}
|
||||
|
||||
func HandleSeriesPage(c *gin.Context) {
|
||||
h := GetBase()
|
||||
h["Version"] = StaticVersion(c)
|
||||
h["Title"] = "专题 | " + Ei.BTitle
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["CurrentPage"] = "series"
|
||||
h["Article"] = Ei.PageSeries
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLFront(c, "series", h)
|
||||
}
|
||||
|
||||
func HandleArchivesPage(c *gin.Context) {
|
||||
h := GetBase()
|
||||
h["Version"] = StaticVersion(c)
|
||||
h["Title"] = "归档 | " + Ei.BTitle
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["CurrentPage"] = "archives"
|
||||
h["Article"] = Ei.PageArchives
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLFront(c, "archives", h)
|
||||
}
|
||||
|
||||
func HandleArticlePage(c *gin.Context) {
|
||||
path := c.Param("slug")
|
||||
artc := Ei.MapArticles[path[0:strings.Index(path, ".")]]
|
||||
if artc == nil {
|
||||
HandleNotFound(c)
|
||||
return
|
||||
}
|
||||
h := GetBase()
|
||||
h["Version"] = StaticVersion(c)
|
||||
h["Title"] = artc.Title + " | " + Ei.BTitle
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["CurrentPage"] = "post-" + artc.Slug
|
||||
var name string
|
||||
if path == "blogroll.html" {
|
||||
name = "blogroll"
|
||||
} else if path == "about.html" {
|
||||
name = "about"
|
||||
} else {
|
||||
name = "article"
|
||||
h["Copyright"] = Ei.Copyright
|
||||
if !artc.UpdateTime.IsZero() {
|
||||
h["Days"] = int(time.Now().Sub(artc.UpdateTime).Hours()) / 24
|
||||
} else {
|
||||
h["Days"] = int(time.Now().Sub(artc.CreateTime).Hours()) / 24
|
||||
}
|
||||
if artc.SerieID > 0 {
|
||||
h["Serie"] = QuerySerie(artc.SerieID)
|
||||
}
|
||||
}
|
||||
h["Article"] = artc
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLFront(c, name, h)
|
||||
}
|
||||
|
||||
func HandleSearchPage(c *gin.Context) {
|
||||
h := GetBase()
|
||||
h["Version"] = StaticVersion(c)
|
||||
h["Title"] = "站内搜索 | " + Ei.BTitle
|
||||
h["Path"] = ""
|
||||
h["CurrentPage"] = "search-post"
|
||||
|
||||
q := strings.TrimSpace(c.Query("q"))
|
||||
if q != "" {
|
||||
start, err := strconv.Atoi(c.Query("start"))
|
||||
if start < 1 || err != nil {
|
||||
start = 1
|
||||
}
|
||||
h["Word"] = q
|
||||
var result *ESSearchResult
|
||||
vals := c.Request.URL.Query()
|
||||
result = Elasticsearch(q, setting.Conf.PageNum, start-1)
|
||||
if result != nil {
|
||||
result.Took /= 1000
|
||||
for i, v := range result.Hits.Hits {
|
||||
if artc := Ei.MapArticles[result.Hits.Hits[i].Source.Slug]; len(v.Highlight.Content) == 0 && artc != nil {
|
||||
result.Hits.Hits[i].Highlight.Content = []string{artc.Excerpt}
|
||||
}
|
||||
}
|
||||
h["SearchResult"] = result
|
||||
if start-setting.Conf.PageNum > 0 {
|
||||
vals.Set("start", fmt.Sprint(start-setting.Conf.PageNum))
|
||||
h["Prev"] = vals.Encode()
|
||||
}
|
||||
if result.Hits.Total >= start+setting.Conf.PageNum {
|
||||
vals.Set("start", fmt.Sprint(start+setting.Conf.PageNum))
|
||||
h["Next"] = vals.Encode()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
h["HotWords"] = setting.Conf.HotWords
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLFront(c, "search", h)
|
||||
}
|
||||
|
||||
func HandleDisqusFrom(c *gin.Context) {
|
||||
params := strings.Split(c.Param("slug"), "|")
|
||||
if len(params) != 4 || params[1] == "" {
|
||||
c.String(http.StatusOK, "出错啦。。。")
|
||||
return
|
||||
}
|
||||
artc := Ei.MapArticles[params[0]]
|
||||
data := gin.H{
|
||||
"Title": "发表评论 | " + Ei.BTitle,
|
||||
"ATitle": artc.Title,
|
||||
"Thread": params[1],
|
||||
}
|
||||
err := Tmpl.ExecuteTemplate(c.Writer, "disqus.html", data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
}
|
||||
|
||||
func HandleFeed(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, "static/feed.xml")
|
||||
}
|
||||
|
||||
func HandleOpenSearch(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, "static/opensearch.xml")
|
||||
}
|
||||
|
||||
func HandleRobots(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, "static/robots.txt")
|
||||
}
|
||||
|
||||
func HandleSitemap(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, "static/sitemap.xml")
|
||||
}
|
||||
|
||||
// 服务端推送谷歌统计
|
||||
func HandleBeacon(c *gin.Context) {
|
||||
ua := c.Request.UserAgent()
|
||||
// TODO 过滤黑名单
|
||||
vals := c.Request.URL.Query()
|
||||
vals.Set("v", setting.Conf.Google.V)
|
||||
vals.Set("tid", setting.Conf.Google.Tid)
|
||||
vals.Set("t", setting.Conf.Google.T)
|
||||
cookie, _ := c.Cookie("u")
|
||||
vals.Set("cid", cookie)
|
||||
|
||||
vals.Set("dl", c.Request.Referer())
|
||||
vals.Set("uip", c.ClientIP())
|
||||
go func() {
|
||||
req, err := http.NewRequest("POST", "https://www.google-analytics.com/collect", strings.NewReader(vals.Encode()))
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
}
|
||||
req.Header.Set("User-Agent", ua)
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
}
|
||||
if res.StatusCode/100 != 2 {
|
||||
logd.Error(string(data))
|
||||
}
|
||||
}()
|
||||
c.String(http.StatusNoContent, "accepted")
|
||||
}
|
||||
|
||||
// 服务端获取评论详细
|
||||
type DisqusComments struct {
|
||||
ErrNo int `json:"errno"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
Data struct {
|
||||
Next string `json:"next"`
|
||||
Total int `json:"total,omitempty"`
|
||||
Comments []commentsDetail `json:"comments"`
|
||||
Thread string `json:"thread"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type commentsDetail struct {
|
||||
Id string `json:"id"`
|
||||
Parent int `json:"parent"`
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
Avatar string `json:"avatar"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
CreatedAtStr string `json:"createdAtStr"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func HandleDisqus(c *gin.Context) {
|
||||
slug := c.Param("slug")
|
||||
cursor := c.Query("cursor")
|
||||
dcs := DisqusComments{}
|
||||
postsList := PostsList(slug, cursor)
|
||||
if postsList != nil {
|
||||
dcs.ErrNo = postsList.Code
|
||||
if postsList.Cursor.HasNext {
|
||||
dcs.Data.Next = postsList.Cursor.Next
|
||||
}
|
||||
dcs.Data.Total = len(postsList.Response)
|
||||
dcs.Data.Comments = make([]commentsDetail, len(postsList.Response))
|
||||
for i, v := range postsList.Response {
|
||||
if dcs.Data.Thread == "" {
|
||||
dcs.Data.Thread = v.Thread
|
||||
}
|
||||
dcs.Data.Comments[i] = commentsDetail{
|
||||
Id: v.Id,
|
||||
Name: v.Author.Name,
|
||||
Parent: v.Parent,
|
||||
Url: v.Author.ProfileUrl,
|
||||
Avatar: v.Author.Avatar.Cache,
|
||||
CreatedAt: v.CreatedAt,
|
||||
CreatedAtStr: ConvertStr(v.CreatedAt),
|
||||
Message: v.Message,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dcs.ErrNo = FAIL
|
||||
dcs.ErrMsg = "系统错误"
|
||||
}
|
||||
c.JSON(http.StatusOK, dcs)
|
||||
}
|
||||
|
||||
// [thread:[5279901489] parent:[] identifier:[post-troubleshooting-https] next:[] author_name:[你好] author_email:[chenqijing2@163.com] message:[fdsfdsf]]
|
||||
func HandleDisqusCreate(c *gin.Context) {
|
||||
rep := gin.H{"errno": SUCCESS, "errmsg": ""}
|
||||
defer c.JSON(http.StatusOK, rep)
|
||||
msg := c.PostForm("message")
|
||||
email := c.PostForm("author_email")
|
||||
name := c.PostForm("author_name")
|
||||
thread := c.PostForm("thread")
|
||||
identifier := c.PostForm("identifier")
|
||||
if msg == "" || email == "" || name == "" || thread == "" || identifier == "" {
|
||||
rep["errno"] = FAIL
|
||||
rep["errmsg"] = "参数错误"
|
||||
return
|
||||
}
|
||||
pc := &PostCreate{
|
||||
Message: msg,
|
||||
Parent: c.PostForm("parent"),
|
||||
Thread: thread,
|
||||
AuthorEmail: email,
|
||||
AuthorName: name,
|
||||
Identifier: identifier,
|
||||
IpAddress: c.ClientIP(),
|
||||
}
|
||||
|
||||
id := PostComment(pc)
|
||||
if id == "" {
|
||||
rep["errno"] = FAIL
|
||||
rep["errmsg"] = "系统错误"
|
||||
return
|
||||
}
|
||||
rep["errno"] = SUCCESS
|
||||
rep["data"] = gin.H{"id": id}
|
||||
}
|
||||
|
||||
func RenderHTMLFront(c *gin.Context, name string, data gin.H) {
|
||||
var buf bytes.Buffer
|
||||
err := Tmpl.ExecuteTemplate(&buf, name, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data["LayoutContent"] = template.HTML(buf.String())
|
||||
err = Tmpl.ExecuteTemplate(c.Writer, "homeLayout.html", data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
}
|
||||
83
glide.lock
generated
@@ -1,83 +0,0 @@
|
||||
hash: 4b70e76a2e830e97033c06d0e5a90c3199985ff5070bdf8364b1feca63d5caa5
|
||||
updated: 2016-12-25T00:17:00.257473303+08:00
|
||||
imports:
|
||||
- name: github.com/boj/redistore
|
||||
version: fc113767cd6b051980f260d6dbe84b2740c46ab0
|
||||
- name: github.com/eiblog/blackfriday
|
||||
version: c0ec111761ae784fe31cc076f2fa0e2d2216d623
|
||||
- name: github.com/eiblog/utils
|
||||
version: ad2f63940c4f16d0dbfc3f4df59e8cb7af0f80ec
|
||||
subpackages:
|
||||
- logd
|
||||
- mgo
|
||||
- tmpl
|
||||
- uuid
|
||||
- name: github.com/garyburd/redigo
|
||||
version: f8c71fc158ba13d50a7f5d8f10ea18ec49463c73
|
||||
subpackages:
|
||||
- internal
|
||||
- redis
|
||||
- name: github.com/gin-gonic/contrib
|
||||
version: 7b9bbbaec78850441ed357ac702e474b26c08f9b
|
||||
subpackages:
|
||||
- sessions
|
||||
- name: github.com/gin-gonic/gin
|
||||
version: e2212d40c62a98b388a5eb48ecbdcf88534688ba
|
||||
subpackages:
|
||||
- binding
|
||||
- render
|
||||
- name: github.com/golang/protobuf
|
||||
version: 2402d76f3d41f928c7902a765dfc872356dd3aad
|
||||
subpackages:
|
||||
- proto
|
||||
- name: github.com/gorilla/context
|
||||
version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42
|
||||
- name: github.com/gorilla/securecookie
|
||||
version: fa5329f913702981df43dcb2a380bac429c810b5
|
||||
- name: github.com/gorilla/sessions
|
||||
version: 83c8db3bdc9be789e57e3756ffbcffd2d7d40176
|
||||
- name: github.com/manucorporat/sse
|
||||
version: ee05b128a739a0fb76c7ebd3ae4810c1de808d6d
|
||||
- name: github.com/mattn/go-isatty
|
||||
version: 30a891c33c7cde7b02a981314b4228ec99380cca
|
||||
- name: github.com/shurcooL/sanitized_anchor_name
|
||||
version: 1dba4b3954bc059efc3991ec364f9f9a35f597d2
|
||||
- name: golang.org/x/net
|
||||
version: f315505cf3349909cdf013ea56690da34e96a451
|
||||
subpackages:
|
||||
- context
|
||||
- name: golang.org/x/sys
|
||||
version: d75a52659825e75fff6158388dddc6a5b04f9ba5
|
||||
subpackages:
|
||||
- unix
|
||||
- name: gopkg.in/go-playground/validator.v8
|
||||
version: c193cecd124b5cc722d7ee5538e945bdb3348435
|
||||
- name: gopkg.in/mgo.v2
|
||||
version: 3f83fa5005286a7fe593b055f0d7771a7dce4655
|
||||
subpackages:
|
||||
- bson
|
||||
- internal/json
|
||||
- internal/sasl
|
||||
- internal/scram
|
||||
- name: gopkg.in/yaml.v2
|
||||
version: a5b47d31c556af34a302ce5d659e6fea44d90de0
|
||||
- name: qiniupkg.com/api.v7
|
||||
version: 7cfd4b639917bf924d8c1cd17a6d61175e809066
|
||||
subpackages:
|
||||
- api
|
||||
- auth/qbox
|
||||
- conf
|
||||
- kodo
|
||||
- kodocli
|
||||
- name: qiniupkg.com/x
|
||||
version: f512abcf45ab4e2ba0fd4784c57b53d495997d66
|
||||
subpackages:
|
||||
- bytes.v7
|
||||
- bytes.v7/seekable
|
||||
- ctype.v7
|
||||
- log.v7
|
||||
- reqid.v7
|
||||
- rpc.v7
|
||||
- url.v7
|
||||
- xlog.v7
|
||||
testImports: []
|
||||
16
glide.yaml
@@ -1,16 +0,0 @@
|
||||
package: github.com/eiblog/eiblog
|
||||
import:
|
||||
- package: github.com/eiblog/blackfriday
|
||||
- package: github.com/eiblog/utils
|
||||
subpackages:
|
||||
- logd
|
||||
- mgo
|
||||
- tmpl
|
||||
- package: github.com/gin-gonic/contrib
|
||||
subpackages:
|
||||
- sessions
|
||||
- package: github.com/gin-gonic/gin
|
||||
- package: gopkg.in/mgo.v2
|
||||
subpackages:
|
||||
- bson
|
||||
- package: gopkg.in/yaml.v2
|
||||