Skip to content

Commit

Permalink
fix(generics): support community page and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Oct 17, 2024
1 parent bd230de commit c955a66
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 31 deletions.
4 changes: 3 additions & 1 deletion crates/css-syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ serde_json.workspace = true
serde.workspace = true
url.workspace = true
html-escape.workspace = true
rari-deps.workspace = true
rari-types = { workspace = true, optional = true }

css-syntax-types = { path = "../css-syntax-types" }
Expand All @@ -22,6 +21,9 @@ css-definition-syntax = { path = "../css-definition-syntax" }
[build-dependencies]
anyhow = "1"

[dev-dependencies]
rari-deps.workspace = true

[features]
default = []
rari = ["dep:rari-types"]
1 change: 0 additions & 1 deletion crates/css-syntax/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod error;
pub mod syntax;
pub mod utils;
1 change: 0 additions & 1 deletion crates/css-syntax/src/utils.rs

This file was deleted.

14 changes: 10 additions & 4 deletions crates/rari-cli/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ use axum::extract::Request;
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::{Json, Router};
use rari_doc::error::DocError;
use rari_doc::pages::json::BuiltDocy;
use rari_doc::pages::page::{Page, PageBuilder, PageLike};
use tracing::{error, span, Level};

async fn get_json(req: Request) -> Result<Json<BuiltDocy>, AppError> {
async fn get_json_handler(req: Request) -> Result<Json<BuiltDocy>, AppError> {
let url = req.uri().path();
let json = get_json(url)?;
Ok(Json(json))
}

fn get_json(url: &str) -> Result<BuiltDocy, DocError> {
let span = span!(Level::ERROR, "url", "{}", url);
let _enter1 = span.enter();
let url = url.strip_suffix("index.json").unwrap_or(url);
let url = url.strip_suffix("/index.json").unwrap_or(url);
let page = Page::from_url(url)?;

let slug = &page.slug();
Expand All @@ -19,7 +25,7 @@ async fn get_json(req: Request) -> Result<Json<BuiltDocy>, AppError> {
let _enter2 = span.enter();
let json = page.build()?;
tracing::info!("{url}");
Ok(Json(json))
Ok(json)
}

struct AppError(anyhow::Error);
Expand All @@ -44,7 +50,7 @@ pub fn serve() -> Result<(), anyhow::Error> {
.build()
.unwrap()
.block_on(async {
let app = Router::new().fallback(get_json);
let app = Router::new().fallback(get_json_handler);

let listener = tokio::net::TcpListener::bind("0.0.0.0:8083").await.unwrap();
axum::serve(listener, app).await.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions crates/rari-doc/src/pages/types/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ impl PageReader for GenericPage {
let without_root: &Path = path.strip_prefix(root)?;
let (slug_prefix, title_suffix, root) = if without_root.starts_with("plus/") {
(Some("plus/docs"), "MDN Plus", root.join("plus"))
} else if without_root.starts_with("community/") || without_root == Path::new("community") {
(None, "Contribute to MDN", root.join("community"))
} else if without_root.starts_with("observatory/") {
(
Some("observatory/docs"),
Expand Down
17 changes: 0 additions & 17 deletions crates/rari-doc/src/pages/types/spa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,6 @@ static BASIC_SPAS: Map<&'static str, BuildSPA> = phf_map!(
data: SPAData::BasicSPA(BasicSPA { no_indexing: true, only_follow: false }),
..DEFAULT_BASIC_SPA
},
"observatory/docs/tests_and_scoring" => BuildSPA {
slug: "observatory/docs/tests_and_scoring",
page_title: concat!("Tests & Scoring - ", OBSERVATORY_TITLE_FULL),
page_description: OBSERVATORY_DESCRIPTION,
..DEFAULT_BASIC_SPA
},
"observatory/docs/faq" => BuildSPA {
slug: "observatory/docs/faq",
page_title: concat!("FAQ - ", OBSERVATORY_TITLE_FULL),
page_description: OBSERVATORY_DESCRIPTION,
..DEFAULT_BASIC_SPA
},
"search" => BuildSPA {
slug: "search",
page_title: "Search",
Expand Down Expand Up @@ -363,11 +351,6 @@ static BASIC_SPAS: Map<&'static str, BuildSPA> = phf_map!(
page_title: "About MDN",
..DEFAULT_BASIC_SPA
},
"community" => BuildSPA {
slug: "community",
page_title: "Contribute to MDN",
..DEFAULT_BASIC_SPA
},
"advertising" => BuildSPA {
slug: "advertising",
page_title: "Advertise with us",
Expand Down
1 change: 0 additions & 1 deletion crates/rari-doc/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub fn url_meta_from(url: &str) -> Result<UrlMeta<'_>, UrlError> {
["community", tail] if locale == Default::default() && tail.starts_with("spotlight") => {
(PageCategory::ContributorSpotlight, *tail)
}
["community", ..] => return Err(UrlError::InvalidUrl),
_ => {
let (_, slug) = strip_locale_from_url(url);
let slug = slug.strip_prefix('/').unwrap_or(slug);
Expand Down
6 changes: 0 additions & 6 deletions crates/rari-tools/src/redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,6 @@ mod tests {
let slugs = vec!["A".to_string()];
let _docs = DocFixtures::new(&slugs, Locale::EnUs);
let url = "/en-US/docs/A";
let locale = Locale::EnUs;
let result = validate_to_url(url);
assert!(result.is_ok());
}
Expand All @@ -834,7 +833,6 @@ mod tests {
let slugs = vec!["A".to_string()];
let _docs = DocFixtures::new(&slugs, Locale::EnUs);
let url = "/en-US/docs/B";
let locale = Locale::EnUs;
let result = validate_to_url(url);
assert!(result.is_err());
}
Expand All @@ -844,20 +842,17 @@ mod tests {
let slugs = vec!["A".to_string()];
let _docs = DocFixtures::new(&slugs, Locale::EnUs);
let url = "/";
let locale = Locale::EnUs;
let result = validate_to_url(url);
assert!(result.is_err());

let url = "/en-US/A";
let locale = Locale::EnUs;
let result = validate_to_url(url);
assert!(result.is_err());
}

#[test]
fn test_validate_to_url_invalid_symbols() {
let url = "/en-US/docs/\nA";
let locale = Locale::EnUs;
let result = validate_to_url(url);
assert!(result.is_err());
}
Expand All @@ -867,7 +862,6 @@ mod tests {
let slugs = vec!["A".to_string()];
let _docs = DocFixtures::new(&slugs, Locale::EnUs);
let url = "/en-US/docs/A";
let locale = Locale::PtBr;
let result = validate_to_url(url);
println!("{:?}", result);
assert!(result.is_ok());
Expand Down

0 comments on commit c955a66

Please sign in to comment.