Compare commits
83 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
433064de00 | ||
|
|
9d71ca8198 | ||
|
|
7c938bf024 | ||
|
|
65fcc69efa | ||
|
|
d06bab72a5 | ||
|
|
95900eec1a | ||
|
|
dfae78891d | ||
|
|
c515e33e2c | ||
|
|
5b12dd625b | ||
|
|
9b918caccd | ||
|
|
2be53379e1 | ||
|
|
944e27c58a | ||
|
|
92baf970bc | ||
|
|
64a754167a | ||
|
|
af2a20c34a | ||
|
|
f28d0e77e0 | ||
|
|
9a1b4db61a | ||
|
|
c9d04aded3 | ||
|
|
ee51f678cb | ||
|
|
434c1bf168 | ||
|
|
d2de603957 | ||
|
|
e7fdf6b1db | ||
|
|
305ae0ee70 | ||
|
|
a5749fdab6 | ||
|
|
391f19e2a9 | ||
|
|
2c6c5bb977 | ||
|
|
860a85e209 | ||
|
|
2a8d9b3bbd | ||
|
|
1509a68cda | ||
|
|
7f26503247 | ||
|
|
235145ed46 | ||
|
|
20e89d6a76 | ||
|
|
d86ab71ad9 | ||
|
|
4600ed5094 | ||
|
|
5fcadd1c81 | ||
|
|
42b106d582 | ||
|
|
bb06be36fe | ||
|
|
cb3fb2d2e7 | ||
|
|
779a23cb75 | ||
|
|
e2fa96cd62 | ||
|
|
db26fb51e5 | ||
|
|
994be5d508 | ||
|
|
a5c3d33565 | ||
|
|
1ffc58eccf | ||
|
|
b6ad4e8949 | ||
|
|
41704917db | ||
|
|
f6ba716f55 | ||
|
|
b2e6c168c5 | ||
|
|
eca741896f | ||
|
|
17792e5a7e | ||
|
|
04289c633e | ||
|
|
3a5eb6fccc | ||
|
|
f6d8656c83 | ||
|
|
4690d5123b | ||
|
|
a9e8e39d34 | ||
|
|
c51055a0db | ||
|
|
445b188517 | ||
|
|
4bfff2e5e9 | ||
|
|
aa91997c0c | ||
|
|
3b2a6689be | ||
|
|
4c46be3f03 | ||
|
|
da47e9880f | ||
|
|
4f92e0d619 | ||
|
|
3a8f7d120b | ||
|
|
cf0a897ad0 | ||
|
|
418b604946 | ||
|
|
b93c320987 | ||
|
|
b24f7c0666 | ||
|
|
efe80fbc6b | ||
|
|
65b89bcae5 | ||
|
|
289b8145bc | ||
|
|
bf0ad811ff | ||
|
|
db00a9b527 | ||
|
|
38aa704198 | ||
|
|
9c58447e3b | ||
|
|
34fc5f368c | ||
|
|
daa561e67e | ||
|
|
364d293660 | ||
|
|
5170844623 | ||
|
|
7047a3599d | ||
|
|
d0c830c1e6 | ||
|
|
bf699e4957 | ||
|
|
c315737871 |
@@ -1,12 +1,12 @@
|
|||||||
# Ignore all files and dirs
|
# Ignore all files and dirs
|
||||||
*
|
|
||||||
|
|
||||||
# Unignore files or dirs
|
# Unignore files or dirs
|
||||||
!build
|
.github
|
||||||
!bin
|
bin
|
||||||
!conf
|
docs
|
||||||
!assets
|
.gitignore
|
||||||
!website
|
db.sqlite
|
||||||
!CHANGELOG.md
|
docker-compose.yml
|
||||||
!LICENSE
|
eiblog.conf
|
||||||
!README.md
|
Makefile
|
||||||
|
|||||||
12
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: eiblog
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||||
56
.github/workflows/release.yml
vendored
@@ -7,37 +7,49 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
package:
|
package:
|
||||||
runs-on: self-hosted
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Golang env
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: ^1.15
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Cache mod
|
|
||||||
uses: actions/cache@v1
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
with:
|
with:
|
||||||
path: ~/go/pkg/mod
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
- name: Set up Docker Buildx
|
||||||
${{ runner.os }}-go-
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
- name: Docker tag
|
- name: Docker tag
|
||||||
id: vars
|
id: vars
|
||||||
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
|
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
|
||||||
- name: Set up QEMU
|
- name: Login to Docker Hub
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/login-action@v2
|
||||||
- name: Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
- name: Docker login
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
with:
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
- name: Build image
|
|
||||||
env:
|
- name: Build and push eiblog
|
||||||
GOPROXY: https://goproxy.io,direct
|
uses: docker/build-push-action@v3
|
||||||
run: scripts/run_build.sh deepzz0 ${{ steps.vars.outputs.tag }}
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./build/package/eiblog.Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
deepzz0/eiblog:${{ steps.vars.outputs.tag }}
|
||||||
|
deepzz0/eiblog:latest
|
||||||
|
|
||||||
|
- name: Build and push backup
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./build/package/backup.Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
deepzz0/backup:${{ steps.vars.outputs.tag }}
|
||||||
|
deepzz0/backup:latest
|
||||||
|
|
||||||
- name: Package tar
|
- name: Package tar
|
||||||
env:
|
env:
|
||||||
|
|||||||
1
.gitignore
vendored
@@ -19,3 +19,4 @@ backend
|
|||||||
# vendor/
|
# vendor/
|
||||||
bin
|
bin
|
||||||
assets/*.*
|
assets/*.*
|
||||||
|
db.sqlite
|
||||||
|
|||||||
130
CHANGELOG.md
@@ -2,6 +2,136 @@
|
|||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
### [2.2.11](https://github.com/eiblog/eiblog/compare/v2.2.10...v2.2.11) (2024-01-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **disqus:** fix returned posts list not have parent post ([9d71ca8](https://github.com/eiblog/eiblog/commit/9d71ca81988bfc614d13fcb02079f0dba9ef43cc))
|
||||||
|
|
||||||
|
### [2.2.10](https://github.com/eiblog/eiblog/compare/v2.2.9...v2.2.10) (2023-12-22)
|
||||||
|
|
||||||
|
### [2.2.9](https://github.com/eiblog/eiblog/compare/v2.2.8...v2.2.9) (2023-09-25)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* google analytics not work, supported ga4 measurement protocol ([9b918ca](https://github.com/eiblog/eiblog/commit/9b918caccd9fd7faff7d253693e075ccd0150c17))
|
||||||
|
|
||||||
|
### [2.2.8](https://github.com/eiblog/eiblog/compare/v2.2.7...v2.2.8) (2023-07-12)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **backup:** restore db and tests ([f28d0e7](https://github.com/eiblog/eiblog/commit/f28d0e77e06dd435dc13a1867f18a011e34b8f53))
|
||||||
|
|
||||||
|
### [2.2.7](https://github.com/eiblog/eiblog/compare/v2.2.6...v2.2.7) (2023-07-12)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **backup:** 数据恢复错误 ([ee51f67](https://github.com/eiblog/eiblog/commit/ee51f678cbf93332fedccf927704e78a6063289c))
|
||||||
|
|
||||||
|
### [2.2.6](https://github.com/eiblog/eiblog/compare/v2.2.5...v2.2.6) (2023-06-19)
|
||||||
|
|
||||||
|
### [2.2.5](https://github.com/eiblog/eiblog/compare/v2.2.4...v2.2.5) (2023-05-26)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **backup:** libresolv.so.2: No such file or directory ([2c6c5bb](https://github.com/eiblog/eiblog/commit/2c6c5bb97708683bed8c889a7a1076f1f88ee5a8))
|
||||||
|
|
||||||
|
### [2.2.4](https://github.com/eiblog/eiblog/compare/v2.2.3...v2.2.4) (2023-05-25)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **ci:** fix .dockerignore ([1509a68](https://github.com/eiblog/eiblog/commit/1509a68cda74ace6b4060b5015f20143303ca36f))
|
||||||
|
|
||||||
|
### [2.2.3](https://github.com/eiblog/eiblog/compare/v2.2.2...v2.2.3) (2023-05-25)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **ci:** script file name ([20e89d6](https://github.com/eiblog/eiblog/commit/20e89d6a76f01aee60b98f8ae43a2c65b4fb3904))
|
||||||
|
|
||||||
|
### [2.2.2](https://github.com/eiblog/eiblog/compare/v2.2.1...v2.2.2) (2023-05-25)
|
||||||
|
|
||||||
|
### [2.2.1](https://github.com/eiblog/eiblog/compare/v2.2.0...v2.2.1) (2023-05-17)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* try to fix backup symbol not found ([bb06be3](https://github.com/eiblog/eiblog/commit/bb06be36fe016e753ca56aa2321ce7e39bffe3e0))
|
||||||
|
|
||||||
|
## [2.2.0](https://github.com/eiblog/eiblog/compare/v2.1.18...v2.2.0) (2023-05-17)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **backup:** add restore flag ([779a23c](https://github.com/eiblog/eiblog/commit/779a23cb75ab5059826370d08b754569a4af4aea))
|
||||||
|
|
||||||
|
### [2.1.18](https://github.com/eiblog/eiblog/compare/v2.1.17...v2.1.18) (2023-01-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **backup:** can not execute ([f6ba716](https://github.com/eiblog/eiblog/commit/f6ba716f554cfb638752875c4842e4ffb1b7e9a6))
|
||||||
|
* disqus api using http post ([b2e6c16](https://github.com/eiblog/eiblog/commit/b2e6c168c5f63b29cf5c2884e04dd99caa677bc0))
|
||||||
|
|
||||||
|
### [2.1.17](https://github.com/eiblog/eiblog/compare/v2.1.16...v2.1.17) (2023-01-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* 1. template read panic ([f6d8656](https://github.com/eiblog/eiblog/commit/f6d8656c83591584581383643d109611d7ed2caa))
|
||||||
|
* **disqus:** failed to commit disqus comments ([a9e8e39](https://github.com/eiblog/eiblog/commit/a9e8e39d342488ec46175997f3df9ab109f2fecf))
|
||||||
|
* fist comment of disqus error ([17792e5](https://github.com/eiblog/eiblog/commit/17792e5a7edb7e84623d9307555e7983ba306565))
|
||||||
|
|
||||||
|
### [2.1.16](https://github.com/eiblog/eiblog/compare/v2.1.15...v2.1.16) (2022-11-20)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **backup:** error path in compressed file ([aa91997](https://github.com/eiblog/eiblog/commit/aa91997c0caca27e9979692879f8877765dabd9d))
|
||||||
|
* rss image path incorrect: data-src -> src ([4bfff2e](https://github.com/eiblog/eiblog/commit/4bfff2e5e9b0efb4112a5f2f6bc55eebcef1c6eb))
|
||||||
|
|
||||||
|
### [2.1.15](https://github.com/eiblog/eiblog/compare/v2.1.14...v2.1.15) (2022-09-28)
|
||||||
|
|
||||||
|
### [2.1.14](https://github.com/eiblog/eiblog/compare/v2.1.13...v2.1.14) (2022-09-28)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* cgo and sqlite build in alpine image closed [#28](https://github.com/eiblog/eiblog/issues/28) ([b93c320](https://github.com/eiblog/eiblog/commit/b93c320987a936db6e5ca50c547022de9ab9a0f1))
|
||||||
|
|
||||||
|
### [2.1.13](https://github.com/eiblog/eiblog/compare/v2.1.12...v2.1.13) (2022-09-27)
|
||||||
|
|
||||||
|
### [2.1.12](https://github.com/eiblog/eiblog/compare/v2.1.11...v2.1.12) (2022-08-09)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#35](https://github.com/eiblog/eiblog/issues/35) no pubDate added for feed generation ([289b814](https://github.com/eiblog/eiblog/commit/289b8145bcdabd0060c9a0d5f40f5df69d3882d3))
|
||||||
|
|
||||||
|
### [2.1.11](https://github.com/eiblog/eiblog/compare/v2.1.10...v2.1.11) (2022-07-19)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **backup:** configuration error ([38aa704](https://github.com/eiblog/eiblog/commit/38aa704198070d3e1436b230b40b1deb3e94c5ac))
|
||||||
|
|
||||||
|
### [2.1.10](https://github.com/eiblog/eiblog/compare/v2.1.9...v2.1.10) (2022-04-22)
|
||||||
|
|
||||||
|
### [2.1.9](https://github.com/eiblog/eiblog/compare/v2.1.8...v2.1.9) (2022-02-14)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **eiblog:** comments title error ([5170844](https://github.com/eiblog/eiblog/commit/517084462336ce01c3f79099c1e54297979f5877))
|
||||||
|
|
||||||
|
### [2.1.8](https://github.com/eiblog/eiblog/compare/v2.1.7...v2.1.8) (2021-11-18)
|
||||||
|
|
||||||
### [2.1.7](https://github.com/eiblog/eiblog/compare/v2.1.6...v2.1.7) (2021-11-13)
|
### [2.1.7](https://github.com/eiblog/eiblog/compare/v2.1.6...v2.1.7) (2021-11-13)
|
||||||
|
|
||||||
### [2.1.6](https://github.com/eiblog/eiblog/compare/v2.1.5...v2.1.6) (2021-11-12)
|
### [2.1.6](https://github.com/eiblog/eiblog/compare/v2.1.5...v2.1.6) (2021-11-12)
|
||||||
|
|||||||
83
README.md
@@ -1,4 +1,4 @@
|
|||||||
# EiBlog [](https://travis-ci.org/eiblog/eiblog) [](LICENSE.md) [](https://github.com/eiblog/eiblog/releases)
|
# EiBlog [](LICENSE.md) [](https://github.com/eiblog/eiblog/releases)
|
||||||
|
|
||||||
> 博客项目结构参考模版:https://github.com/deepzz0/appdemo
|
> 博客项目结构参考模版:https://github.com/deepzz0/appdemo
|
||||||
|
|
||||||
@@ -6,9 +6,43 @@
|
|||||||
|
|
||||||
但它有着部署简单(上线复杂!)的特点,不推荐没有计算机知识的朋友搭建,欢迎咨询。该博客的个中优点(简洁、轻快,安全),等你体验。
|
但它有着部署简单(上线复杂!)的特点,不推荐没有计算机知识的朋友搭建,欢迎咨询。该博客的个中优点(简洁、轻快,安全),等你体验。
|
||||||
|
|
||||||
|
Docker镜像地址:
|
||||||
|
|
||||||
|
* 博客服务:[deepzz0/eiblog](https://hub.docker.com/r/deepzz0/eiblog)
|
||||||
|
* 博客搜索:[deepzz0/elasticsearch](https://hub.docker.com/r/deepzz0/elasticsearch)
|
||||||
|
* 数据备份:[deepzz0/backup](https://hub.docker.com/r/deepzz0/backup)
|
||||||
|
|
||||||
### 快速体验
|
### 快速体验
|
||||||
|
|
||||||
这里以 mongodb 为例,更多支持的后端存储服务如下:
|
**二进制**
|
||||||
|
|
||||||
|
1、下载压缩包,到 [这里](https://github.com/eiblog/eiblog/releases) 下载 eiblog(非backup) 相应系统压缩包,然后解压缩。
|
||||||
|
|
||||||
|
2、启动服务:`./backend`
|
||||||
|
|
||||||
|
**Docker**
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker run --name eiblog \
|
||||||
|
-p 9000:9000 \
|
||||||
|
deepzz0/eiblog:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
**Compose**
|
||||||
|
|
||||||
|
参考项目根目录下的 [docker-compose.yml](https://github.com/eiblog/eiblog/blob/v2/docker-compose.yml),修改相关配置:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker compose up -d
|
||||||
|
或
|
||||||
|
$ docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
然后访问 `localhost:9000` 就可以了,后台地址 `localhost:9000/admin/login`,默认账户密码 `deepzz/deepzz`。
|
||||||
|
|
||||||
|
> 默认情况下未开启博客搜索 `elasticsearch`,需要的话需要启动 es 服务并修改配置 `app.yml`。
|
||||||
|
|
||||||
|
**数据库支持**
|
||||||
|
|
||||||
| 类型(driver) | 地址(source)示例 |
|
| 类型(driver) | 地址(source)示例 |
|
||||||
| -------------- | ------------------------------------------------------------ |
|
| -------------- | ------------------------------------------------------------ |
|
||||||
@@ -19,42 +53,6 @@
|
|||||||
| sqlserver | sqlserver://user:password@localhost:9930?database=eiblog |
|
| sqlserver | sqlserver://user:password@localhost:9930?database=eiblog |
|
||||||
| clickhouse | tcp://localhost:9000?database=eiblog&username=user&password=password&read_timeout=10&write_timeout=20 |
|
| clickhouse | tcp://localhost:9000?database=eiblog&username=user&password=password&read_timeout=10&write_timeout=20 |
|
||||||
|
|
||||||
1、启动依赖服务,mongodb、elasticsearch:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ docker run --name mongodb \
|
|
||||||
-p 27017:27017 \
|
|
||||||
-v ${PWD}/mgodb:/data/db \
|
|
||||||
mongo:3.2
|
|
||||||
|
|
||||||
$ docker run --name elasticsearch \
|
|
||||||
-p 9200:9200 \
|
|
||||||
-v ${PWD}/esdata:/usr/share/elasticsearch/data \
|
|
||||||
deepzz0/elasticsearch:2.4.1
|
|
||||||
```
|
|
||||||
|
|
||||||
2、下载压缩包,到 [这里](https://github.com/eiblog/eiblog/releases) 下载 eiblog(非backup) 相应系统压缩包,然后解压缩。
|
|
||||||
|
|
||||||
3、修改配置,将数据库与ES地址修改为相应地址:
|
|
||||||
|
|
||||||
```
|
|
||||||
# 修改 conf/app.yml 数据库连接配置
|
|
||||||
database:
|
|
||||||
driver: mongodb
|
|
||||||
source: mongodb://localhost:27017
|
|
||||||
|
|
||||||
# 修改 conf/app.yml ES连接配置,如果不启用搜索功能可以置空
|
|
||||||
eshost: http://localhost:9200
|
|
||||||
```
|
|
||||||
|
|
||||||
4、启动服务:
|
|
||||||
|
|
||||||
```
|
|
||||||
./backend
|
|
||||||
```
|
|
||||||
|
|
||||||
然后访问 `localhost:9000` 就可以了,后台地址 `localhost:9000/admin/login`,默认账户密码 `deepzz/deepzz`。
|
|
||||||
|
|
||||||
### 功能特性
|
### 功能特性
|
||||||
|
|
||||||
本着博客本质用来分享知识的特点,`EiBlog` 不会有较强的定制功能(包括主题,CDN支持等),仅保持常用简单页面与功能:
|
本着博客本质用来分享知识的特点,`EiBlog` 不会有较强的定制功能(包括主题,CDN支持等),仅保持常用简单页面与功能:
|
||||||
@@ -85,12 +83,11 @@ eshost: http://localhost:9200
|
|||||||
|
|
||||||
### 博客页面
|
### 博客页面
|
||||||
|
|
||||||
可以容易的看到 [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+`,堪称完美。这些安全的相关配置会在后面的部署过程中接触到。
|
可以容易的看到 [ssllabs](https://www.ssllabs.com/ssltest/analyze.html?d=deepzz.com&latest) 评分`A+`,[myssl](https://myssl.com/deepzz.com) 评分`A+`,堪称完美。这些安全的相关配置会在后面的部署过程中接触到。
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|

|
||||||

|
|
||||||
|
|
||||||
### 更多文档
|
### 更多文档
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
|
FROM golang:1.20 AS builder
|
||||||
|
|
||||||
|
WORKDIR /eiblog
|
||||||
|
COPY . .
|
||||||
|
RUN ./scripts/run_build.sh backup
|
||||||
|
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
LABEL maintainer="deepzz.qi@gmail.com"
|
LABEL maintainer="deepzz.qi@gmail.com"
|
||||||
|
|
||||||
RUN apk add --update --no-cache tzdata ca-certificates mongodb-tools
|
RUN apk add --update --no-cache tzdata ca-certificates \
|
||||||
|
mongodb-tools libc6-compat gcompat
|
||||||
COPY README.md /app/README.md
|
COPY README.md /app/README.md
|
||||||
COPY CHANGELOG.md /app/CHANGELOG.md
|
COPY CHANGELOG.md /app/CHANGELOG.md
|
||||||
COPY LICENSE /app/LICENSE
|
COPY LICENSE /app/LICENSE
|
||||||
|
|
||||||
COPY bin/backend /app/backend
|
COPY --from=builder /eiblog/bin/backend /app/backend
|
||||||
COPY conf /app/conf
|
COPY conf /app/conf
|
||||||
|
|
||||||
EXPOSE 9001
|
EXPOSE 9001
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
FROM golang:1.20 AS builder
|
||||||
|
|
||||||
|
WORKDIR /eiblog
|
||||||
|
COPY . .
|
||||||
|
RUN ./scripts/run_build.sh eiblog
|
||||||
|
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
LABEL maintainer="deepzz.qi@gmail.com"
|
LABEL maintainer="deepzz.qi@gmail.com"
|
||||||
|
|
||||||
@@ -6,7 +13,7 @@ COPY README.md /app/README.md
|
|||||||
COPY CHANGELOG.md /app/CHANGELOG.md
|
COPY CHANGELOG.md /app/CHANGELOG.md
|
||||||
COPY LICENSE /app/LICENSE
|
COPY LICENSE /app/LICENSE
|
||||||
|
|
||||||
COPY bin/backend /app/backend
|
COPY --from=builder /eiblog/bin/backend /app/backend
|
||||||
COPY conf /app/conf
|
COPY conf /app/conf
|
||||||
COPY website /app/website
|
COPY website /app/website
|
||||||
COPY assets /app/assets
|
COPY assets /app/assets
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/eiblog/eiblog/pkg/config"
|
"github.com/eiblog/eiblog/pkg/config"
|
||||||
@@ -12,25 +13,32 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var restore bool
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.BoolVar(&restore, "restore", false, "restore data into mongodb")
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Hi, it's App " + config.Conf.BackupApp.Name)
|
fmt.Println("Hi, it's App " + config.Conf.BackupApp.Name)
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
endRun := make(chan error, 1)
|
endRun := make(chan error, 1)
|
||||||
|
|
||||||
runTimer(endRun)
|
runCommand(restore, endRun)
|
||||||
|
|
||||||
runHTTPServer(endRun)
|
runHTTPServer(endRun)
|
||||||
fmt.Println(<-endRun)
|
fmt.Println(<-endRun)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTimer(endRun chan error) {
|
func runCommand(restore bool, endRun chan error) {
|
||||||
go func() {
|
go func() {
|
||||||
endRun <- timer.Start()
|
endRun <- timer.Start(restore)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func runHTTPServer(endRun chan error) {
|
func runHTTPServer(endRun chan error) {
|
||||||
if !config.Conf.EiBlogApp.EnableHTTP {
|
if !config.Conf.BackupApp.EnableHTTP {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +54,7 @@ func runHTTPServer(endRun chan error) {
|
|||||||
ping.RegisterRoutes(e)
|
ping.RegisterRoutes(e)
|
||||||
|
|
||||||
// start
|
// start
|
||||||
address := fmt.Sprintf(":%d", config.Conf.EiBlogApp.HTTPPort)
|
address := fmt.Sprintf(":%d", config.Conf.BackupApp.HTTPPort)
|
||||||
go func() {
|
go func() {
|
||||||
endRun <- e.Run(address)
|
endRun <- e.Run(address)
|
||||||
}()
|
}()
|
||||||
|
|||||||
15
conf/app.yml
@@ -1,8 +1,8 @@
|
|||||||
appname: eiblog
|
appname: eiblog
|
||||||
database:
|
database:
|
||||||
driver: postgres
|
driver: sqlite
|
||||||
source: host=localhost port=5432 user=postgres dbname=eiblog sslmode=disable password=MTI3LjAuMC4x
|
source: ./db.sqlite
|
||||||
eshost:
|
eshost: # http://elasticsearch:9200
|
||||||
eiblogapp:
|
eiblogapp:
|
||||||
mode:
|
mode:
|
||||||
name: cmd-eiblog
|
name: cmd-eiblog
|
||||||
@@ -28,11 +28,10 @@ eiblogapp:
|
|||||||
publickey: wdSgxRm9rdGAlLKFcFdToBe3GT4SibmV7Y8EjJQ0r4GWXeKtxpopMAeIeoI2dTEg
|
publickey: wdSgxRm9rdGAlLKFcFdToBe3GT4SibmV7Y8EjJQ0r4GWXeKtxpopMAeIeoI2dTEg
|
||||||
accesstoken: 50023908f39f4607957e909b495326af
|
accesstoken: 50023908f39f4607957e909b495326af
|
||||||
google: # 谷歌分析
|
google: # 谷歌分析
|
||||||
url: https://www.google-analytics.com/collect
|
url: https://www.google-analytics.com/g/collect
|
||||||
tid: UA-xxxxxx-1
|
tid: G-xxxxxxxxxx
|
||||||
v: "1"
|
v: "2"
|
||||||
t: pageview
|
adsense: <script async src="https://pagead2.googlesyndication.com/xxx" crossorigin="anonymous"></script>
|
||||||
adsense: <script data-ad-client="ca-pub-5384494508691406" async src=""></script>
|
|
||||||
qiniu: # 七牛OSS
|
qiniu: # 七牛OSS
|
||||||
bucket: eiblog
|
bucket: eiblog
|
||||||
domain: st.deepzz.com
|
domain: st.deepzz.com
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ services:
|
|||||||
- ${PWD}/esdata:/usr/share/elasticsearch/data
|
- ${PWD}/esdata:/usr/share/elasticsearch/data
|
||||||
restart: always
|
restart: always
|
||||||
eiblog:
|
eiblog:
|
||||||
iamge: deepzz0/eiblog:latest
|
image: deepzz0/eiblog:latest
|
||||||
volumes:
|
volumes:
|
||||||
- ${PWD}/conf:/app/conf
|
- ${PWD}/conf:/app/conf
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
@@ -21,13 +21,13 @@ services:
|
|||||||
- elasticsearch
|
- elasticsearch
|
||||||
- mongodb
|
- mongodb
|
||||||
environment:
|
environment:
|
||||||
- GODEBUG=netdns=cgo
|
|
||||||
- RUN_MODE=prod
|
- RUN_MODE=prod
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:9000:9000
|
- 127.0.0.1:9000:9000
|
||||||
restart: always
|
restart: always
|
||||||
backup:
|
backup:
|
||||||
image: deepzz0/backup:latest
|
image: deepzz0/backup:latest
|
||||||
|
#command: ./backend --restore true
|
||||||
volumes:
|
volumes:
|
||||||
- ${PWD}/conf:/app/conf
|
- ${PWD}/conf:/app/conf
|
||||||
links:
|
links:
|
||||||
|
|||||||
@@ -2,42 +2,58 @@
|
|||||||
|
|
||||||
> 博客项目结构参考模版:https://github.com/deepzz0/appdemo
|
> 博客项目结构参考模版:https://github.com/deepzz0/appdemo
|
||||||
|
|
||||||
EiBlog 镜像仓库地址:https://hub.docker.com/u/deepzz0
|
|
||||||
|
|
||||||
用过其它博客系统,不喜欢,不够轻,不够快!这是我开发的第二款博客系统,也实在不想再在这件事情上过多纠结了。`EiBlog` 是一个比较稳定的博客系统,现已迭代至 `2.0` 版本,稳定性和维护你是不用担心的。
|
用过其它博客系统,不喜欢,不够轻,不够快!这是我开发的第二款博客系统,也实在不想再在这件事情上过多纠结了。`EiBlog` 是一个比较稳定的博客系统,现已迭代至 `2.0` 版本,稳定性和维护你是不用担心的。
|
||||||
|
|
||||||
但它有着部署简单(上线复杂!)的特点,不推荐没有计算机知识的朋友搭建,欢迎咨询。该博客的个中优点(简洁、轻快,安全),等你体验。
|
但它有着部署简单(上线复杂!)的特点,不推荐没有计算机知识的朋友搭建,欢迎咨询。该博客的个中优点(简洁、轻快,安全),等你体验。
|
||||||
|
|
||||||
### 快速体验
|
### 快速体验
|
||||||
|
|
||||||
1、下载程序压缩包:到 [这里](https://github.com/eiblog/eiblog/releases) 下载 eiblog 相应系统压缩包,然后解压缩。
|
这里以 mongodb 为例,更多支持的后端存储服务如下:
|
||||||
|
|
||||||
2、启动数据库服务:博客支持多种数据库后端,如MongoDB、MySQL、Postgres、SQLite等。
|
| 类型(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 |
|
||||||
|
|
||||||
|
1、启动依赖服务,mongodb、elasticsearch:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker run --name mongodb \
|
||||||
|
-p 27017:27017 \
|
||||||
|
-v ${PWD}/mgodb:/data/db \
|
||||||
|
mongo:3.2
|
||||||
|
|
||||||
|
$ docker run --name elasticsearch \
|
||||||
|
-p 9200:9200 \
|
||||||
|
-v ${PWD}/esdata:/usr/share/elasticsearch/data \
|
||||||
|
deepzz0/elasticsearch:2.4.1
|
||||||
|
```
|
||||||
|
|
||||||
|
2、下载压缩包,到 [这里](https://github.com/eiblog/eiblog/releases) 下载 eiblog(非backup) 相应系统压缩包,然后解压缩。
|
||||||
|
|
||||||
|
3、修改配置,将数据库与ES地址修改为相应地址:
|
||||||
|
|
||||||
```
|
```
|
||||||
# 修改 conf/app.yml 数据库连接配置
|
# 修改 conf/app.yml 数据库连接配置
|
||||||
# driver可选:mongodb、mysql、postgres、sqlite、sqlserver、clickhouse、redis等
|
|
||||||
# source为相应的连接地址
|
|
||||||
database:
|
database:
|
||||||
driver: postgres
|
driver: mongodb
|
||||||
source: host=localhost port=5432 user=postgres dbname=eiblog sslmode=disable password=MTI3LjAuMC4x
|
source: mongodb://localhost:27017
|
||||||
```
|
|
||||||
|
|
||||||
3、启动 ES 搜索服务:博客使用 ElasticSearch 2.4.1 做为搜索引擎。
|
# 修改 conf/app.yml ES连接配置,如果不启用搜索功能可以置空
|
||||||
|
|
||||||
```
|
|
||||||
# 修改 conf/app.yml ElasticSearch连接配置
|
|
||||||
# 如果不启用搜索功能可以置空
|
|
||||||
eshost: http://localhost:9200
|
eshost: http://localhost:9200
|
||||||
```
|
```
|
||||||
|
|
||||||
4、启动博客程序。
|
4、启动服务:
|
||||||
|
|
||||||
```
|
```
|
||||||
./backend
|
./backend
|
||||||
```
|
```
|
||||||
|
|
||||||
然后访问 `localhost:9000` 就可以了。
|
然后访问 `localhost:9000` 就可以了,后台地址 `localhost:9000/admin/login`,默认账户密码 `deepzz/deepzz`。
|
||||||
|
|
||||||
### 功能特性
|
### 功能特性
|
||||||
|
|
||||||
@@ -49,16 +65,16 @@ eshost: http://localhost:9200
|
|||||||
|
|
||||||
功能说明:
|
功能说明:
|
||||||
|
|
||||||
- [x] 博客归档,利用时间线帮助我们将归纳博文,内容少于一年按月归档,大于则按年归档。
|
* 博客归档,利用时间线帮助我们将归纳博文,内容少于一年按月归档,大于则按年归档。
|
||||||
- [x] 博客专题,有时候博文是同一系列,专题能够帮助我们很好归纳博文,对阅读者是非常友好的。
|
* 博客专题,有时候博文是同一系列,专题能够帮助我们很好归纳博文,对阅读者是非常友好的。
|
||||||
- [x] 标签系统,每篇博文都可以打上不同标签,使得在归档和专题不满足的情况下自定义归档,这块辅助搜索简直完美。
|
* 标签系统,每篇博文都可以打上不同标签,使得在归档和专题不满足的情况下自定义归档,这块辅助搜索简直完美。
|
||||||
- [x] 搜索系统,依托ElasticSearch实现的站内搜索,速度与效率并存,再加上google opensearch,搜索只流畅。
|
* 搜索系统,依托ElasticSearch实现的站内搜索,速度与效率并存,再加上google opensearch,搜索只流畅。
|
||||||
- [x] 管理后台,内嵌全功能 `Typecho` 后台系统,全功能 `Markdown` 编辑器让你感觉什么是简洁清爽。
|
* 管理后台,内嵌全功能 `Typecho` 后台系统,全功能 `Markdown` 编辑器让你感觉什么是简洁清爽。
|
||||||
- [x] 谷歌统计,由于google api的速度问题,从而实现了后端API异步统计,使得博客页面加载飞速。
|
* 谷歌统计,由于google api的速度问题,从而实现了后端API异步统计,使得博客页面加载飞速。
|
||||||
- [x] Disqus评论,国内评论系统不友好,因此选择disqus,又由于众所周知原因国内不能用,实现另类disqus评论方式。
|
* Disqus评论,国内评论系统不友好,因此选择disqus,又由于众所周知原因国内不能用,实现另类disqus评论方式。
|
||||||
- [x] 多存储后端,支持mongodb、mysql、postgres、sqlite等存储后端。
|
* 多存储后端,支持mongodb、mysql、postgres、sqlite等存储后端。
|
||||||
- [x] 七牛CDN,支持在 `Markdown` 编辑器直接上传附件,让你只考虑编辑内容,解放思想。
|
* 七牛CDN,支持在 `Markdown` 编辑器直接上传附件,让你只考虑编辑内容,解放思想。
|
||||||
- [x] 自动备份,支持多存储后端的备份功能,备份数据保存到七牛CDN上。
|
* 自动备份,支持多存储后端的备份功能,备份数据保存到七牛CDN上。
|
||||||
|
|
||||||
当然,为了让整个系统加载速度更快,还做了更多优化措施:
|
当然,为了让整个系统加载速度更快,还做了更多优化措施:
|
||||||
|
|
||||||
@@ -71,10 +87,9 @@ eshost: http://localhost:9200
|
|||||||
|
|
||||||
可以容易的看到 [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+`,堪称完美。这些安全的相关配置会在后面的部署过程中接触到。
|
可以容易的看到 [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+`,堪称完美。这些安全的相关配置会在后面的部署过程中接触到。
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|

|
||||||

|
|
||||||
|
|
||||||
### 更多文档
|
### 更多文档
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ twitter:
|
|||||||
|
|
||||||
每当你发部一个推文,你如果带上你的网址,它会自动给你展示成卡片的形式
|
每当你发部一个推文,你如果带上你的网址,它会自动给你展示成卡片的形式
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

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

|

|
||||||
|
|||||||
BIN
docs/img/article-description.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
docs/img/article-title.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
docs/img/blank.gif
Normal file
|
After Width: | Height: | Size: 37 B |
BIN
docs/img/deepzz-home-page.jpeg
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
docs/img/default_avatar.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
docs/img/dialog-box-without-all-contols.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/img/opensearch.gif
Normal file
|
After Width: | Height: | Size: 1.9 MiB |
BIN
docs/img/show-admin.png
Normal file
|
After Width: | Height: | Size: 566 KiB |
BIN
docs/img/show-home.png
Normal file
|
After Width: | Height: | Size: 547 KiB |
BIN
docs/img/show-home2.png
Normal file
|
After Width: | Height: | Size: 382 KiB |
BIN
docs/img/twitter-pub.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
docs/img/twitter-pub2.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
@@ -24,17 +24,17 @@
|
|||||||
|
|
||||||
结果是:
|
结果是:
|
||||||
|
|
||||||

|

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

|

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

|

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

|

|
||||||
|
|
||||||
懒加载,需要为该图片指定大小(长高):
|
懒加载,需要为该图片指定大小(长高):
|
||||||
```
|
```
|
||||||
@@ -61,7 +61,7 @@ x 为小写字母(x,y,z)中的 x。使页面未加载时也占了相应的
|
|||||||
### 摘要截取
|
### 摘要截取
|
||||||
摘要截取主要是提供给首页显示,如:
|
摘要截取主要是提供给首页显示,如:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
红框中圈出来的就是截取出来的内容。在 `conf/app.yml` 的配置项有两个:
|
红框中圈出来的就是截取出来的内容。在 `conf/app.yml` 的配置项有两个:
|
||||||
|
|
||||||
|
|||||||
12
eiblog.conf
@@ -17,7 +17,7 @@ server {
|
|||||||
server_tokens off;
|
server_tokens off;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
rewrite ^/(.*)$ https://$host/$1 permanent;
|
rewrite ^/(.*)$ https://deepzz.com/$1 permanent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +61,10 @@ server {
|
|||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
expires 1d;
|
expires 1d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($host != 'deepzz.com' ) {
|
||||||
|
rewrite ^/(.*)$ https://deepzz.com/$1 permanent;
|
||||||
|
}
|
||||||
|
|
||||||
# proxy setting
|
# proxy setting
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
@@ -74,9 +78,6 @@ server {
|
|||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
location ^~ /admin/ {
|
location ^~ /admin/ {
|
||||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
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 Cache-Control no-cache;
|
||||||
add_header X-Frame-Options SAMEORIGIN;
|
add_header X-Frame-Options SAMEORIGIN;
|
||||||
add_header X-Content-Type-Options nosniff;
|
add_header X-Content-Type-Options nosniff;
|
||||||
@@ -89,9 +90,6 @@ server {
|
|||||||
|
|
||||||
location / {
|
location / {
|
||||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
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 Cache-Control no-cache;
|
||||||
# 内容安全策略: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
|
# 内容安全策略: 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 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";
|
||||||
|
|||||||
29
go.mod
@@ -3,25 +3,22 @@ module github.com/eiblog/eiblog
|
|||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
|
|
||||||
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae
|
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae
|
||||||
github.com/gin-contrib/sessions v0.0.3
|
github.com/gin-contrib/sessions v0.0.5
|
||||||
github.com/gin-gonic/gin v1.7.4
|
github.com/gin-gonic/gin v1.9.1
|
||||||
github.com/golang/protobuf v1.4.2
|
github.com/lib/pq v1.10.9
|
||||||
github.com/lib/pq v1.10.1
|
|
||||||
github.com/qiniu/go-sdk/v7 v7.11.0
|
github.com/qiniu/go-sdk/v7 v7.11.0
|
||||||
github.com/satori/go.uuid v1.2.0
|
github.com/satori/go.uuid v1.2.0
|
||||||
github.com/sirupsen/logrus v1.4.2
|
github.com/sirupsen/logrus v1.9.3
|
||||||
|
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
|
||||||
github.com/swaggo/gin-swagger v1.3.3
|
github.com/swaggo/gin-swagger v1.3.3
|
||||||
github.com/swaggo/swag v1.7.4
|
github.com/swaggo/swag v1.7.4
|
||||||
go.mongodb.org/mongo-driver v1.5.1
|
go.mongodb.org/mongo-driver v1.11.4
|
||||||
google.golang.org/grpc v1.35.0
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
google.golang.org/protobuf v1.25.0
|
gorm.io/driver/clickhouse v0.6.0
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gorm.io/driver/mysql v1.5.2
|
||||||
gorm.io/driver/clickhouse v0.1.0
|
gorm.io/driver/postgres v1.5.4
|
||||||
gorm.io/driver/mysql v1.0.6
|
gorm.io/driver/sqlite v1.5.4
|
||||||
gorm.io/driver/postgres v1.0.8
|
gorm.io/driver/sqlserver v1.5.2
|
||||||
gorm.io/driver/sqlite v1.1.4
|
gorm.io/gorm v1.25.5
|
||||||
gorm.io/driver/sqlserver v1.0.7
|
|
||||||
gorm.io/gorm v1.21.9
|
|
||||||
)
|
)
|
||||||
|
|||||||
12
pkg/cache/cache.go
vendored
@@ -25,9 +25,11 @@ var (
|
|||||||
// Ei eiblog cache
|
// Ei eiblog cache
|
||||||
Ei *Cache
|
Ei *Cache
|
||||||
|
|
||||||
// regenerate pages chan
|
// PagesCh regenerate pages chan
|
||||||
PagesCh = make(chan string, 2)
|
PagesCh = make(chan string, 2)
|
||||||
PageSeries = "series-md"
|
// PageSeries the page series regenerate flag
|
||||||
|
PageSeries = "series-md"
|
||||||
|
// PageArchive the page archive regenerate flag
|
||||||
PageArchive = "archive-md"
|
PageArchive = "archive-md"
|
||||||
|
|
||||||
// ArticleStartID article start id
|
// ArticleStartID article start id
|
||||||
@@ -518,7 +520,7 @@ func (c *Cache) regeneratePages() {
|
|||||||
}
|
}
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
}
|
}
|
||||||
c.PageSeries = string(render.RenderPage(buf.Bytes()))
|
c.PageSeries = string(render.PageRender(buf.Bytes()))
|
||||||
case PageArchive:
|
case PageArchive:
|
||||||
sort.Sort(c.Archives)
|
sort.Sort(c.Archives)
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
@@ -551,7 +553,7 @@ func (c *Cache) regeneratePages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.PageArchives = string(render.RenderPage(buf.Bytes()))
|
c.PageArchives = string(render.PageRender(buf.Bytes()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
pkg/cache/render/render.go
vendored
@@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
// blackfriday 配置
|
// blackfriday 配置
|
||||||
const (
|
const (
|
||||||
commonHtmlFlags = 0 |
|
commonHTMLFlags = 0 |
|
||||||
blackfriday.HTML_TOC |
|
blackfriday.HTML_TOC |
|
||||||
blackfriday.HTML_USE_XHTML |
|
blackfriday.HTML_USE_XHTML |
|
||||||
blackfriday.HTML_USE_SMARTYPANTS |
|
blackfriday.HTML_USE_SMARTYPANTS |
|
||||||
@@ -42,9 +42,9 @@ var (
|
|||||||
regHeader = regexp.MustCompile("</nav></div>")
|
regHeader = regexp.MustCompile("</nav></div>")
|
||||||
)
|
)
|
||||||
|
|
||||||
// RenderPage 渲染markdown
|
// PageRender 渲染markdown
|
||||||
func RenderPage(md []byte) []byte {
|
func PageRender(md []byte) []byte {
|
||||||
renderer := blackfriday.HtmlRenderer(commonHtmlFlags, "", "")
|
renderer := blackfriday.HtmlRenderer(commonHTMLFlags, "", "")
|
||||||
return blackfriday.Markdown(md, renderer, commonExtensions)
|
return blackfriday.Markdown(md, renderer, commonExtensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,12 +56,12 @@ func GenerateExcerptMarkdown(article *model.Article) {
|
|||||||
index := strings.Index(article.Content, "\r\n")
|
index := strings.Index(article.Content, "\r\n")
|
||||||
prefix := article.Content[len(blogapp.General.DescPrefix):index]
|
prefix := article.Content[len(blogapp.General.DescPrefix):index]
|
||||||
|
|
||||||
article.Desc = tools.IgnoreHtmlTag(prefix)
|
article.Desc = tools.IgnoreHTMLTag(prefix)
|
||||||
article.Content = article.Content[index:]
|
article.Content = article.Content[index:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找目录
|
// 查找目录
|
||||||
content := RenderPage([]byte(article.Content))
|
content := PageRender([]byte(article.Content))
|
||||||
index := regHeader.FindIndex(content)
|
index := regHeader.FindIndex(content)
|
||||||
if index != nil {
|
if index != nil {
|
||||||
article.Header = string(content[0:index[1]])
|
article.Header = string(content[0:index[1]])
|
||||||
@@ -73,7 +73,7 @@ func GenerateExcerptMarkdown(article *model.Article) {
|
|||||||
// excerpt
|
// excerpt
|
||||||
index = regIdentifier.FindStringIndex(article.Content)
|
index = regIdentifier.FindStringIndex(article.Content)
|
||||||
if index != nil {
|
if index != nil {
|
||||||
article.Excerpt = tools.IgnoreHtmlTag(article.Content[:index[0]])
|
article.Excerpt = tools.IgnoreHTMLTag(article.Content[:index[0]])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uc := []rune(article.Content)
|
uc := []rune(article.Content)
|
||||||
@@ -81,5 +81,5 @@ func GenerateExcerptMarkdown(article *model.Article) {
|
|||||||
if len(uc) < length {
|
if len(uc) < length {
|
||||||
length = len(uc)
|
length = len(uc)
|
||||||
}
|
}
|
||||||
article.Excerpt = tools.IgnoreHtmlTag(string(uc[0:length]))
|
article.Excerpt = tools.IgnoreHTMLTag(string(uc[0:length]))
|
||||||
}
|
}
|
||||||
|
|||||||
5
pkg/cache/store/mongodb.go
vendored
@@ -326,6 +326,11 @@ func (db *mongodb) LoadArticleList(ctx context.Context, search SearchArticles) (
|
|||||||
return articles, int(count), nil
|
return articles, int(count), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DropDatabase drop eiblog database
|
||||||
|
func (db *mongodb) DropDatabase(ctx context.Context) error {
|
||||||
|
return db.Database(mongoDBName).Drop(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// counter counter
|
// counter counter
|
||||||
type counter struct {
|
type counter struct {
|
||||||
Name string
|
Name string
|
||||||
|
|||||||
84
pkg/cache/store/mongodb_test.go
vendored
@@ -13,7 +13,7 @@ var (
|
|||||||
store Store
|
store Store
|
||||||
acct *model.Account
|
acct *model.Account
|
||||||
blogger *model.Blogger
|
blogger *model.Blogger
|
||||||
series *model.Series
|
series *model.Serie
|
||||||
article *model.Article
|
article *model.Article
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,12 +25,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
// account
|
// account
|
||||||
acct = &model.Account{
|
acct = &model.Account{
|
||||||
Username: "deepzz",
|
Username: "deepzz",
|
||||||
Password: "deepzz",
|
Password: "deepzz",
|
||||||
Email: "deepzz@example.com",
|
Email: "deepzz@example.com",
|
||||||
PhoneN: "12345678900",
|
PhoneN: "12345678900",
|
||||||
Address: "address",
|
Address: "address",
|
||||||
CreateTime: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
// blogger
|
// blogger
|
||||||
blogger = &model.Blogger{
|
blogger = &model.Blogger{
|
||||||
@@ -41,11 +41,11 @@ func init() {
|
|||||||
Copyright: "Copyright",
|
Copyright: "Copyright",
|
||||||
}
|
}
|
||||||
// series
|
// series
|
||||||
series = &model.Series{
|
series = &model.Serie{
|
||||||
Slug: "slug",
|
Slug: "slug",
|
||||||
Name: "series name",
|
Name: "series name",
|
||||||
Desc: "series desc",
|
Desc: "series desc",
|
||||||
CreateTime: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
// article
|
// article
|
||||||
article = &model.Article{
|
article = &model.Article{
|
||||||
@@ -55,21 +55,20 @@ func init() {
|
|||||||
Count: 0,
|
Count: 0,
|
||||||
Content: "### count",
|
Content: "### count",
|
||||||
SerieID: 0,
|
SerieID: 0,
|
||||||
Tags: "",
|
Tags: nil,
|
||||||
IsDraft: false,
|
IsDraft: false,
|
||||||
|
|
||||||
UpdateTime: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
CreateTime: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadInsertAccount(t *testing.T) {
|
func TestLoadInsertAccount(t *testing.T) {
|
||||||
acct2, err := store.LoadInsertAccount(context.Background(), acct)
|
ok, err := store.LoadInsertAccount(context.Background(), acct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Log(acct2)
|
t.Log(ok)
|
||||||
t.Log(acct == acct2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateAccount(t *testing.T) {
|
func TestUpdateAccount(t *testing.T) {
|
||||||
@@ -86,12 +85,11 @@ func TestUpdateAccount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadInsertBlogger(t *testing.T) {
|
func TestLoadInsertBlogger(t *testing.T) {
|
||||||
blogger2, err := store.LoadInsertBlogger(context.Background(), blogger)
|
ok, err := store.LoadInsertBlogger(context.Background(), blogger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Log(blogger2)
|
t.Log(ok)
|
||||||
t.Log(blogger == blogger2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateBlogger(t *testing.T) {
|
func TestUpdateBlogger(t *testing.T) {
|
||||||
@@ -104,21 +102,21 @@ func TestUpdateBlogger(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInsertSeries(t *testing.T) {
|
func TestInsertSeries(t *testing.T) {
|
||||||
err := store.InsertSeries(context.Background(), series)
|
err := store.InsertSerie(context.Background(), series)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoveSeries(t *testing.T) {
|
func TestRemoveSeries(t *testing.T) {
|
||||||
err := store.RemoveSeries(context.Background(), 1)
|
err := store.RemoveSerie(context.Background(), 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateSeries(t *testing.T) {
|
func TestUpdateSeries(t *testing.T) {
|
||||||
err := store.UpdateSeries(context.Background(), 2, map[string]interface{}{
|
err := store.UpdateSerie(context.Background(), 2, map[string]interface{}{
|
||||||
"desc": "update desc",
|
"desc": "update desc",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -127,7 +125,7 @@ func TestUpdateSeries(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadAllSeries(t *testing.T) {
|
func TestLoadAllSeries(t *testing.T) {
|
||||||
series, err := store.LoadAllSeries(context.Background())
|
series, err := store.LoadAllSerie(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -136,7 +134,7 @@ func TestLoadAllSeries(t *testing.T) {
|
|||||||
|
|
||||||
func TestInsertArticle(t *testing.T) {
|
func TestInsertArticle(t *testing.T) {
|
||||||
article.ID = 12
|
article.ID = 12
|
||||||
err := store.InsertArticle(context.Background(), article)
|
err := store.InsertArticle(context.Background(), article, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -150,14 +148,14 @@ func TestRemoveArticle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteArticle(t *testing.T) {
|
func TestDeleteArticle(t *testing.T) {
|
||||||
err := store.DeleteArticle(context.Background(), 12)
|
err := store.RemoveArticle(context.Background(), 12)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCleanArticles(t *testing.T) {
|
func TestCleanArticles(t *testing.T) {
|
||||||
err := store.CleanArticles(context.Background())
|
err := store.CleanArticles(context.Background(), time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -173,33 +171,13 @@ func TestUpdateArticle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRecoverArticle(t *testing.T) {
|
|
||||||
err := store.RecoverArticle(context.Background(), 12)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadAllArticle(t *testing.T) {
|
func TestLoadAllArticle(t *testing.T) {
|
||||||
articles, err := store.LoadAllArticle(context.Background())
|
_, total, err := store.LoadArticleList(context.Background(), SearchArticles{
|
||||||
|
Page: 1,
|
||||||
|
Limit: 1000,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Logf("load all articles: %d", len(articles))
|
t.Logf("load all articles: %d", total)
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadTrashArticles(t *testing.T) {
|
|
||||||
articles, err := store.LoadTrashArticles(context.Background())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
t.Logf("load trash articles: %d", len(articles))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadDraftArticles(t *testing.T) {
|
|
||||||
articles, err := store.LoadDraftArticles(context.Background())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
t.Logf("load draft articles: %d", len(articles))
|
|
||||||
}
|
}
|
||||||
|
|||||||
8
pkg/cache/store/rdbms.go
vendored
@@ -3,6 +3,7 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eiblog/eiblog/pkg/model"
|
"github.com/eiblog/eiblog/pkg/model"
|
||||||
@@ -129,7 +130,7 @@ func (db *rdbms) InsertArticle(ctx context.Context, article *model.Article, star
|
|||||||
if id < startID {
|
if id < startID {
|
||||||
id = startID
|
id = startID
|
||||||
} else {
|
} else {
|
||||||
id += 1
|
id++
|
||||||
}
|
}
|
||||||
article.ID = id
|
article.ID = id
|
||||||
}
|
}
|
||||||
@@ -190,6 +191,11 @@ func (db *rdbms) LoadArticleList(ctx context.Context, search SearchArticles) (mo
|
|||||||
return articles, int(count), err
|
return articles, int(count), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DropDatabase drop eiblog database
|
||||||
|
func (db *rdbms) DropDatabase(ctx context.Context) error {
|
||||||
|
return errors.New("can not drop eiblog database in rdbms")
|
||||||
|
}
|
||||||
|
|
||||||
// register store
|
// register store
|
||||||
func init() {
|
func init() {
|
||||||
Register("mysql", &rdbms{})
|
Register("mysql", &rdbms{})
|
||||||
|
|||||||
3
pkg/cache/store/store.go
vendored
@@ -64,6 +64,9 @@ type Store interface {
|
|||||||
LoadArticle(ctx context.Context, id int) (*model.Article, error)
|
LoadArticle(ctx context.Context, id int) (*model.Article, error)
|
||||||
// LoadArticleList 查找文章列表
|
// LoadArticleList 查找文章列表
|
||||||
LoadArticleList(ctx context.Context, search SearchArticles) (model.SortedArticles, int, error)
|
LoadArticleList(ctx context.Context, search SearchArticles) (model.SortedArticles, int, error)
|
||||||
|
|
||||||
|
// 危险操作
|
||||||
|
DropDatabase(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver 存储驱动
|
// Driver 存储驱动
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -69,7 +69,6 @@ type Google struct {
|
|||||||
URL string `yaml:"url"`
|
URL string `yaml:"url"`
|
||||||
Tid string `yaml:"tid"`
|
Tid string `yaml:"tid"`
|
||||||
V string `yaml:"v"`
|
V string `yaml:"v"`
|
||||||
T string `yaml:"t"`
|
|
||||||
AdSense string `yaml:"adsense"`
|
AdSense string `yaml:"adsense"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
_ "github.com/eiblog/eiblog/pkg/core/backup/docs" // docs
|
_ "github.com/eiblog/eiblog/pkg/core/backup/docs" // docs
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
swaggerFiles "github.com/swaggo/files"
|
||||||
ginSwagger "github.com/swaggo/gin-swagger"
|
ginSwagger "github.com/swaggo/gin-swagger"
|
||||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterRoutes register routes
|
// RegisterRoutes register routes
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/eiblog/eiblog/pkg/cache/store"
|
||||||
"github.com/eiblog/eiblog/pkg/config"
|
"github.com/eiblog/eiblog/pkg/config"
|
||||||
"github.com/eiblog/eiblog/pkg/internal"
|
"github.com/eiblog/eiblog/pkg/internal"
|
||||||
)
|
)
|
||||||
@@ -23,7 +25,19 @@ func (s Storage) BackupData(now time.Time) error {
|
|||||||
case "mongodb":
|
case "mongodb":
|
||||||
return backupFromMongoDB(now)
|
return backupFromMongoDB(now)
|
||||||
default:
|
default:
|
||||||
return errors.New("unsupported database source backup to qiniu")
|
return errors.New("unsupported source backup to qiniu: " +
|
||||||
|
config.Conf.Database.Driver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreData implements timer.Storage
|
||||||
|
func (s Storage) RestoreData() error {
|
||||||
|
switch config.Conf.Database.Driver {
|
||||||
|
case "mongodb":
|
||||||
|
return restoreToMongoDB()
|
||||||
|
default:
|
||||||
|
return errors.New("unsupported source restore from qiniu: " +
|
||||||
|
config.Conf.Database.Driver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +58,7 @@ func backupFromMongoDB(now time.Time) error {
|
|||||||
}
|
}
|
||||||
// tar
|
// tar
|
||||||
name := fmt.Sprintf("eiblog-%s.tar.gz", now.Format("2006-01-02"))
|
name := fmt.Sprintf("eiblog-%s.tar.gz", now.Format("2006-01-02"))
|
||||||
arg = fmt.Sprintf("tar czf /tmp/%s /tmp/eiblog", name)
|
arg = fmt.Sprintf("tar czf /tmp/%s -C /tmp eiblog", name)
|
||||||
cmd = exec.CommandContext(ctx, "sh", "-c", arg)
|
cmd = exec.CommandContext(ctx, "sh", "-c", arg)
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -61,9 +75,10 @@ func backupFromMongoDB(now time.Time) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
uploadParams := internal.UploadParams{
|
uploadParams := internal.UploadParams{
|
||||||
Name: name,
|
Name: filepath.Join("blog", name), // blog/eiblog-xx.tar.gz
|
||||||
Size: s.Size(),
|
Size: s.Size(),
|
||||||
Data: f,
|
Data: f,
|
||||||
|
NoCompletePath: true,
|
||||||
|
|
||||||
Conf: config.Conf.BackupApp.Qiniu,
|
Conf: config.Conf.BackupApp.Qiniu,
|
||||||
}
|
}
|
||||||
@@ -73,10 +88,58 @@ func backupFromMongoDB(now time.Time) error {
|
|||||||
}
|
}
|
||||||
// after days delete
|
// after days delete
|
||||||
deleteParams := internal.DeleteParams{
|
deleteParams := internal.DeleteParams{
|
||||||
Name: name,
|
Name: name,
|
||||||
Days: config.Conf.BackupApp.Validity,
|
Days: config.Conf.BackupApp.Validity,
|
||||||
|
NoCompletePath: true,
|
||||||
|
|
||||||
Conf: config.Conf.BackupApp.Qiniu,
|
Conf: config.Conf.BackupApp.Qiniu,
|
||||||
}
|
}
|
||||||
return internal.QiniuDelete(deleteParams)
|
return internal.QiniuDelete(deleteParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func restoreToMongoDB() error {
|
||||||
|
// backup file
|
||||||
|
params := internal.ContentParams{
|
||||||
|
Prefix: "blog/",
|
||||||
|
|
||||||
|
Conf: config.Conf.BackupApp.Qiniu,
|
||||||
|
}
|
||||||
|
raw, err := internal.QiniuContent(params)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f, err := os.OpenFile("/tmp/eiblog.tar.gz", os.O_WRONLY|os.O_CREATE, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, _ = f.Write(raw)
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
|
||||||
|
defer cancel()
|
||||||
|
// drop database
|
||||||
|
store, err := store.NewStore(config.Conf.Database.Driver,
|
||||||
|
config.Conf.Database.Source)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = store.DropDatabase(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// unarchive
|
||||||
|
arg := fmt.Sprintf("tar xzf /tmp/eiblog.tar.gz -C /tmp")
|
||||||
|
cmd := exec.CommandContext(ctx, "sh", "-c", arg)
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// restore
|
||||||
|
u, err := url.Parse(config.Conf.Database.Source)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
arg = fmt.Sprintf("mongorestore -h %s -d eiblog /tmp/eiblog", u.Host)
|
||||||
|
cmd = exec.CommandContext(ctx, "sh", "-c", arg)
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Start to backup with ticker
|
// Start to backup with ticker
|
||||||
func Start() error {
|
func Start(restore bool) (err error) {
|
||||||
var storage Storage
|
var storage Storage
|
||||||
// backup instance
|
// backup instance
|
||||||
switch config.Conf.BackupApp.BackupTo {
|
switch config.Conf.BackupApp.BackupTo {
|
||||||
@@ -24,13 +24,18 @@ func Start() error {
|
|||||||
return errors.New("timer: unknown backup to driver: " +
|
return errors.New("timer: unknown backup to driver: " +
|
||||||
config.Conf.BackupApp.BackupTo)
|
config.Conf.BackupApp.BackupTo)
|
||||||
}
|
}
|
||||||
|
if restore {
|
||||||
|
err = storage.RestoreData()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logrus.Info("timer: RestoreData success")
|
||||||
|
}
|
||||||
// parse duration
|
// parse duration
|
||||||
interval, err := ParseDuration(config.Conf.BackupApp.Interval)
|
interval, err := ParseDuration(config.Conf.BackupApp.Interval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t := time.NewTicker(interval)
|
t := time.NewTicker(interval)
|
||||||
for now := range t.C {
|
for now := range t.C {
|
||||||
err = storage.BackupData(now)
|
err = storage.BackupData(now)
|
||||||
@@ -65,4 +70,5 @@ func ParseDuration(d string) (time.Duration, error) {
|
|||||||
// Storage backup backend
|
// Storage backup backend
|
||||||
type Storage interface {
|
type Storage interface {
|
||||||
BackupData(now time.Time) error
|
BackupData(now time.Time) error
|
||||||
|
RestoreData() error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ func handleAPIPostCreate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
// 旧文章
|
// 旧文章
|
||||||
article.ID = cid
|
article.ID = cid
|
||||||
artc, _ := cache.Ei.FindArticleByID(article.ID)
|
artc, _ := cache.Ei.FindArticleByID(article.ID) // cache
|
||||||
if artc != nil {
|
if artc != nil {
|
||||||
article.IsDraft = false
|
article.IsDraft = false
|
||||||
article.Count = artc.Count
|
article.Count = artc.Count
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ func init() {
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
xmlTmpl, err = template.New("").Funcs(template.FuncMap{
|
xmlTmpl, err = template.New("").Funcs(template.FuncMap{
|
||||||
"dateformat": tools.DateFormat,
|
"dateformat": tools.DateFormat,
|
||||||
|
"imgtonormal": tools.ImgToNormal,
|
||||||
}).ParseGlob(root)
|
}).ParseGlob(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ func handleAdminProfile(c *gin.Context) {
|
|||||||
renderHTMLAdminLayout(c, "admin-profile", params)
|
renderHTMLAdminLayout(c, "admin-profile", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// T tag struct
|
||||||
type T struct {
|
type T struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Tags string `json:"tags"`
|
Tags string `json:"tags"`
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package page
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
htemplate "html/template"
|
htemplate "html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -198,10 +200,11 @@ func handleDisqusList(c *gin.Context) {
|
|||||||
|
|
||||||
slug := c.Param("slug")
|
slug := c.Param("slug")
|
||||||
cursor := c.Query("cursor")
|
cursor := c.Query("cursor")
|
||||||
if artc := cache.Ei.ArticlesMap[slug]; artc != nil {
|
artc := cache.Ei.ArticlesMap[slug]
|
||||||
|
if artc != nil {
|
||||||
dcs.Data.Thread = artc.Thread
|
dcs.Data.Thread = artc.Thread
|
||||||
}
|
}
|
||||||
postsList, err := internal.PostsList(slug, cursor)
|
postsList, err := internal.PostsList(artc, cursor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error("hadnleDisqusList.PostsList: ", err)
|
logrus.Error("hadnleDisqusList.PostsList: ", err)
|
||||||
dcs.ErrNo = 0
|
dcs.ErrNo = 0
|
||||||
@@ -222,13 +225,25 @@ func handleDisqusList(c *gin.Context) {
|
|||||||
ID: v.ID,
|
ID: v.ID,
|
||||||
Name: v.Author.Name,
|
Name: v.Author.Name,
|
||||||
Parent: v.Parent,
|
Parent: v.Parent,
|
||||||
Url: v.Author.ProfileUrl,
|
URL: v.Author.ProfileURL,
|
||||||
Avatar: v.Author.Avatar.Cache,
|
Avatar: v.Author.Avatar.Cache,
|
||||||
CreatedAtStr: tools.ConvertStr(v.CreatedAt),
|
CreatedAtStr: tools.ConvertStr(v.CreatedAt),
|
||||||
Message: v.Message,
|
Message: v.Message,
|
||||||
IsDeleted: v.IsDeleted,
|
IsDeleted: v.IsDeleted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// query thread & update
|
||||||
|
if artc != nil && artc.Thread == "" {
|
||||||
|
if dcs.Data.Thread != "" {
|
||||||
|
artc.Thread = dcs.Data.Thread
|
||||||
|
} else if internal.ThreadDetails(artc) == nil {
|
||||||
|
dcs.Data.Thread = artc.Thread
|
||||||
|
}
|
||||||
|
cache.Ei.UpdateArticle(context.Background(), artc.ID,
|
||||||
|
map[string]interface{}{
|
||||||
|
"thread": artc.Thread,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleDisqusPage 评论页
|
// handleDisqusPage 评论页
|
||||||
@@ -240,7 +255,7 @@ func handleDisqusPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
article := cache.Ei.ArticlesMap[array[0]]
|
article := cache.Ei.ArticlesMap[array[0]]
|
||||||
params := gin.H{
|
params := gin.H{
|
||||||
"Titile": "发表评论 | " + cache.Ei.Blogger.BTitle,
|
"Title": "发表评论 | " + cache.Ei.Blogger.BTitle,
|
||||||
"ATitle": article.Title,
|
"ATitle": article.Title,
|
||||||
"Thread": array[1],
|
"Thread": array[1],
|
||||||
"Slug": article.Slug,
|
"Slug": article.Slug,
|
||||||
@@ -261,7 +276,7 @@ type commentsDetail struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Parent int `json:"parent"`
|
Parent int `json:"parent"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Url string `json:"url"`
|
URL string `json:"url"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
CreatedAtStr string `json:"createdAtStr"`
|
CreatedAtStr string `json:"createdAtStr"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
@@ -274,7 +289,7 @@ func handleDisqusCreate(c *gin.Context) {
|
|||||||
defer c.JSON(http.StatusOK, resp)
|
defer c.JSON(http.StatusOK, resp)
|
||||||
|
|
||||||
msg := c.PostForm("message")
|
msg := c.PostForm("message")
|
||||||
email := c.PostForm("author_name")
|
email := c.PostForm("author_email")
|
||||||
name := c.PostForm("author_name")
|
name := c.PostForm("author_name")
|
||||||
thread := c.PostForm("thread")
|
thread := c.PostForm("thread")
|
||||||
identifier := c.PostForm("identifier")
|
identifier := c.PostForm("identifier")
|
||||||
@@ -283,7 +298,7 @@ func handleDisqusCreate(c *gin.Context) {
|
|||||||
resp.ErrMsg = "参数错误"
|
resp.ErrMsg = "参数错误"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.Info("email: %s comments: %s", email, thread)
|
logrus.Infof("email: %s comments: %s", email, thread)
|
||||||
|
|
||||||
comment := internal.PostComment{
|
comment := internal.PostComment{
|
||||||
Message: msg,
|
Message: msg,
|
||||||
@@ -292,7 +307,7 @@ func handleDisqusCreate(c *gin.Context) {
|
|||||||
AuthorEmail: email,
|
AuthorEmail: email,
|
||||||
AuthorName: name,
|
AuthorName: name,
|
||||||
Identifier: identifier,
|
Identifier: identifier,
|
||||||
IpAddress: c.ClientIP(),
|
IPAddress: c.ClientIP(),
|
||||||
}
|
}
|
||||||
postDetail, err := internal.PostCreate(&comment)
|
postDetail, err := internal.PostCreate(&comment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -312,7 +327,7 @@ func handleDisqusCreate(c *gin.Context) {
|
|||||||
ID: postDetail.Response.ID,
|
ID: postDetail.Response.ID,
|
||||||
Name: name,
|
Name: name,
|
||||||
Parent: postDetail.Response.Parent,
|
Parent: postDetail.Response.Parent,
|
||||||
Url: postDetail.Response.Author.ProfileUrl,
|
URL: postDetail.Response.Author.ProfileURL,
|
||||||
Avatar: postDetail.Response.Author.Avatar.Cache,
|
Avatar: postDetail.Response.Author.Avatar.Cache,
|
||||||
CreatedAtStr: tools.ConvertStr(postDetail.Response.CreatedAt),
|
CreatedAtStr: tools.ConvertStr(postDetail.Response.CreatedAt),
|
||||||
Message: postDetail.Response.Message,
|
Message: postDetail.Response.Message,
|
||||||
@@ -321,27 +336,34 @@ func handleDisqusCreate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleBeaconPage 服务端推送谷歌统计
|
// handleBeaconPage 服务端推送谷歌统计
|
||||||
|
// https://www.thyngster.com/ga4-measurement-protocol-cheatsheet/
|
||||||
func handleBeaconPage(c *gin.Context) {
|
func handleBeaconPage(c *gin.Context) {
|
||||||
ua := c.Request.UserAgent()
|
ua := c.Request.UserAgent()
|
||||||
|
|
||||||
vals := c.Request.URL.Query()
|
vals := c.Request.URL.Query()
|
||||||
vals.Set("v", config.Conf.EiBlogApp.Google.V)
|
vals.Set("v", config.Conf.EiBlogApp.Google.V)
|
||||||
vals.Set("tid", config.Conf.EiBlogApp.Google.Tid)
|
vals.Set("tid", config.Conf.EiBlogApp.Google.Tid)
|
||||||
vals.Set("t", config.Conf.EiBlogApp.Google.T)
|
|
||||||
cookie, _ := c.Cookie("u")
|
cookie, _ := c.Cookie("u")
|
||||||
vals.Set("cid", cookie)
|
vals.Set("cid", cookie)
|
||||||
|
|
||||||
vals.Set("dl", c.Request.Referer())
|
vals.Set("dl", c.Request.Referer()) // document location
|
||||||
vals.Set("uip", c.ClientIP())
|
vals.Set("en", "page_view") // event name
|
||||||
|
vals.Set("sct", "1") // Session Count
|
||||||
|
vals.Set("seg", "1") // Session Engagment
|
||||||
|
vals.Set("_uip", c.ClientIP()) // user ip
|
||||||
|
vals.Set("_p", fmt.Sprint(201226219+rand.Intn(499999999))) // random page load hash
|
||||||
|
vals.Set("_ee", "1") // external event
|
||||||
go func() {
|
go func() {
|
||||||
req, err := http.NewRequest("POST", config.Conf.EiBlogApp.Google.URL,
|
url := config.Conf.EiBlogApp.Google.URL + "?" + vals.Encode()
|
||||||
strings.NewReader(vals.Encode()))
|
req, err := http.NewRequest("POST", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error("HandleBeaconPage.NewRequest: ", err)
|
logrus.Error("HandleBeaconPage.NewRequest: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.Header.Set("User-Agent", ua)
|
req.Header.Set("User-Agent", ua)
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Sec-Ch-Ua", c.GetHeader("Sec-Ch-Ua"))
|
||||||
|
req.Header.Set("Sec-Ch-Ua-Platform", c.GetHeader("Sec-Ch-Ua-Platform"))
|
||||||
|
req.Header.Set("Sec-Ch-Ua-Mobile", c.GetHeader("Sec-Ch-Ua-Mobile"))
|
||||||
res, err := http.DefaultClient.Do(req)
|
res, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error("HandleBeaconPage.Do: ", err)
|
logrus.Error("HandleBeaconPage.Do: ", err)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package page
|
package page
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/fs"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@@ -17,10 +18,15 @@ var htmlTmpl *template.Template
|
|||||||
func init() {
|
func init() {
|
||||||
htmlTmpl = template.New("eiblog").Funcs(tools.TplFuncMap)
|
htmlTmpl = template.New("eiblog").Funcs(tools.TplFuncMap)
|
||||||
root := filepath.Join(config.WorkDir, "website")
|
root := filepath.Join(config.WorkDir, "website")
|
||||||
files := tools.ReadDirFiles(root, func(name string) bool {
|
files := tools.ReadDirFiles(root, func(fi fs.FileInfo) bool {
|
||||||
|
name := fi.Name()
|
||||||
if name == ".DS_Store" {
|
if name == ".DS_Store" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
// should not read template dir
|
||||||
|
if fi.IsDir() && name == "template" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
_, err := htmlTmpl.ParseFiles(files...)
|
_, err := htmlTmpl.ParseFiles(files...)
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
_ "github.com/eiblog/eiblog/pkg/core/eiblog/docs" // docs
|
_ "github.com/eiblog/eiblog/pkg/core/eiblog/docs" // docs
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
swaggerFiles "github.com/swaggo/files"
|
||||||
ginSwagger "github.com/swaggo/gin-swagger"
|
ginSwagger "github.com/swaggo/gin-swagger"
|
||||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterRoutes register routes
|
// RegisterRoutes register routes
|
||||||
|
|||||||
@@ -16,11 +16,14 @@ import (
|
|||||||
|
|
||||||
// disqus api
|
// disqus api
|
||||||
const (
|
const (
|
||||||
apiPostsCount = "https://disqus.com/api/3.0/threads/set.json"
|
apiPostsCount = "https://disqus.com/api/3.0/threads/set.json"
|
||||||
apiPostsList = "https://disqus.com/api/3.0/threads/listPosts.json"
|
apiPostsList = "https://disqus.com/api/3.0/threads/listPostsThreaded"
|
||||||
apiPostCreate = "https://disqus.com/api/3.0/posts/create.json"
|
apiPostCreate = "https://disqus.com/api/3.0/posts/create.json"
|
||||||
apiPostApprove = "https://disqus.com/api/3.0/posts/approve.json"
|
apiPostApprove = "https://disqus.com/api/3.0/posts/approve.json"
|
||||||
apiThreadCreate = "https://disqus.com/api/3.0/threads/create.json"
|
apiThreadCreate = "https://disqus.com/api/3.0/threads/create.json"
|
||||||
|
apiThreadDetails = "https://disqus.com/api/3.0/threads/details.json"
|
||||||
|
|
||||||
|
disqusAPIKey = "E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkDisqusConfig() error {
|
func checkDisqusConfig() error {
|
||||||
@@ -95,8 +98,8 @@ func PostsCount(articles map[string]*model.Article) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// postsListResp 获取评论列表
|
// PostsListResp 获取评论列表
|
||||||
type postsListResp struct {
|
type PostsListResp struct {
|
||||||
Cursor struct {
|
Cursor struct {
|
||||||
HasNext bool
|
HasNext bool
|
||||||
Next string
|
Next string
|
||||||
@@ -113,7 +116,7 @@ type postDetail struct {
|
|||||||
IsDeleted bool
|
IsDeleted bool
|
||||||
Author struct {
|
Author struct {
|
||||||
Name string
|
Name string
|
||||||
ProfileUrl string
|
ProfileURL string
|
||||||
Avatar struct {
|
Avatar struct {
|
||||||
Cache string
|
Cache string
|
||||||
}
|
}
|
||||||
@@ -122,16 +125,17 @@ type postDetail struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PostsList 评论列表
|
// PostsList 评论列表
|
||||||
func PostsList(slug, cursor string) (*postsListResp, error) {
|
func PostsList(article *model.Article, cursor string) (*PostsListResp, error) {
|
||||||
if err := checkDisqusConfig(); err != nil {
|
if err := checkDisqusConfig(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
vals := url.Values{}
|
vals := url.Values{}
|
||||||
vals.Set("api_key", config.Conf.EiBlogApp.Disqus.PublicKey)
|
vals.Set("api_key", disqusAPIKey)
|
||||||
vals.Set("forum", config.Conf.EiBlogApp.Disqus.ShortName)
|
vals.Set("forum", config.Conf.EiBlogApp.Disqus.ShortName)
|
||||||
vals.Set("thread:ident", "post-"+slug)
|
vals.Set("thread", article.Thread)
|
||||||
vals.Set("cursor", cursor)
|
vals.Set("cursor", cursor)
|
||||||
|
vals.Set("order", "popular")
|
||||||
vals.Set("limit", "50")
|
vals.Set("limit", "50")
|
||||||
|
|
||||||
resp, err := httpGet(apiPostsList + "?" + vals.Encode())
|
resp, err := httpGet(apiPostsList + "?" + vals.Encode())
|
||||||
@@ -148,7 +152,7 @@ func PostsList(slug, cursor string) (*postsListResp, error) {
|
|||||||
return nil, errors.New(string(b))
|
return nil, errors.New(string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
result := &postsListResp{}
|
result := &PostsListResp{}
|
||||||
err = json.Unmarshal(b, result)
|
err = json.Unmarshal(b, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -163,23 +167,24 @@ type PostComment struct {
|
|||||||
Thread string
|
Thread string
|
||||||
AuthorEmail string
|
AuthorEmail string
|
||||||
AuthorName string
|
AuthorName string
|
||||||
IpAddress string
|
IPAddress string
|
||||||
Identifier string
|
Identifier string
|
||||||
UserAgent string
|
UserAgent string
|
||||||
}
|
}
|
||||||
|
|
||||||
type postCreateResp struct {
|
// PostCreateResp create comments resp
|
||||||
|
type PostCreateResp struct {
|
||||||
Code int
|
Code int
|
||||||
Response postDetail
|
Response postDetail
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostCreate 评论文章
|
// PostCreate 评论文章
|
||||||
func PostCreate(pc *PostComment) (*postCreateResp, error) {
|
func PostCreate(pc *PostComment) (*PostCreateResp, error) {
|
||||||
if err := checkDisqusConfig(); err != nil {
|
if err := checkDisqusConfig(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
vals := url.Values{}
|
vals := url.Values{}
|
||||||
vals.Set("api_key", "E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F")
|
vals.Set("api_key", disqusAPIKey)
|
||||||
vals.Set("message", pc.Message)
|
vals.Set("message", pc.Message)
|
||||||
vals.Set("parent", pc.Parent)
|
vals.Set("parent", pc.Parent)
|
||||||
vals.Set("thread", pc.Thread)
|
vals.Set("thread", pc.Thread)
|
||||||
@@ -201,7 +206,7 @@ func PostCreate(pc *PostComment) (*postCreateResp, error) {
|
|||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, errors.New(string(b))
|
return nil, errors.New(string(b))
|
||||||
}
|
}
|
||||||
result := &postCreateResp{}
|
result := &PostCreateResp{}
|
||||||
err = json.Unmarshal(b, result)
|
err = json.Unmarshal(b, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -294,3 +299,46 @@ func ThreadCreate(article *model.Article, btitle string) error {
|
|||||||
article.Thread = result.Response.ID
|
article.Thread = result.Response.ID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// threadDetailsResp thread info
|
||||||
|
type threadDetailsResp struct {
|
||||||
|
Code int
|
||||||
|
Response struct {
|
||||||
|
ID string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ThreadDetails thread详细
|
||||||
|
func ThreadDetails(article *model.Article) error {
|
||||||
|
if err := checkDisqusConfig(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
vals := url.Values{}
|
||||||
|
vals.Set("api_key", config.Conf.EiBlogApp.Disqus.PublicKey)
|
||||||
|
vals.Set("access_token", config.Conf.EiBlogApp.Disqus.AccessToken)
|
||||||
|
vals.Set("forum", config.Conf.EiBlogApp.Disqus.ShortName)
|
||||||
|
vals.Set("thread:ident", "post-"+article.Slug)
|
||||||
|
|
||||||
|
resp, err := httpGet(apiThreadDetails + "?" + vals.Encode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return errors.New(string(b))
|
||||||
|
}
|
||||||
|
|
||||||
|
result := &threadDetailsResp{}
|
||||||
|
err = json.Unmarshal(b, result)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
article.Thread = result.Response.ID
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func checkESConfig() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ElasticSearch 搜索文章
|
// ElasticSearch 搜索文章
|
||||||
func ElasticSearch(query string, size, from int) (*searchIndexResult, error) {
|
func ElasticSearch(query string, size, from int) (*SearchIndexResult, error) {
|
||||||
if err := checkESConfig(); err != nil {
|
if err := checkESConfig(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ func ElasticAddIndex(article *model.Article) error {
|
|||||||
img := tools.PickFirstImage(article.Content)
|
img := tools.PickFirstImage(article.Content)
|
||||||
mapping := map[string]interface{}{
|
mapping := map[string]interface{}{
|
||||||
"title": article.Title,
|
"title": article.Title,
|
||||||
"content": tools.IgnoreHtmlTag(article.Content),
|
"content": tools.IgnoreHTMLTag(article.Content),
|
||||||
"slug": article.Slug,
|
"slug": article.Slug,
|
||||||
"tag": article.Tags,
|
"tag": article.Tags,
|
||||||
"img": img,
|
"img": img,
|
||||||
@@ -241,8 +241,8 @@ func deleteIndexDocument(index, typ string, ids []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// searchIndexResult 查询结果
|
// SearchIndexResult 查询结果
|
||||||
type searchIndexResult struct {
|
type SearchIndexResult struct {
|
||||||
Took float32 `json:"took"`
|
Took float32 `json:"took"`
|
||||||
Hits struct {
|
Hits struct {
|
||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
@@ -264,7 +264,7 @@ type searchIndexResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// indexQueryDSL 语句查询文档
|
// indexQueryDSL 语句查询文档
|
||||||
func indexQueryDSL(index, typ string, size, from int, dsl []byte) (*searchIndexResult, error) {
|
func indexQueryDSL(index, typ string, size, from int, dsl []byte) (*SearchIndexResult, error) {
|
||||||
rawurl := fmt.Sprintf("%s/%s/%s/_search?size=%d&from=%d", config.Conf.ESHost,
|
rawurl := fmt.Sprintf("%s/%s/%s/_search?size=%d&from=%d", config.Conf.ESHost,
|
||||||
index, typ, size, from)
|
index, typ, size, from)
|
||||||
resp, err := httpPost(rawurl, dsl)
|
resp, err := httpPost(rawurl, dsl)
|
||||||
@@ -276,7 +276,7 @@ func indexQueryDSL(index, typ string, size, from int, dsl []byte) (*searchIndexR
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result := &searchIndexResult{}
|
result := &SearchIndexResult{}
|
||||||
err = json.Unmarshal(data, result)
|
err = json.Unmarshal(data, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/eiblog/eiblog/pkg/config"
|
"github.com/eiblog/eiblog/pkg/config"
|
||||||
|
|
||||||
@@ -15,9 +17,10 @@ import (
|
|||||||
|
|
||||||
// UploadParams upload params
|
// UploadParams upload params
|
||||||
type UploadParams struct {
|
type UploadParams struct {
|
||||||
Name string
|
Name string
|
||||||
Size int64
|
Size int64
|
||||||
Data io.Reader
|
Data io.Reader
|
||||||
|
NoCompletePath bool
|
||||||
|
|
||||||
Conf config.Qiniu
|
Conf config.Qiniu
|
||||||
}
|
}
|
||||||
@@ -28,7 +31,10 @@ func QiniuUpload(params UploadParams) (string, error) {
|
|||||||
params.Conf.SecretKey == "" {
|
params.Conf.SecretKey == "" {
|
||||||
return "", errors.New("qiniu config error")
|
return "", errors.New("qiniu config error")
|
||||||
}
|
}
|
||||||
key := completeQiniuKey(params.Name)
|
key := params.Name
|
||||||
|
if !params.NoCompletePath {
|
||||||
|
key = filepath.Base(params.Name)
|
||||||
|
}
|
||||||
|
|
||||||
mac := qbox.NewMac(params.Conf.AccessKey,
|
mac := qbox.NewMac(params.Conf.AccessKey,
|
||||||
params.Conf.SecretKey)
|
params.Conf.SecretKey)
|
||||||
@@ -65,15 +71,19 @@ func QiniuUpload(params UploadParams) (string, error) {
|
|||||||
|
|
||||||
// DeleteParams delete params
|
// DeleteParams delete params
|
||||||
type DeleteParams struct {
|
type DeleteParams struct {
|
||||||
Name string
|
Name string
|
||||||
Days int
|
Days int
|
||||||
|
NoCompletePath bool
|
||||||
|
|
||||||
Conf config.Qiniu
|
Conf config.Qiniu
|
||||||
}
|
}
|
||||||
|
|
||||||
// QiniuDelete 删除文件
|
// QiniuDelete 删除文件
|
||||||
func QiniuDelete(params DeleteParams) error {
|
func QiniuDelete(params DeleteParams) error {
|
||||||
key := completeQiniuKey(params.Name)
|
key := params.Name
|
||||||
|
if !params.NoCompletePath {
|
||||||
|
key = completeQiniuKey(params.Name)
|
||||||
|
}
|
||||||
|
|
||||||
mac := qbox.NewMac(params.Conf.AccessKey,
|
mac := qbox.NewMac(params.Conf.AccessKey,
|
||||||
params.Conf.SecretKey)
|
params.Conf.SecretKey)
|
||||||
@@ -95,6 +105,47 @@ func QiniuDelete(params DeleteParams) error {
|
|||||||
return bucketManager.Delete(params.Conf.Bucket, key)
|
return bucketManager.Delete(params.Conf.Bucket, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContentParams list params
|
||||||
|
type ContentParams struct {
|
||||||
|
Prefix string
|
||||||
|
|
||||||
|
Conf config.Qiniu
|
||||||
|
}
|
||||||
|
|
||||||
|
// QiniuContent 获取文件列表
|
||||||
|
func QiniuContent(params ContentParams) ([]byte, error) {
|
||||||
|
mac := qbox.NewMac(params.Conf.AccessKey,
|
||||||
|
params.Conf.SecretKey)
|
||||||
|
// region
|
||||||
|
region, err := storage.GetRegion(params.Conf.AccessKey, params.Conf.Bucket)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cfg := &storage.Config{
|
||||||
|
UseHTTPS: true,
|
||||||
|
Region: region,
|
||||||
|
}
|
||||||
|
// manager
|
||||||
|
bucketManager := storage.NewBucketManager(mac, cfg)
|
||||||
|
// list file
|
||||||
|
files, _, _, _, err := bucketManager.ListFiles(params.Conf.Bucket, params.Prefix, "", "", 1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(files) == 0 {
|
||||||
|
return nil, errors.New("no file")
|
||||||
|
}
|
||||||
|
deadline := time.Now().Add(time.Second * 60).Unix()
|
||||||
|
url := storage.MakePrivateURLv2(mac, "https://"+params.Conf.Domain, files[0].Key, deadline)
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
return io.ReadAll(resp.Body)
|
||||||
|
}
|
||||||
|
|
||||||
// completeQiniuKey 修复路径
|
// completeQiniuKey 修复路径
|
||||||
func completeQiniuKey(name string) string {
|
func completeQiniuKey(name string) string {
|
||||||
ext := filepath.Ext(name)
|
ext := filepath.Ext(name)
|
||||||
|
|||||||
@@ -46,3 +46,18 @@ func TestQiniuUpload(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestQiniuContent(t *testing.T) {
|
||||||
|
params := ContentParams{
|
||||||
|
Conf: config.Qiniu{
|
||||||
|
AccessKey: os.Getenv("QINIU_ACCESSKEY"),
|
||||||
|
SecretKey: os.Getenv("QINIU_SECRETKEY"),
|
||||||
|
Bucket: os.Getenv("QINIU_BUCKET"),
|
||||||
|
Domain: "bu.st.deepzz.com",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, err := QiniuContent(params)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("QiniuList error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ type Article struct {
|
|||||||
SerieID int `gorm:"column:serie_id;not null" bson:"serie_id"` // 专题ID
|
SerieID int `gorm:"column:serie_id;not null" bson:"serie_id"` // 专题ID
|
||||||
Tags pq.StringArray `gorm:"column:tags;type:text[]" bson:"tags"` // tags
|
Tags pq.StringArray `gorm:"column:tags;type:text[]" bson:"tags"` // tags
|
||||||
IsDraft bool `gorm:"column:is_draft;not null" bson:"is_draft"` // 是否是草稿
|
IsDraft bool `gorm:"column:is_draft;not null" bson:"is_draft"` // 是否是草稿
|
||||||
|
Thread string `gorm:"column:thread" bson:"thread"` // disqus thread
|
||||||
|
|
||||||
DeletedAt time.Time `gorm:"column:deleted_at;not null" bson:"deleted_at"` // 删除时间
|
DeletedAt time.Time `gorm:"column:deleted_at;not null" bson:"deleted_at"` // 删除时间
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;default:current_timestamp" bson:"updated_at"` // 更新时间
|
UpdatedAt time.Time `gorm:"column:updated_at;default:current_timestamp" bson:"updated_at"` // 更新时间
|
||||||
@@ -28,7 +29,6 @@ type Article struct {
|
|||||||
Header string `gorm:"-" bson:"-"` // header
|
Header string `gorm:"-" bson:"-"` // header
|
||||||
Excerpt string `gorm:"-" bson:"-"` // 预览信息
|
Excerpt string `gorm:"-" bson:"-"` // 预览信息
|
||||||
Desc string `gorm:"-" bson:"-"` // 描述
|
Desc string `gorm:"-" bson:"-"` // 描述
|
||||||
Thread string `gorm:"-" bson:"-"` // disqus thread
|
|
||||||
Prev *Article `gorm:"-" bson:"-"` // 上篇文章
|
Prev *Article `gorm:"-" bson:"-"` // 上篇文章
|
||||||
Next *Article `gorm:"-" bson:"-"` // 下篇文章
|
Next *Article `gorm:"-" bson:"-"` // 下篇文章
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
.PHONY: protoc
|
|
||||||
|
|
||||||
protoc:
|
|
||||||
@${PWD}/protoc.sh
|
|
||||||
@@ -1,226 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
|
||||||
// versions:
|
|
||||||
// protoc-gen-go v1.25.0
|
|
||||||
// protoc v3.13.0
|
|
||||||
// source: cmd-demo/demo.proto
|
|
||||||
|
|
||||||
package cmd_demo
|
|
||||||
|
|
||||||
import (
|
|
||||||
proto "github.com/golang/protobuf/proto"
|
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
reflect "reflect"
|
|
||||||
sync "sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Verify that this generated code is sufficiently up-to-date.
|
|
||||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
|
||||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
|
||||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
|
||||||
)
|
|
||||||
|
|
||||||
// This is a compile-time assertion that a sufficiently up-to-date version
|
|
||||||
// of the legacy proto package is being used.
|
|
||||||
const _ = proto.ProtoPackageIsVersion4
|
|
||||||
|
|
||||||
type UserInfoReq struct {
|
|
||||||
state protoimpl.MessageState
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
|
|
||||||
UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *UserInfoReq) Reset() {
|
|
||||||
*x = UserInfoReq{}
|
|
||||||
if protoimpl.UnsafeEnabled {
|
|
||||||
mi := &file_cmd_demo_demo_proto_msgTypes[0]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *UserInfoReq) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UserInfoReq) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *UserInfoReq) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_cmd_demo_demo_proto_msgTypes[0]
|
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
if ms.LoadMessageInfo() == nil {
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
return mi.MessageOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Use UserInfoReq.ProtoReflect.Descriptor instead.
|
|
||||||
func (*UserInfoReq) Descriptor() ([]byte, []int) {
|
|
||||||
return file_cmd_demo_demo_proto_rawDescGZIP(), []int{0}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *UserInfoReq) GetUserId() int64 {
|
|
||||||
if x != nil {
|
|
||||||
return x.UserId
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserInfoResp struct {
|
|
||||||
state protoimpl.MessageState
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
|
|
||||||
UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
|
||||||
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *UserInfoResp) Reset() {
|
|
||||||
*x = UserInfoResp{}
|
|
||||||
if protoimpl.UnsafeEnabled {
|
|
||||||
mi := &file_cmd_demo_demo_proto_msgTypes[1]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *UserInfoResp) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UserInfoResp) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *UserInfoResp) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_cmd_demo_demo_proto_msgTypes[1]
|
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
if ms.LoadMessageInfo() == nil {
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
return mi.MessageOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Use UserInfoResp.ProtoReflect.Descriptor instead.
|
|
||||||
func (*UserInfoResp) Descriptor() ([]byte, []int) {
|
|
||||||
return file_cmd_demo_demo_proto_rawDescGZIP(), []int{1}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *UserInfoResp) GetUserId() int64 {
|
|
||||||
if x != nil {
|
|
||||||
return x.UserId
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *UserInfoResp) GetUsername() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Username
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var File_cmd_demo_demo_proto protoreflect.FileDescriptor
|
|
||||||
|
|
||||||
var file_cmd_demo_demo_proto_rawDesc = []byte{
|
|
||||||
0x0a, 0x13, 0x63, 0x6d, 0x64, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x64, 0x65, 0x6d, 0x6f, 0x2e,
|
|
||||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x64, 0x65, 0x6d, 0x6f, 0x22, 0x26, 0x0a, 0x0b, 0x55,
|
|
||||||
0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73,
|
|
||||||
0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65,
|
|
||||||
0x72, 0x49, 0x64, 0x22, 0x43, 0x0a, 0x0c, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52,
|
|
||||||
0x65, 0x73, 0x70, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01,
|
|
||||||
0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08,
|
|
||||||
0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
|
|
||||||
0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x32, 0x3b, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72,
|
|
||||||
0x12, 0x33, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x11, 0x2e, 0x64,
|
|
||||||
0x65, 0x6d, 0x6f, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a,
|
|
||||||
0x12, 0x2e, 0x64, 0x65, 0x6d, 0x6f, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52,
|
|
||||||
0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x19, 0x5a, 0x17, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63,
|
|
||||||
0x6d, 0x64, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x3b, 0x63, 0x6d, 0x64, 0x5f, 0x64, 0x65, 0x6d, 0x6f,
|
|
||||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
file_cmd_demo_demo_proto_rawDescOnce sync.Once
|
|
||||||
file_cmd_demo_demo_proto_rawDescData = file_cmd_demo_demo_proto_rawDesc
|
|
||||||
)
|
|
||||||
|
|
||||||
func file_cmd_demo_demo_proto_rawDescGZIP() []byte {
|
|
||||||
file_cmd_demo_demo_proto_rawDescOnce.Do(func() {
|
|
||||||
file_cmd_demo_demo_proto_rawDescData = protoimpl.X.CompressGZIP(file_cmd_demo_demo_proto_rawDescData)
|
|
||||||
})
|
|
||||||
return file_cmd_demo_demo_proto_rawDescData
|
|
||||||
}
|
|
||||||
|
|
||||||
var file_cmd_demo_demo_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
|
||||||
var file_cmd_demo_demo_proto_goTypes = []interface{}{
|
|
||||||
(*UserInfoReq)(nil), // 0: demo.UserInfoReq
|
|
||||||
(*UserInfoResp)(nil), // 1: demo.UserInfoResp
|
|
||||||
}
|
|
||||||
var file_cmd_demo_demo_proto_depIdxs = []int32{
|
|
||||||
0, // 0: demo.User.UserInfo:input_type -> demo.UserInfoReq
|
|
||||||
1, // 1: demo.User.UserInfo:output_type -> demo.UserInfoResp
|
|
||||||
1, // [1:2] is the sub-list for method output_type
|
|
||||||
0, // [0:1] is the sub-list for method input_type
|
|
||||||
0, // [0:0] is the sub-list for extension type_name
|
|
||||||
0, // [0:0] is the sub-list for extension extendee
|
|
||||||
0, // [0:0] is the sub-list for field type_name
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { file_cmd_demo_demo_proto_init() }
|
|
||||||
func file_cmd_demo_demo_proto_init() {
|
|
||||||
if File_cmd_demo_demo_proto != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !protoimpl.UnsafeEnabled {
|
|
||||||
file_cmd_demo_demo_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
|
||||||
switch v := v.(*UserInfoReq); i {
|
|
||||||
case 0:
|
|
||||||
return &v.state
|
|
||||||
case 1:
|
|
||||||
return &v.sizeCache
|
|
||||||
case 2:
|
|
||||||
return &v.unknownFields
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file_cmd_demo_demo_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
|
||||||
switch v := v.(*UserInfoResp); i {
|
|
||||||
case 0:
|
|
||||||
return &v.state
|
|
||||||
case 1:
|
|
||||||
return &v.sizeCache
|
|
||||||
case 2:
|
|
||||||
return &v.unknownFields
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
type x struct{}
|
|
||||||
out := protoimpl.TypeBuilder{
|
|
||||||
File: protoimpl.DescBuilder{
|
|
||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
|
||||||
RawDescriptor: file_cmd_demo_demo_proto_rawDesc,
|
|
||||||
NumEnums: 0,
|
|
||||||
NumMessages: 2,
|
|
||||||
NumExtensions: 0,
|
|
||||||
NumServices: 1,
|
|
||||||
},
|
|
||||||
GoTypes: file_cmd_demo_demo_proto_goTypes,
|
|
||||||
DependencyIndexes: file_cmd_demo_demo_proto_depIdxs,
|
|
||||||
MessageInfos: file_cmd_demo_demo_proto_msgTypes,
|
|
||||||
}.Build()
|
|
||||||
File_cmd_demo_demo_proto = out.File
|
|
||||||
file_cmd_demo_demo_proto_rawDesc = nil
|
|
||||||
file_cmd_demo_demo_proto_goTypes = nil
|
|
||||||
file_cmd_demo_demo_proto_depIdxs = nil
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
option go_package = "proto/cmd-demo;cmd_demo";
|
|
||||||
|
|
||||||
package demo;
|
|
||||||
|
|
||||||
message UserInfoReq {
|
|
||||||
int64 user_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UserInfoResp {
|
|
||||||
int64 user_id = 1;
|
|
||||||
string username = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// User service
|
|
||||||
service User {
|
|
||||||
rpc UserInfo(UserInfoReq) returns (UserInfoResp) {}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
|
||||||
|
|
||||||
package cmd_demo
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
codes "google.golang.org/grpc/codes"
|
|
||||||
status "google.golang.org/grpc/status"
|
|
||||||
)
|
|
||||||
|
|
||||||
// This is a compile-time assertion to ensure that this generated file
|
|
||||||
// is compatible with the grpc package it is being compiled against.
|
|
||||||
const _ = grpc.SupportPackageIsVersion7
|
|
||||||
|
|
||||||
// UserClient is the client API for User service.
|
|
||||||
//
|
|
||||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
|
||||||
type UserClient interface {
|
|
||||||
UserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*UserInfoResp, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type userClient struct {
|
|
||||||
cc grpc.ClientConnInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewUserClient(cc grpc.ClientConnInterface) UserClient {
|
|
||||||
return &userClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *userClient) UserInfo(ctx context.Context, in *UserInfoReq, opts ...grpc.CallOption) (*UserInfoResp, error) {
|
|
||||||
out := new(UserInfoResp)
|
|
||||||
err := c.cc.Invoke(ctx, "/demo.User/UserInfo", in, out, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserServer is the server API for User service.
|
|
||||||
// All implementations must embed UnimplementedUserServer
|
|
||||||
// for forward compatibility
|
|
||||||
type UserServer interface {
|
|
||||||
UserInfo(context.Context, *UserInfoReq) (*UserInfoResp, error)
|
|
||||||
mustEmbedUnimplementedUserServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnimplementedUserServer must be embedded to have forward compatible implementations.
|
|
||||||
type UnimplementedUserServer struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (UnimplementedUserServer) UserInfo(context.Context, *UserInfoReq) (*UserInfoResp, error) {
|
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method UserInfo not implemented")
|
|
||||||
}
|
|
||||||
func (UnimplementedUserServer) mustEmbedUnimplementedUserServer() {}
|
|
||||||
|
|
||||||
// UnsafeUserServer may be embedded to opt out of forward compatibility for this service.
|
|
||||||
// Use of this interface is not recommended, as added methods to UserServer will
|
|
||||||
// result in compilation errors.
|
|
||||||
type UnsafeUserServer interface {
|
|
||||||
mustEmbedUnimplementedUserServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterUserServer(s grpc.ServiceRegistrar, srv UserServer) {
|
|
||||||
s.RegisterService(&_User_serviceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _User_UserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(UserInfoReq)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(UserServer).UserInfo(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: "/demo.User/UserInfo",
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(UserServer).UserInfo(ctx, req.(*UserInfoReq))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _User_serviceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "demo.User",
|
|
||||||
HandlerType: (*UserServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "UserInfo",
|
|
||||||
Handler: _User_UserInfo_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{},
|
|
||||||
Metadata: "cmd-demo/demo.proto",
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
for file in */*.proto; do
|
|
||||||
if test -f $file; then
|
|
||||||
protoc --go_out=. --go_opt=paths=source_relative \
|
|
||||||
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
|
||||||
$file;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
@@ -10,8 +10,8 @@ for file in pkg/core/*; do
|
|||||||
# tar platform
|
# tar platform
|
||||||
for os in linux darwin windows; do
|
for os in linux darwin windows; do
|
||||||
_target="$app-$_tag.$os-$_arch.tar.gz"
|
_target="$app-$_tag.$os-$_arch.tar.gz"
|
||||||
CGO_ENABLED=0 GOOS=$os GOARCH=$_arch \
|
GOOS=$os GOARCH=$_arch \
|
||||||
go build -tags prod -o backend "./cmd/$app"
|
go build -tags prod -ldflags '-extldflags "-static"' -o backend "./cmd/$app"
|
||||||
if [ "$app" = "eiblog" ]; then
|
if [ "$app" = "eiblog" ]; then
|
||||||
tar czf $_target conf website assets backend
|
tar czf $_target conf website assets backend
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,33 +1,3 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
_registry="$1"
|
go build -tags prod -ldflags '-extldflags "-static"' -o bin/backend "./cmd/$1"
|
||||||
_tag="$2"
|
|
||||||
_platform="linux/amd64,linux/arm64,linux/386"
|
|
||||||
|
|
||||||
if [ -z "$_registry" ] || [ -z "$_tag" ]; then
|
|
||||||
echo "Please specify image repository and tag."
|
|
||||||
exit 0;
|
|
||||||
fi
|
|
||||||
|
|
||||||
# create and use builder
|
|
||||||
docker buildx inspect builder >/dev/null 2>&1
|
|
||||||
if [ "$?" != "0" ]; then
|
|
||||||
docker buildx create --use --name builder
|
|
||||||
fi
|
|
||||||
|
|
||||||
# prepare dir ./bin
|
|
||||||
mkdir -p ./bin
|
|
||||||
# build demo app
|
|
||||||
for file in pkg/core/*; do
|
|
||||||
app="$(basename $file)";
|
|
||||||
CGO_ENABLED=0 go build -tags prod -o bin/backend "./cmd/$app"
|
|
||||||
# docker image
|
|
||||||
docker buildx build --platform "$_platform" \
|
|
||||||
-f "build/package/$app.Dockerfile" \
|
|
||||||
-t "$_registry/$app:latest" \
|
|
||||||
-t "$_registry/$app:$_tag" \
|
|
||||||
--push .
|
|
||||||
done
|
|
||||||
|
|
||||||
# clean dir ./bin
|
|
||||||
rm -rf ./bin
|
|
||||||
|
|||||||
@@ -73,3 +73,8 @@ func GetAvatar(domain string) string {
|
|||||||
|
|
||||||
return avatar
|
return avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImgToNormal replace lazy image attr data-src to src
|
||||||
|
func ImgToNormal(content string) string {
|
||||||
|
return strings.ReplaceAll(content, "data-src=", "src=")
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -22,13 +23,13 @@ func EncryptPasswd(name, pass string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadDirFiles 读取目录
|
// ReadDirFiles 读取目录
|
||||||
func ReadDirFiles(dir string, filter func(name string) bool) (files []string) {
|
func ReadDirFiles(dir string, filter func(fi fs.FileInfo) bool) (files []string) {
|
||||||
fileInfos, err := ioutil.ReadDir(dir)
|
fileInfos, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, fi := range fileInfos {
|
for _, fi := range fileInfos {
|
||||||
if filter(fi.Name()) {
|
if filter(fi) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
@@ -42,19 +43,19 @@ func ReadDirFiles(dir string, filter func(name string) bool) (files []string) {
|
|||||||
|
|
||||||
// 2016-10-22T07:03:01
|
// 2016-10-22T07:03:01
|
||||||
const (
|
const (
|
||||||
JUST_NOW = "几秒前"
|
JustNow = "几秒前"
|
||||||
MINUTES_AGO = "%d分钟前"
|
MinutesAgo = "%d分钟前"
|
||||||
HOURS_AGO = "%d小时前"
|
HoursAgo = "%d小时前"
|
||||||
DAYS_AGO = "%d天前"
|
DaysAgo = "%d天前"
|
||||||
MONTH_AGO = "%d月前"
|
MonthAgo = "%d月前"
|
||||||
YEARS_AGO = "%d年前"
|
YearsAgo = "%d年前"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConvertStr 时间转换为间隔
|
// ConvertStr 时间转换为间隔
|
||||||
func ConvertStr(str string) string {
|
func ConvertStr(str string) string {
|
||||||
t, err := time.ParseInLocation("2006-01-02T15:04:05", str, time.UTC)
|
t, err := time.ParseInLocation("2006-01-02T15:04:05", str, time.UTC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return JUST_NOW
|
return JustNow
|
||||||
}
|
}
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
y1, m1, d1 := t.Date()
|
y1, m1, d1 := t.Date()
|
||||||
@@ -62,17 +63,17 @@ func ConvertStr(str string) string {
|
|||||||
h1, mi1, s1 := t.Clock()
|
h1, mi1, s1 := t.Clock()
|
||||||
h2, mi2, s2 := now.Clock()
|
h2, mi2, s2 := now.Clock()
|
||||||
if y := y2 - y1; y > 1 || (y == 1 && m2-m1 >= 0) {
|
if y := y2 - y1; y > 1 || (y == 1 && m2-m1 >= 0) {
|
||||||
return fmt.Sprintf(YEARS_AGO, y)
|
return fmt.Sprintf(YearsAgo, y)
|
||||||
} else if m := y*12 + int(m2-m1); m > 1 || (m == 1 && d2-d1 >= 0) {
|
} else if m := y*12 + int(m2-m1); m > 1 || (m == 1 && d2-d1 >= 0) {
|
||||||
return fmt.Sprintf(MONTH_AGO, m)
|
return fmt.Sprintf(MonthAgo, m)
|
||||||
} else if d := m*dayIn(y1, m1) + d2 - d1; d > 1 || (d == 1 && h2-h1 >= 0) {
|
} else if d := m*dayIn(y1, m1) + d2 - d1; d > 1 || (d == 1 && h2-h1 >= 0) {
|
||||||
return fmt.Sprintf(DAYS_AGO, d)
|
return fmt.Sprintf(DaysAgo, d)
|
||||||
} else if h := d*24 + h2 - h1; h > 1 || (h == 1 && mi2-mi1 >= 0) {
|
} else if h := d*24 + h2 - h1; h > 1 || (h == 1 && mi2-mi1 >= 0) {
|
||||||
return fmt.Sprintf(HOURS_AGO, h)
|
return fmt.Sprintf(HoursAgo, h)
|
||||||
} else if mi := h*60 + mi2 - mi1; mi > 1 || (mi == 1 && s2-s1 >= 0) {
|
} else if mi := h*60 + mi2 - mi1; mi > 1 || (mi == 1 && s2-s1 >= 0) {
|
||||||
return fmt.Sprintf(MINUTES_AGO, mi)
|
return fmt.Sprintf(MinutesAgo, mi)
|
||||||
}
|
}
|
||||||
return JUST_NOW
|
return JustNow
|
||||||
}
|
}
|
||||||
|
|
||||||
// dayIn 获取天数
|
// dayIn 获取天数
|
||||||
@@ -120,8 +121,8 @@ var (
|
|||||||
regexpEnter = regexp.MustCompile(`\s+`)
|
regexpEnter = regexp.MustCompile(`\s+`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// IgnoreHtmlTag 去掉 html tag
|
// IgnoreHTMLTag 去掉 html tag
|
||||||
func IgnoreHtmlTag(src string) string {
|
func IgnoreHTMLTag(src string) string {
|
||||||
// 去除所有尖括号内的HTML代码
|
// 去除所有尖括号内的HTML代码
|
||||||
src = regexpBrackets.ReplaceAllString(src, "")
|
src = regexpBrackets.ReplaceAllString(src, "")
|
||||||
// 去除换行符
|
// 去除换行符
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
{{define "ana_js"}}
|
{{define "ana_js"}}
|
||||||
!function(e,n,o){var t=e.screen,a=encodeURIComponent,r=["dt="+a(n.title),"dr="+a(n.referrer),"ul="+(o.language||o.browserLanguage),"sd="+t.colorDepth+"-bit","sr="+t.width+"x"+t.height,"_="+ +new Date],i="?"+r.join("&");e.__beacon_img=new Image,e.__beacon_img.src="/beacon.html"+i}(window,document,navigator,location);
|
!function(e,n,o){var t=e.screen,a=encodeURIComponent,r=["dt="+a(n.title),"dr="+a(n.referrer),"ul="+(o.language||o.browserLanguage).toLowerCase(),"sd="+t.colorDepth+"-bit","sr="+t.width+"x"+t.height,"_="+ +new Date],i="?"+r.join("&");e.__beacon_img=new Image,e.__beacon_img.src="/beacon.html"+i}(window,document,navigator,location);
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -15,8 +15,9 @@
|
|||||||
<comments>https://{{$.Host}}/post/{{.Slug}}.html#comments</comments>
|
<comments>https://{{$.Host}}/post/{{.Slug}}.html#comments</comments>
|
||||||
<guid>https://{{$.Host}}/post/{{.Slug}}.html</guid>
|
<guid>https://{{$.Host}}/post/{{.Slug}}.html</guid>
|
||||||
<description>
|
<description>
|
||||||
<![CDATA[<blockquote>{{.Content}}<p>本文链接:<a href="https://{{$.Host}}/post/{{.Slug}}.html">https://{{$.Host}}/post/{{.Slug}}.html</a>,<a href="https://{{$.Host}}/post/{{.Slug}}.html#comments">参与评论 »</a></p>]]>
|
<![CDATA[{{imgtonormal .Content}}<p>本文链接:<a href="https://{{$.Host}}/post/{{.Slug}}.html">https://{{$.Host}}/post/{{.Slug}}.html</a>,<a href="https://{{$.Host}}/post/{{.Slug}}.html#comments">参与评论 »</a></p>]]>
|
||||||
</description>
|
</description>
|
||||||
|
<pubDate>{{dateformat .CreatedAt "Mon, 02 Jan 2006 15:04:05 -0700"}}</pubDate>
|
||||||
</item>
|
</item>
|
||||||
{{end}}
|
{{end}}
|
||||||
</channel>
|
</channel>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
|
||||||
|
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
||||||
<ShortName>{{.BTitle}}</ShortName>
|
<ShortName>{{.BTitle}}</ShortName>
|
||||||
<Description>{{.SubTitle}}</Description>
|
<Description>{{.SubTitle}}</Description>
|
||||||
<Url type="text/html" template="https://{{.Host}}/search.html?q={searchTerms}" />
|
<InputEncoding>UTF-8</InputEncoding>
|
||||||
|
<Url type="text/html" method="get" template="https://{{.Host}}/search.html?q={searchTerms}" />
|
||||||
|
<moz:SearchForm>https://{{.Host}}/search.html</moz:SearchForm>
|
||||||
</OpenSearchDescription>
|
</OpenSearchDescription>
|
||||||
|
|||||||