forked from realaravinth/libmedium
Compare commits
87 commits
Author | SHA1 | Date | |
---|---|---|---|
02b20ba677 | |||
ec522a5bb2 | |||
7e5469ad2e | |||
2a4f8ce539 | |||
|
74bf91b976 | ||
|
91c46a64ae | ||
2cec7c2ad2 | |||
c64b40c616 | |||
c249ebeb8b | |||
|
1db3171069 | ||
|
c41f5649e6 | ||
84bb01dbb3 | |||
1b8c15aded | |||
aae35112cd | |||
bfee1f132d | |||
|
fc55eb4de0 | ||
|
888354ed5c | ||
|
4665d2ff87 | ||
|
2b5e82878e | ||
02280710a0 | |||
|
b0183fa2b3 | ||
da71fc1d08 | |||
|
ae52cc555f | ||
eb5f3067c1 | |||
|
3111f3e25c | ||
8bddddea2c | |||
|
e42bff0b5c | ||
1bf1d60cd9 | |||
|
b261bee2f1 | ||
64313eca1f | |||
|
b373dcd75a | ||
b6f916f5f9 | |||
3cf66d941f | |||
fce6090bfa | |||
6586c02cbf | |||
8b9819008a | |||
|
fa38ee17e2 | ||
|
e3a862905d | ||
|
825b01cfa6 | ||
|
19996e67f3 | ||
|
4d7283c3da | ||
d621853a1d | |||
|
b0b09176c5 | ||
2ca90b1d3f | |||
|
b8c3e17404 | ||
8fc0f8f0d5 | |||
|
ecbcf02d4d | ||
ea24dca77d | |||
|
3714d29a23 | ||
4f6d4b709e | |||
95616fef4a | |||
0b3a43088b | |||
ac503b0b06 | |||
883c609412 | |||
|
d44cf2d5c6 | ||
8ee266d846 | |||
c07c5798d9 | |||
63ef7f75ba | |||
b53ac22ba4 | |||
88c7914f96 | |||
a9dc57e77a | |||
cad6e4cff9 | |||
220295bfde | |||
ecc9baf2b1 | |||
534028fc7f | |||
9308f4f344 | |||
d7f47273b2 | |||
|
df5f8c38b0 | ||
|
0ae9390417 | ||
|
864262394d | ||
|
41e84b8a57 | ||
|
3f01a5ff0a | ||
|
0dc45f8fe6 | ||
|
c7f50a4359 | ||
a6bb64d209 | |||
8199005f84 | |||
55c368bd63 | |||
e98a5132a0 | |||
304cfe46cd | |||
|
d3b4ae0952 | ||
|
603ceeba76 | ||
|
e53c128538 | ||
|
5b1a8bea86 | ||
|
f96cb38f3d | ||
6467697558 | |||
|
16a6044773 | ||
d2dcd6b048 |
13 changed files with 657 additions and 672 deletions
43
.github/workflows/clippy-fmt.yml
vendored
43
.github/workflows/clippy-fmt.yml
vendored
|
@ -1,43 +0,0 @@
|
||||||
name: Lint
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, synchronize, reopened]
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
fmt:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Install Rust
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
components: rustfmt
|
|
||||||
- name: Check with rustfmt
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: fmt
|
|
||||||
args: --all -- --check
|
|
||||||
|
|
||||||
clippy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Install Rust
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
components: clippy
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Check with Clippy
|
|
||||||
uses: actions-rs/clippy-check@v1
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
args: --workspace --tests --all-features
|
|
49
.github/workflows/coverage.yml
vendored
49
.github/workflows/coverage.yml
vendored
|
@ -1,49 +0,0 @@
|
||||||
name: Coverage
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, synchronize, reopened]
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build_and_test:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
version:
|
|
||||||
- nightly
|
|
||||||
|
|
||||||
name: ${{ matrix.version }} - x86_64-unknown-linux-gnu
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: ⚡ Cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cargo/registry
|
|
||||||
~/.cargo/git
|
|
||||||
target
|
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Install ${{ matrix.version }}
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: ${{ matrix.version }}-x86_64-unknown-linux-gnu
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Generate coverage file
|
|
||||||
if: (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
|
||||||
uses: actions-rs/tarpaulin@v0.1
|
|
||||||
with:
|
|
||||||
args: "-t 1200"
|
|
||||||
env:
|
|
||||||
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
|
||||||
|
|
||||||
- name: Upload to Codecov
|
|
||||||
uses: codecov/codecov-action@v2
|
|
||||||
if: github.ref == 'refs/heads/master'
|
|
70
.github/workflows/linux.yml
vendored
70
.github/workflows/linux.yml
vendored
|
@ -1,70 +0,0 @@
|
||||||
name: Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, synchronize, reopened]
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build_and_test:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
version:
|
|
||||||
#- 1.51.0
|
|
||||||
- stable
|
|
||||||
# - nightly
|
|
||||||
|
|
||||||
name: ${{ matrix.version }} - x86_64-unknown-linux-gnu
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: ⚡ Cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
/var/lib/docker
|
|
||||||
~/.cargo/registry
|
|
||||||
~/.cargo/git
|
|
||||||
target
|
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
if: (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'realaravinth/libmedium'
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Install ${{ matrix.version }}
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: ${{ matrix.version }}-x86_64-unknown-linux-gnu
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: build
|
|
||||||
run: make
|
|
||||||
|
|
||||||
- name: run tests
|
|
||||||
run: make test
|
|
||||||
|
|
||||||
- name: build and publish docker images
|
|
||||||
run: make docker-publish
|
|
||||||
|
|
||||||
- name: generate documentation
|
|
||||||
if: matrix.version == 'stable' && (github.repository == 'realaravinth/libmedium')
|
|
||||||
run: make doc
|
|
||||||
env:
|
|
||||||
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value
|
|
||||||
|
|
||||||
- name: Deploy to GitHub libmedium
|
|
||||||
if: matrix.version == 'stable' && (github.repository == 'realaravinth/libmedium')
|
|
||||||
uses: JamesIves/github-pages-deploy-action@3.7.1
|
|
||||||
with:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
BRANCH: gh-libmedium
|
|
||||||
FOLDER: target/doc
|
|
|
@ -31,7 +31,6 @@ steps:
|
||||||
when:
|
when:
|
||||||
event: [push, tag, deployment]
|
event: [push, tag, deployment]
|
||||||
branch: master
|
branch: master
|
||||||
secrets: [docker_token]
|
|
||||||
settings:
|
settings:
|
||||||
repo: realaravinth/libmedium
|
repo: realaravinth/libmedium
|
||||||
username: realaravinth
|
username: realaravinth
|
||||||
|
|
1054
Cargo.lock
generated
1054
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -16,7 +16,7 @@ actix-rt = "2"
|
||||||
actix-web = "4.0.1"
|
actix-web = "4.0.1"
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
chrono = "0.4.23"
|
chrono = "0.4.23"
|
||||||
config = "0.13"
|
config = "0.14"
|
||||||
derive_more = "0.99"
|
derive_more = "0.99"
|
||||||
futures = "0.3.17"
|
futures = "0.3.17"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
|
@ -34,7 +34,7 @@ sha256 = "1.5.0"
|
||||||
|
|
||||||
[dependencies.graphql_client]
|
[dependencies.graphql_client]
|
||||||
features = ["reqwest"]
|
features = ["reqwest"]
|
||||||
version = "0.13.0"
|
version = "0.14.0"
|
||||||
|
|
||||||
[dependencies.reqwest]
|
[dependencies.reqwest]
|
||||||
features = ["json"]
|
features = ["json"]
|
||||||
|
|
|
@ -57,7 +57,7 @@ business.
|
||||||
| http://md.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion/ | N/A | Hetzner | [~vern](https://vern.cc) |
|
| http://md.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion/ | N/A | Hetzner | [~vern](https://vern.cc) |
|
||||||
| http://vernaqj2qr2pijpgvf3od6ssc3ulz3nv52gwr3hba5l6humuzmgq.b32.i2p/ | N/A | Hetzner | [~vern](https://vern.cc) |
|
| http://vernaqj2qr2pijpgvf3od6ssc3ulz3nv52gwr3hba5l6humuzmgq.b32.i2p/ | N/A | Hetzner | [~vern](https://vern.cc) |
|
||||||
| https://medium.hostux.net | France | Gandi | [hostux](https://hostux.net) |
|
| https://medium.hostux.net | France | Gandi | [hostux](https://hostux.net) |
|
||||||
| https://read.sudovanilla.com | US | Cloudflare | [SudoVanilla](https://sudovanilla.com) |
|
| https://r.sudovanilla.org | US | Selfhosted | [SudoVanilla](https://sudovanilla.org) |
|
||||||
| https://libmedium.ducks.party | DE | Datalix | [ducks.party](https://ducks.party) |
|
| https://libmedium.ducks.party | DE | Datalix | [ducks.party](https://ducks.party) |
|
||||||
## Deploy
|
## Deploy
|
||||||
|
|
||||||
|
|
12
renovate.json
Normal file
12
renovate.json
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": ["config:recommended", ":dependencyDashboard"],
|
||||||
|
"labels": ["renovate-bot"],
|
||||||
|
"prHourlyLimit": 0,
|
||||||
|
"timezone": "Asia/kolkata",
|
||||||
|
"prCreation": "immediate",
|
||||||
|
"vulnerabilityAlerts": {
|
||||||
|
"enabled": true,
|
||||||
|
"labels": ["renovate-bot", "renovate-security", "security"]
|
||||||
|
}
|
||||||
|
}
|
20
src/data.rs
20
src/data.rs
|
@ -164,14 +164,14 @@ impl Data {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_post_light(&self, id: &str) -> PostUrl {
|
pub async fn get_post_light(&self, id: &str) -> Option<PostUrl> {
|
||||||
match self.posts.get(id) {
|
match self.posts.get(id) {
|
||||||
Ok(Some(v)) => {
|
Ok(Some(v)) => {
|
||||||
let cached: PostResp = bincode::deserialize(&v[..]).unwrap();
|
let cached: PostResp = bincode::deserialize(&v[..]).unwrap();
|
||||||
PostUrl {
|
Some(PostUrl {
|
||||||
slug: cached.unique_slug,
|
slug: cached.unique_slug,
|
||||||
username: cached.creator.username,
|
username: cached.creator.username,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let vars = get_post_light::Variables { id: id.to_owned() };
|
let vars = get_post_light::Variables { id: id.to_owned() };
|
||||||
|
@ -180,10 +180,16 @@ impl Data {
|
||||||
let res = post_graphql::<GetPostLight, _>(&self.client, URL, vars)
|
let res = post_graphql::<GetPostLight, _>(&self.client, URL, vars)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = res.data.expect("missing response data").post.unwrap();
|
if res.data.is_none() {
|
||||||
PostUrl {
|
None
|
||||||
slug: res.unique_slug,
|
} else {
|
||||||
username: res.creator.username,
|
match res.data.expect("missing response data").post {
|
||||||
|
None => None,
|
||||||
|
Some(res) => Some(PostUrl {
|
||||||
|
slug: res.unique_slug,
|
||||||
|
username: res.creator.username,
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
34
src/post.rs
34
src/post.rs
|
@ -345,6 +345,7 @@ pub fn apply_markup(
|
||||||
) -> Vec<String> {
|
) -> Vec<String> {
|
||||||
let mut paragraphs: Vec<String> = Vec::with_capacity(data.content.body_model.paragraphs.len());
|
let mut paragraphs: Vec<String> = Vec::with_capacity(data.content.body_model.paragraphs.len());
|
||||||
let mut state = ListState::default();
|
let mut state = ListState::default();
|
||||||
|
let mut no_render_html = false;
|
||||||
for (pindex, p) in data.content.body_model.paragraphs.iter().enumerate() {
|
for (pindex, p) in data.content.body_model.paragraphs.iter().enumerate() {
|
||||||
let mut pos = PositionMap::default();
|
let mut pos = PositionMap::default();
|
||||||
if p.type_ == "H3" && pindex == 0 {
|
if p.type_ == "H3" && pindex == 0 {
|
||||||
|
@ -383,33 +384,42 @@ pub fn apply_markup(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut content = String::with_capacity(p.text.len());
|
let mut content = String::with_capacity(p.text.len());
|
||||||
content += &Markup::start(p, gists, pindex, &mut state);
|
let start = &Markup::start(p, gists, pindex, &mut state);
|
||||||
|
content += start;
|
||||||
|
if start == "<pre>" {
|
||||||
|
no_render_html = true;
|
||||||
|
}
|
||||||
pos.arr.sort();
|
pos.arr.sort();
|
||||||
|
let mut page = String::default();
|
||||||
if let Some(first) = pos.arr.first() {
|
if let Some(first) = pos.arr.first() {
|
||||||
//content += p.text.substring(cur, *first as usize);
|
page += p.text.slice(cur..*first as usize);
|
||||||
content += p.text.slice(cur..*first as usize);
|
|
||||||
cur = incr_cur(cur, *first);
|
cur = incr_cur(cur, *first);
|
||||||
for point in pos.arr.iter() {
|
for point in pos.arr.iter() {
|
||||||
//content.push(p.text.substring(start, start + point);
|
|
||||||
// if *point != 0 {
|
|
||||||
|
|
||||||
if cur != *point as usize {
|
if cur != *point as usize {
|
||||||
// content += p.text.substring(cur, *point as usize);
|
page += p.text.slice(cur..*point as usize);
|
||||||
content += p.text.slice(cur..*point as usize);
|
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
let pos_markups = pos.map.get(point).unwrap();
|
let pos_markups = pos.map.get(point).unwrap();
|
||||||
for m in pos_markups.iter() {
|
for m in pos_markups.iter() {
|
||||||
content += &m.apply_markup(pindex);
|
page += &m.apply_markup(pindex);
|
||||||
}
|
}
|
||||||
cur = incr_cur(cur, *point);
|
cur = incr_cur(cur, *point);
|
||||||
}
|
}
|
||||||
log::debug!("LAST");
|
log::debug!("LAST");
|
||||||
content += p.text.slice(cur..);
|
page += p.text.slice(cur..);
|
||||||
content += &Markup::end(p, pindex, &mut state);
|
let end = &Markup::end(p, pindex, &mut state);
|
||||||
|
if end == "</pre>" {
|
||||||
|
no_render_html = false;
|
||||||
|
}
|
||||||
|
content += &page;
|
||||||
|
content += end;
|
||||||
} else {
|
} else {
|
||||||
log::debug!("LAST WITH NO MARKUP");
|
log::debug!("LAST WITH NO MARKUP");
|
||||||
content += p.text.slice(cur..);
|
page += p.text.slice(cur..);
|
||||||
|
if no_render_html {
|
||||||
|
page = page.replace("<", "<").replace(">", ">");
|
||||||
|
}
|
||||||
|
content += &page;
|
||||||
content += &Markup::end(p, pindex, &mut state);
|
content += &Markup::end(p, pindex, &mut state);
|
||||||
}
|
}
|
||||||
paragraphs.push(content);
|
paragraphs.push(content);
|
||||||
|
|
38
src/proxy.rs
38
src/proxy.rs
|
@ -158,29 +158,33 @@ async fn assets(path: web::Path<String>, data: AppData) -> impl Responder {
|
||||||
|
|
||||||
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.by_post_id")]
|
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.by_post_id")]
|
||||||
async fn by_post_id(path: web::Path<String>, data: AppData) -> impl Responder {
|
async fn by_post_id(path: web::Path<String>, data: AppData) -> impl Responder {
|
||||||
let post_data = data.get_post_light(&path).await;
|
match data.get_post_light(&path).await {
|
||||||
HttpResponse::Found()
|
None => HttpResponse::NotFound().body("Post not found"),
|
||||||
.append_header((
|
Some(post_data) => HttpResponse::Found()
|
||||||
header::LOCATION,
|
|
||||||
crate::V1_API_ROUTES
|
|
||||||
.proxy
|
|
||||||
.get_page(&post_data.username, &post_data.slug),
|
|
||||||
))
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.top_level_post")]
|
|
||||||
async fn by_top_level_post(path: web::Path<String>, data: AppData) -> impl Responder {
|
|
||||||
if let Some(post_id) = path.split('-').last() {
|
|
||||||
let post_data = data.get_post_light(post_id).await;
|
|
||||||
HttpResponse::Found()
|
|
||||||
.append_header((
|
.append_header((
|
||||||
header::LOCATION,
|
header::LOCATION,
|
||||||
crate::V1_API_ROUTES
|
crate::V1_API_ROUTES
|
||||||
.proxy
|
.proxy
|
||||||
.get_page(&post_data.username, &post_data.slug),
|
.get_page(&post_data.username, &post_data.slug),
|
||||||
))
|
))
|
||||||
.finish()
|
.finish(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.top_level_post")]
|
||||||
|
async fn by_top_level_post(path: web::Path<String>, data: AppData) -> impl Responder {
|
||||||
|
if let Some(post_id) = path.split('-').last() {
|
||||||
|
match data.get_post_light(post_id).await {
|
||||||
|
None => HttpResponse::NotFound().body("Post not found"),
|
||||||
|
Some(post_data) => HttpResponse::Found()
|
||||||
|
.append_header((
|
||||||
|
header::LOCATION,
|
||||||
|
crate::V1_API_ROUTES
|
||||||
|
.proxy
|
||||||
|
.get_page(&post_data.username, &post_data.slug),
|
||||||
|
))
|
||||||
|
.finish(),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
HttpResponse::NotFound().body("Post not found, please file bug report")
|
HttpResponse::NotFound().body("Post not found, please file bug report")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
body {
|
body {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
|
@ -317,7 +317,6 @@ padding: 0;
|
||||||
body {
|
body {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
|
||||||
}
|
}
|
||||||
main {
|
main {
|
||||||
width: 35em;
|
width: 35em;
|
||||||
|
|
Loading…
Reference in a new issue