Compare commits
No commits in common. "master" and "master" have entirely different histories.
13 changed files with 667 additions and 652 deletions
43
.github/workflows/clippy-fmt.yml
vendored
Normal file
43
.github/workflows/clippy-fmt.yml
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
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
Normal file
49
.github/workflows/coverage.yml
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
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
Normal file
70
.github/workflows/linux.yml
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
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,6 +31,7 @@ steps:
|
|||
when:
|
||||
event: [push, tag, deployment]
|
||||
branch: master
|
||||
secrets: [docker_token]
|
||||
settings:
|
||||
repo: realaravinth/libmedium
|
||||
username: realaravinth
|
||||
|
|
1044
Cargo.lock
generated
1044
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"
|
||||
bincode = "1.3.3"
|
||||
chrono = "0.4.23"
|
||||
config = "0.14"
|
||||
config = "0.13"
|
||||
derive_more = "0.99"
|
||||
futures = "0.3.17"
|
||||
lazy_static = "1.4"
|
||||
|
@ -34,7 +34,7 @@ sha256 = "1.5.0"
|
|||
|
||||
[dependencies.graphql_client]
|
||||
features = ["reqwest"]
|
||||
version = "0.14.0"
|
||||
version = "0.13.0"
|
||||
|
||||
[dependencies.reqwest]
|
||||
features = ["json"]
|
||||
|
|
|
@ -57,7 +57,7 @@ business.
|
|||
| http://md.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion/ | 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://r.sudovanilla.org | US | Selfhosted | [SudoVanilla](https://sudovanilla.org) |
|
||||
| https://read.sudovanilla.com | US | Cloudflare | [SudoVanilla](https://sudovanilla.com) |
|
||||
| https://libmedium.ducks.party | DE | Datalix | [ducks.party](https://ducks.party) |
|
||||
## Deploy
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"$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"]
|
||||
}
|
||||
}
|
16
src/data.rs
16
src/data.rs
|
@ -164,14 +164,14 @@ impl Data {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn get_post_light(&self, id: &str) -> Option<PostUrl> {
|
||||
pub async fn get_post_light(&self, id: &str) -> PostUrl {
|
||||
match self.posts.get(id) {
|
||||
Ok(Some(v)) => {
|
||||
let cached: PostResp = bincode::deserialize(&v[..]).unwrap();
|
||||
Some(PostUrl {
|
||||
PostUrl {
|
||||
slug: cached.unique_slug,
|
||||
username: cached.creator.username,
|
||||
})
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let vars = get_post_light::Variables { id: id.to_owned() };
|
||||
|
@ -180,16 +180,10 @@ impl Data {
|
|||
let res = post_graphql::<GetPostLight, _>(&self.client, URL, vars)
|
||||
.await
|
||||
.unwrap();
|
||||
if res.data.is_none() {
|
||||
None
|
||||
} else {
|
||||
match res.data.expect("missing response data").post {
|
||||
None => None,
|
||||
Some(res) => Some(PostUrl {
|
||||
let res = res.data.expect("missing response data").post.unwrap();
|
||||
PostUrl {
|
||||
slug: res.unique_slug,
|
||||
username: res.creator.username,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
34
src/post.rs
34
src/post.rs
|
@ -345,7 +345,6 @@ pub fn apply_markup(
|
|||
) -> Vec<String> {
|
||||
let mut paragraphs: Vec<String> = Vec::with_capacity(data.content.body_model.paragraphs.len());
|
||||
let mut state = ListState::default();
|
||||
let mut no_render_html = false;
|
||||
for (pindex, p) in data.content.body_model.paragraphs.iter().enumerate() {
|
||||
let mut pos = PositionMap::default();
|
||||
if p.type_ == "H3" && pindex == 0 {
|
||||
|
@ -384,42 +383,33 @@ pub fn apply_markup(
|
|||
}
|
||||
|
||||
let mut content = String::with_capacity(p.text.len());
|
||||
let start = &Markup::start(p, gists, pindex, &mut state);
|
||||
content += start;
|
||||
if start == "<pre>" {
|
||||
no_render_html = true;
|
||||
}
|
||||
content += &Markup::start(p, gists, pindex, &mut state);
|
||||
pos.arr.sort();
|
||||
let mut page = String::default();
|
||||
if let Some(first) = pos.arr.first() {
|
||||
page += p.text.slice(cur..*first as usize);
|
||||
//content += p.text.substring(cur, *first as usize);
|
||||
content += p.text.slice(cur..*first as usize);
|
||||
cur = incr_cur(cur, *first);
|
||||
for point in pos.arr.iter() {
|
||||
//content.push(p.text.substring(start, start + point);
|
||||
// if *point != 0 {
|
||||
|
||||
if cur != *point as usize {
|
||||
page += p.text.slice(cur..*point as usize);
|
||||
// content += p.text.substring(cur, *point as usize);
|
||||
content += p.text.slice(cur..*point as usize);
|
||||
}
|
||||
// }
|
||||
let pos_markups = pos.map.get(point).unwrap();
|
||||
for m in pos_markups.iter() {
|
||||
page += &m.apply_markup(pindex);
|
||||
content += &m.apply_markup(pindex);
|
||||
}
|
||||
cur = incr_cur(cur, *point);
|
||||
}
|
||||
log::debug!("LAST");
|
||||
page += p.text.slice(cur..);
|
||||
let end = &Markup::end(p, pindex, &mut state);
|
||||
if end == "</pre>" {
|
||||
no_render_html = false;
|
||||
}
|
||||
content += &page;
|
||||
content += end;
|
||||
content += p.text.slice(cur..);
|
||||
content += &Markup::end(p, pindex, &mut state);
|
||||
} else {
|
||||
log::debug!("LAST WITH NO MARKUP");
|
||||
page += p.text.slice(cur..);
|
||||
if no_render_html {
|
||||
page = page.replace("<", "<").replace(">", ">");
|
||||
}
|
||||
content += &page;
|
||||
content += p.text.slice(cur..);
|
||||
content += &Markup::end(p, pindex, &mut state);
|
||||
}
|
||||
paragraphs.push(content);
|
||||
|
|
16
src/proxy.rs
16
src/proxy.rs
|
@ -158,33 +158,29 @@ 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")]
|
||||
async fn by_post_id(path: web::Path<String>, data: AppData) -> impl Responder {
|
||||
match data.get_post_light(&path).await {
|
||||
None => HttpResponse::NotFound().body("Post not found"),
|
||||
Some(post_data) => HttpResponse::Found()
|
||||
let post_data = data.get_post_light(&path).await;
|
||||
HttpResponse::Found()
|
||||
.append_header((
|
||||
header::LOCATION,
|
||||
crate::V1_API_ROUTES
|
||||
.proxy
|
||||
.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()
|
||||
let post_data = data.get_post_light(post_id).await;
|
||||
HttpResponse::Found()
|
||||
.append_header((
|
||||
header::LOCATION,
|
||||
crate::V1_API_ROUTES
|
||||
.proxy
|
||||
.get_page(&post_data.username, &post_data.slug),
|
||||
))
|
||||
.finish(),
|
||||
}
|
||||
.finish()
|
||||
} else {
|
||||
HttpResponse::NotFound().body("Post not found, please file bug report")
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
body {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
main {
|
||||
|
|
|
@ -317,6 +317,7 @@ padding: 0;
|
|||
body {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
main {
|
||||
width: 35em;
|
||||
|
|
Loading…
Reference in a new issue