Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Korbs | 4a12404b95 |
|
@ -1,8 +1,6 @@
|
|||
steps:
|
||||
pipeline:
|
||||
backend:
|
||||
image: rust
|
||||
when:
|
||||
event: [push, pull_request, tag, deployment, cron, manual, release]
|
||||
environment:
|
||||
- GIT_HASH=8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value
|
||||
- COMPILED_DATE=2021-07-21
|
||||
|
@ -14,28 +12,22 @@ steps:
|
|||
- make
|
||||
- make test
|
||||
|
||||
build-docker-img:
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
build_docker_img:
|
||||
image: plugins/docker
|
||||
when:
|
||||
event: [pull_request]
|
||||
settings:
|
||||
dry_run: true
|
||||
repo: realaravinth/libmedium
|
||||
username: realaravinth
|
||||
platforms: linux/amd64,linux/arm64/v8
|
||||
tag: latest
|
||||
tags: latest
|
||||
|
||||
|
||||
publish-docker-img:
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
build_and_publish_docker_img:
|
||||
image: plugins/docker
|
||||
when:
|
||||
event: [push, tag, deployment]
|
||||
branch: master
|
||||
secrets: [docker_token]
|
||||
settings:
|
||||
repo: realaravinth/libmedium
|
||||
username: realaravinth
|
||||
password:
|
||||
from_secret: DOCKER_TOKEN
|
||||
platforms: linux/amd64,linux/arm64/v8
|
||||
tag: latest
|
||||
repo: realaravinth/libmedium
|
||||
tags: latest
|
||||
|
|
|
@ -924,12 +924,6 @@ version = "0.3.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "home"
|
||||
version = "0.5.5"
|
||||
|
@ -1176,7 +1170,6 @@ dependencies = [
|
|||
"sailfish",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha256",
|
||||
"sled",
|
||||
"syntect",
|
||||
"url",
|
||||
|
@ -1970,19 +1963,6 @@ dependencies = [
|
|||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha256"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18278f6a914fa3070aa316493f7d2ddfb9ac86ebc06fa3b83bffda487e9065b0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"hex",
|
||||
"sha2",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.1"
|
||||
|
|
|
@ -30,7 +30,6 @@ sled = "0.34.7"
|
|||
syntect = "5.0.0"
|
||||
url = "2.2"
|
||||
actix-web-codegen-const-routes = "0.2.0"
|
||||
sha256 = "1.5.0"
|
||||
|
||||
[dependencies.graphql_client]
|
||||
features = ["reqwest"]
|
||||
|
|
20
README.md
20
README.md
|
@ -49,16 +49,17 @@ medium.com comes up with other, non-harmful ways to run a sustainable
|
|||
business.
|
||||
|
||||
## Instances
|
||||
| Instance | Country | Provider | Host |
|
||||
|--------------------------------|---------|----------|--------------------------|
|
||||
| https://libmedium.batsense.net | India | Airtel | @realaravinth |
|
||||
| https://md.vern.cc | US | 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)
|
||||
| https://medium.hostux.net | France | Gandi | [hostux](https://hostux.net) |
|
||||
| https://read.sudovanilla.comn | US | Cloudflare | [SudoVanilla](https://sudovanilla.com) |
|
||||
|
||||
|
||||
|
||||
| Instance | Country | Provider | Host |
|
||||
| ------------------------------------------------------------------------- | ------- | ---------- | -------------------------------------- |
|
||||
| https://libmedium.batsense.net | India | Airtel | @realaravinth |
|
||||
| https://md.vern.cc | US | 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) |
|
||||
| https://medium.hostux.net | France | Gandi | [hostux](https://hostux.net) |
|
||||
| https://read.sudovanilla.com | US | Cloudflare | [SudoVanilla](https://sudovanilla.com) |
|
||||
| https://libmedium.ducks.party | DE | Datalix | [ducks.party](https://ducks.party) |
|
||||
## Deploy
|
||||
|
||||
1. Grab [`./config/default.toml`](./config/default.toml) and make
|
||||
|
@ -82,6 +83,7 @@ above command.
|
|||
make docker
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
Inspired by [Scribe - An Alternative Medium Frontend](https://sr.ht/~edwardloveall/scribe)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
debug = true
|
||||
source_code = "https://git.batsense.net/realaravinth/libmedium"
|
||||
source_code = "https://github.com/realaravinth/libmedium"
|
||||
#cache = "/var/lib/libmedium"
|
||||
|
||||
[server]
|
||||
|
|
|
@ -21,7 +21,6 @@ use graphql_client::{reqwest::post_graphql, GraphQLQuery};
|
|||
use reqwest::header::USER_AGENT;
|
||||
use reqwest::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha256::digest;
|
||||
use sled::{Db, Tree};
|
||||
|
||||
use crate::proxy::StringUtils;
|
||||
|
@ -288,21 +287,19 @@ impl Data {
|
|||
filepath: &file.file_name,
|
||||
code: &file.content,
|
||||
};
|
||||
file.content = highlight.syntax_highlight(&digest(&file.raw_url));
|
||||
file.content = highlight.syntax_highlight();
|
||||
files.push(file);
|
||||
GistContent {
|
||||
files,
|
||||
html_url: gist_url,
|
||||
}
|
||||
} else {
|
||||
let mut index = 1;
|
||||
gist.files.iter_mut().for_each(|f| {
|
||||
let highlight = render_html::SourcegraphQuery {
|
||||
filepath: &f.file_name,
|
||||
code: &f.content,
|
||||
};
|
||||
f.content = highlight.syntax_highlight(&digest(&f.raw_url));
|
||||
index += 1;
|
||||
f.content = highlight.syntax_highlight();
|
||||
});
|
||||
gist
|
||||
};
|
||||
|
|
22
src/proxy.rs
22
src/proxy.rs
|
@ -34,7 +34,6 @@ pub mod routes {
|
|||
pub by_post_id: &'static str,
|
||||
pub page: &'static str,
|
||||
pub asset: &'static str,
|
||||
pub top_level_post: &'static str,
|
||||
}
|
||||
|
||||
impl Proxy {
|
||||
|
@ -44,7 +43,6 @@ pub mod routes {
|
|||
by_post_id: "/utils/post/{post}",
|
||||
page: "/{username}/{post}",
|
||||
asset: "/asset/medium/{name}",
|
||||
top_level_post: "/{post}",
|
||||
}
|
||||
}
|
||||
pub fn get_page(&self, username: &str, post: &str) -> String {
|
||||
|
@ -133,7 +131,7 @@ const INDEX: &str = include_str!("../templates/index.html");
|
|||
async fn index() -> impl Responder {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(INDEX.replace("SOURCE_CODE_REPLACE", &crate::SETTINGS.source_code))
|
||||
.body(INDEX)
|
||||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.asset")]
|
||||
|
@ -169,23 +167,6 @@ async fn by_post_id(path: web::Path<String>, data: AppData) -> impl Responder {
|
|||
.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((
|
||||
header::LOCATION,
|
||||
crate::V1_API_ROUTES
|
||||
.proxy
|
||||
.get_page(&post_data.username, &post_data.slug),
|
||||
))
|
||||
.finish()
|
||||
} else {
|
||||
HttpResponse::NotFound().body("Post not found, please file bug report")
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.page")]
|
||||
async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responder {
|
||||
let post_id = path.1.split('-').last();
|
||||
|
@ -257,7 +238,6 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||
cfg.service(by_post_id);
|
||||
cfg.service(assets);
|
||||
cfg.service(page);
|
||||
cfg.service(by_top_level_post);
|
||||
cfg.service(index);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ pub struct SourcegraphQuery<'a> {
|
|||
}
|
||||
|
||||
impl<'a> SourcegraphQuery<'a> {
|
||||
pub fn syntax_highlight(&self, gist_name: &str) -> String {
|
||||
pub fn syntax_highlight(&self) -> String {
|
||||
// let ss = SYNTAX_SET;
|
||||
let ts = ThemeSet::load_defaults();
|
||||
|
||||
|
@ -66,8 +66,7 @@ impl<'a> SourcegraphQuery<'a> {
|
|||
if line_num == 0 || line_num == total_lines - 1 {
|
||||
output.push_str(line);
|
||||
} else {
|
||||
let line_id = format!("{gist_name}-{num}");
|
||||
output.push_str(&format!("<div title='click for more options' id=\"line-{line_id}\"class=\"line\"><details class='line_links'><summary class='line_top-link'><a href=\"#line-{line_id}\"<span class=\"line-number\">{num}</span></a>{line}</summary><a href=\"#line-{line_id}\"<span class=\"line-link\">Permanant link</span></a><a href=\"#line-{line_id}\"<span class=\"line-link\">Highlight</span></a></details></div>"
|
||||
output.push_str(&format!("<div title='click for more options' id=\"line-{num}\"class=\"line\"><details class='line_links'><summary class='line_top-link'><a href=\"#line-{num}\"<span class=\"line-number\">{num}</span></a>{line}</summary><a href=\"#line-{num}\"<span class=\"line-link\">Permanant link</span></a><a href=\"#line-{num}\"<span class=\"line-link\">Highlight</span></a></details></div>"
|
||||
));
|
||||
num += 1;
|
||||
}
|
||||
|
@ -154,7 +153,7 @@ mod tests {
|
|||
};
|
||||
let result = query.determine_language(&syntax_set);
|
||||
assert_eq!(result.name, "TeX");
|
||||
let _result = query.syntax_highlight("foo");
|
||||
let _result = query.syntax_highlight();
|
||||
}
|
||||
|
||||
//#[test]
|
||||
|
|
|
@ -69,6 +69,7 @@ impl Settings {
|
|||
|
||||
s = s.add_source(Environment::with_prefix("PAGES").separator("__"));
|
||||
|
||||
|
||||
match env::var("PORT") {
|
||||
Ok(val) => {
|
||||
s = s.set_override("server.port", val).unwrap();
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
href="/@tylerneely/fear-and-loathing-in-lock-free-programming-7158b1cdd50c"
|
||||
>Demo Article</a
|
||||
>
|
||||
| <a href="SOURCE_CODE_REPLACE">Source Code</a>
|
||||
| <a href="https://github.com/realaravinth/libmedium">Source Code</a>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue